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); + BTPageOpaque opaque = (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; + bool isNull; + 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);