Re: [HACKERS] Print b-tree tuples
Am 04.01.13 21:26, schrieb Tom Lane: Samuel Vogel writes: I'm trying to print out the tuples in the b-tree nodes for analysis, but when iterate over more than the first entry of the tuples (scanKey++), I strangely get the error below on query execution: ERROR: relation "simpletest" does not exist LINE 1: SELECT * FROM simpletest WHERE id = 50; Is this patch the only thing you changed? The only obvious explanation for the above error (other than "you fat-fingered the query") seems to be that you caused index searches in pg_class to fail, but I don't see how this patch could be affecting the result of _bt_binsrch. Yes, I've switched to a clean master and only applied this patch. If I put the the break, the query works, so it's fine as well. BTW: I just had a discussion if it would make sense, to recreate my test table with a different order, as a b-tree is always dependent on insertion order. But as the b-tree index is newly created in memory after each restart, two different insertion orders (same values) would give me the same b-tree at least after a restart, right? Regards, Samuel -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Print b-tree tuples
Samuel Vogel writes: > I'm trying to print out the tuples in the b-tree nodes for analysis, but > when iterate over more than the first entry of the tuples (scanKey++), I > strangely get the error below on query execution: > ERROR: relation "simpletest" does not exist > LINE 1: SELECT * FROM simpletest WHERE id = 50; Is this patch the only thing you changed? The only obvious explanation for the above error (other than "you fat-fingered the query") seems to be that you caused index searches in pg_class to fail, but I don't see how this patch could be affecting the result of _bt_binsrch. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Re: [HACKERS] Print b-tree tuples
Hello, I'm trying to print out the tuples in the b-tree nodes for analysis, but when iterate over more than the first entry of the tuples (scanKey++), I strangely get the error below on query execution: ERROR: relation "simpletest" does not exist LINE 1: SELECT * FROM simpletest WHERE id = 50; I was able to get around this by only printing byval attributes: if (!itupdesc->attrs[i-1]->attbyval) break; I would still like to know why my code screws up though. The relnames are not byval, but I should still be able to print the address, right? Regards, Samuel
[HACKERS] Print b-tree tuples
Hello, I'm trying to print out the tuples in the b-tree nodes for analysis, but when iterate over more than the first entry of the tuples (scanKey++), I strangely get the error below on query execution: ERROR: relation "simpletest" does not exist LINE 1: SELECT * FROM simpletest WHERE id = 50; Any help with reviewing my my small attached patch would be greatly appreciated! Regards, Samuel Vogel diff --git src/backend/access/nbtree/nbtsearch.c src/backend/access/nbtree/nbtsearch.c index ac98589477b876cfc8470ea03fb39fa43d5ea9c5..e07ae925332a923da73eb2bb28809e79f4bd7a1b 100644 --- src/backend/access/nbtree/nbtsearch.c +++ src/backend/access/nbtree/nbtsearch.c @@ -203,6 +203,37 @@ _bt_moveright(Relation rel, return buf; } +void +_bt_printindextuple(Relation rel, + int keysz, + ScanKey scankey, + Page page, + OffsetNumber offnum) +{ + TupleDesc itupdesc = RelationGetDescr(rel); + BTPageOpaqueopaque = (BTPageOpaque) PageGetSpecialPointer(page); + IndexTuple itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, offnum));; + int i; + + fprintf(stdout, "%d: ", offnum); + + for (i = 1; i <= keysz; i++) + { + Datum datum; + boolisNull; + int32 result; + + datum = index_getattr(itup, scankey->sk_attno, itupdesc, &isNull); + + if (i > 1) fprintf(stdout, ", "); + fprintf(stdout, "%d", DatumGetInt32(datum)); + + scankey++; + } + + fprintf(stdout, "\n"); +} + /* * _bt_binsrch() -- Do a binary search for a key on a particular page. * @@ -260,6 +291,16 @@ _bt_binsrch(Relation rel, if (high < low) return low; + fprintf(stdout, "---\n"); + fprintf(stdout, "low: %d, high: %d\n", low, high); + + int j; + for (j = low; j <= high; j++) { + _bt_printindextuple(rel, keysz, scankey, page, j); + } + + fprintf(stdout, "---\n"); + /* * Binary search to find the first key on the page >= scan key, or first * key > scankey when nextkey is true. diff --git src/include/access/nbtree.h src/include/access/nbtree.h index eef67f54b504e73b10d4e1b2f12472eeb8481ffa..25b86020af3bdb0e3d2f1c6e730c70a68fc6a9a1 100644 --- src/include/access/nbtree.h +++ src/include/access/nbtree.h @@ -643,6 +643,8 @@ extern int _bt_pagedel(Relation rel, Buffer buf, BTStack stack); /* * prototypes for functions in nbtsearch.c */ +extern void _bt_printindextuple(Relation rel, int keysz, + ScanKey scankey, Page page, OffsetNumber offnum); extern BTStack _bt_search(Relation rel, int keysz, ScanKey scankey, bool nextkey, Buffer *bufP, int access); -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers