Commit 569659ae authored by Tom Lane's avatar Tom Lane

Improve btree's initial-positioning-strategy code so that we never need

to step more than one entry after descending the search tree to arrive at
the correct place to start the scan.  This can improve the behavior
substantially when there are many entries equal to the chosen boundary
value.  Per suggestion from Dmitry Tkach, 14-Jul-03.
parent 772d0f93
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.109 2003/11/29 19:51:40 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.110 2003/12/21 01:23:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -86,8 +86,8 @@ _bt_doinsert(Relation rel, BTItem btitem, ...@@ -86,8 +86,8 @@ _bt_doinsert(Relation rel, BTItem btitem,
itup_scankey = _bt_mkscankey(rel, itup); itup_scankey = _bt_mkscankey(rel, itup);
top: top:
/* find the page containing this key */ /* find the first page containing this key */
stack = _bt_search(rel, natts, itup_scankey, &buf, BT_WRITE); stack = _bt_search(rel, natts, itup_scankey, false, &buf, BT_WRITE);
/* trade in our read lock for a write lock */ /* trade in our read lock for a write lock */
LockBuffer(buf, BUFFER_LOCK_UNLOCK); LockBuffer(buf, BUFFER_LOCK_UNLOCK);
...@@ -100,7 +100,7 @@ top: ...@@ -100,7 +100,7 @@ top:
* need to move right in the tree. See Lehman and Yao for an * need to move right in the tree. See Lehman and Yao for an
* excruciatingly precise description. * excruciatingly precise description.
*/ */
buf = _bt_moveright(rel, buf, natts, itup_scankey, BT_WRITE); buf = _bt_moveright(rel, buf, natts, itup_scankey, false, BT_WRITE);
/* /*
* If we're not allowing duplicates, make sure the key isn't already * If we're not allowing duplicates, make sure the key isn't already
...@@ -175,7 +175,7 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel, ...@@ -175,7 +175,7 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
* Find first item >= proposed new item. Note we could also get a * Find first item >= proposed new item. Note we could also get a
* pointer to end-of-page here. * pointer to end-of-page here.
*/ */
offset = _bt_binsrch(rel, buf, natts, itup_scankey); offset = _bt_binsrch(rel, buf, natts, itup_scankey, false);
/* /*
* Scan over all equal tuples, looking for live conflicts. * Scan over all equal tuples, looking for live conflicts.
...@@ -478,7 +478,7 @@ _bt_insertonpg(Relation rel, ...@@ -478,7 +478,7 @@ _bt_insertonpg(Relation rel,
if (movedright) if (movedright)
newitemoff = P_FIRSTDATAKEY(lpageop); newitemoff = P_FIRSTDATAKEY(lpageop);
else else
newitemoff = _bt_binsrch(rel, buf, keysz, scankey); newitemoff = _bt_binsrch(rel, buf, keysz, scankey, false);
} }
/* /*
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.73 2003/11/29 19:51:40 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtpage.c,v 1.74 2003/12/21 01:23:06 tgl Exp $
* *
* NOTES * NOTES
* Postgres btree pages look like ordinary relation pages. The opaque * Postgres btree pages look like ordinary relation pages. The opaque
...@@ -804,7 +804,7 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full) ...@@ -804,7 +804,7 @@ _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full)
/* we need a scan key to do our search, so build one */ /* we need a scan key to do our search, so build one */
itup_scankey = _bt_mkscankey(rel, &(targetkey->bti_itup)); itup_scankey = _bt_mkscankey(rel, &(targetkey->bti_itup));
/* find the leftmost leaf page containing this key */ /* find the leftmost leaf page containing this key */
stack = _bt_search(rel, rel->rd_rel->relnatts, itup_scankey, stack = _bt_search(rel, rel->rd_rel->relnatts, itup_scankey, false,
&lbuf, BT_READ); &lbuf, BT_READ);
/* don't need a pin on that either */ /* don't need a pin on that either */
_bt_relbuf(rel, lbuf); _bt_relbuf(rel, lbuf);
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.74 2003/11/29 22:40:55 pgsql Exp $ * $PostgreSQL: pgsql/src/include/access/nbtree.h,v 1.75 2003/12/21 01:23:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -459,12 +459,13 @@ extern int _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full); ...@@ -459,12 +459,13 @@ extern int _bt_pagedel(Relation rel, Buffer buf, bool vacuum_full);
/* /*
* prototypes for functions in nbtsearch.c * prototypes for functions in nbtsearch.c
*/ */
extern BTStack _bt_search(Relation rel, int keysz, ScanKey scankey, extern BTStack _bt_search(Relation rel,
Buffer *bufP, int access); int keysz, ScanKey scankey, bool nextkey,
Buffer *bufP, int access);
extern Buffer _bt_moveright(Relation rel, Buffer buf, int keysz, extern Buffer _bt_moveright(Relation rel, Buffer buf, int keysz,
ScanKey scankey, int access); ScanKey scankey, bool nextkey, int access);
extern OffsetNumber _bt_binsrch(Relation rel, Buffer buf, int keysz, extern OffsetNumber _bt_binsrch(Relation rel, Buffer buf, int keysz,
ScanKey scankey); ScanKey scankey, bool nextkey);
extern int32 _bt_compare(Relation rel, int keysz, ScanKey scankey, extern int32 _bt_compare(Relation rel, int keysz, ScanKey scankey,
Page page, OffsetNumber offnum); Page page, OffsetNumber offnum);
extern bool _bt_next(IndexScanDesc scan, ScanDirection dir); extern bool _bt_next(IndexScanDesc scan, ScanDirection dir);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment