mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-10-01 10:31:22 +02:00
c9c0589fda
Teach _bt_binsrch (and related helper routines like _bt_search and
_bt_compare) about the initial positioning requirements of backward
scans. Routines like _bt_binsrch already know all about "nextkey"
searches, so it seems natural to teach them about "goback"/backward
searches, too. These concepts are closely related, and are much easier
to understand when discussed together.
Now that certain implementation details are hidden from _bt_first, it's
straightforward to add a new optimization: backward scans using the <
strategy now avoid extra leaf page accesses in certain "boundary cases".
Consider the following example, which uses the tenk1 table (and its
tenk1_hundred index) from the standard regression tests:
SELECT * FROM tenk1 WHERE hundred < 12 ORDER BY hundred DESC LIMIT 1;
Before this commit, nbtree would scan two leaf pages, even though it was
only really necessary to scan one leaf page. We'll now descend straight
to the leaf page containing a (12, -inf) high key instead. The scan
will locate matching non-pivot tuples with "hundred" values starting
from the value 11. The scan won't waste a page access on the right
sibling leaf page, which cannot possibly contain any matching tuples.
You can think of the optimization added by this commit as disabling an
optimization (the _bt_compare "!pivotsearch" behavior that was added to
Postgres 12 in commit
|
||
---|---|---|
.. | ||
expected | ||
sql | ||
t | ||
.gitignore | ||
amcheck--1.0--1.1.sql | ||
amcheck--1.0.sql | ||
amcheck--1.1--1.2.sql | ||
amcheck--1.2--1.3.sql | ||
amcheck--1.3--1.4.sql | ||
amcheck.control | ||
Makefile | ||
meson.build | ||
verify_heapam.c | ||
verify_nbtree.c |