forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitc9c0589
committed
Optimize nbtree backward scan boundary cases.
Teach _bt_binsrch (and related helper routines like _bt_search and_bt_compare) about the initial positioning requirements of backwardscans. Routines like _bt_binsrch already know all about "nextkey"searches, so it seems natural to teach them about "goback"/backwardsearches, too. These concepts are closely related, and are much easierto understand when discussed together.Now that certain implementation details are hidden from _bt_first, it'sstraightforward 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 itstenk1_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 wasonly really necessary to scan one leaf page. We'll now descend straightto the leaf page containing a (12, -inf) high key instead. The scanwill locate matching non-pivot tuples with "hundred" values startingfrom the value 11. The scan won't waste a page access on the rightsibling leaf page, which cannot possibly contain any matching tuples.You can think of the optimization added by this commit as disabling anoptimization (the _bt_compare "!pivotsearch" behavior that was added toPostgres 12 in commitdd299df) for a small subset of cases where it wasalways counterproductive.Equivalently, you can think of the new optimization as extending the"pivotsearch" behavior that page deletion by VACUUM has long required(since the aforementioned Postgres 12 commit went in) to other, similarcases. Obviously, this isn't strictly necessary for these new cases(unlike VACUUM, _bt_first is prepared to move the scan to the left onceon the leaf level), but the underlying principle is the same.Author: Peter Geoghegan <pg@bowt.ie>Reviewed-By: Matthias van de Meent <boekewurm+postgres@gmail.com>Discussion:https://postgr.es/m/CAH2-Wz=XPzM8HzaLPq278Vms420mVSHfgs9wi5tjFKHcapZCEw@mail.gmail.com1 parentb437571 commitc9c0589
File tree
7 files changed
+210
-149
lines changed- contrib/amcheck
- src
- backend/access/nbtree
- include/access
- test/regress
- expected
- sql
7 files changed
+210
-149
lines changedLines changed: 8 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3165 | 3165 |
| |
3166 | 3166 |
| |
3167 | 3167 |
| |
3168 |
| - | |
| 3168 | + | |
3169 | 3169 |
| |
3170 | 3170 |
| |
3171 | 3171 |
| |
| |||
3227 | 3227 |
| |
3228 | 3228 |
| |
3229 | 3229 |
| |
3230 |
| - | |
| 3230 | + | |
3231 | 3231 |
| |
3232 | 3232 |
| |
3233 | 3233 |
| |
| |||
3250 | 3250 |
| |
3251 | 3251 |
| |
3252 | 3252 |
| |
3253 |
| - | |
| 3253 | + | |
3254 | 3254 |
| |
3255 | 3255 |
| |
3256 | 3256 |
| |
| |||
3288 | 3288 |
| |
3289 | 3289 |
| |
3290 | 3290 |
| |
3291 |
| - | |
| 3291 | + | |
3292 | 3292 |
| |
3293 | 3293 |
| |
3294 | 3294 |
| |
| |||
3514 | 3514 |
| |
3515 | 3515 |
| |
3516 | 3516 |
| |
3517 |
| - | |
3518 |
| - | |
3519 |
| - | |
| 3517 | + | |
| 3518 | + | |
| 3519 | + | |
3520 | 3520 |
| |
3521 | 3521 |
| |
3522 | 3522 |
| |
3523 | 3523 |
| |
3524 | 3524 |
| |
3525 | 3525 |
| |
3526 | 3526 |
| |
3527 |
| - | |
| 3527 | + | |
3528 | 3528 |
| |
3529 | 3529 |
| |
3530 | 3530 |
| |
|
Lines changed: 13 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1958 | 1958 |
| |
1959 | 1959 |
| |
1960 | 1960 |
| |
1961 |
| - | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
1962 | 1970 |
| |
1963 |
| - | |
1964 |
| - | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
1965 | 1975 |
| |
1966 | 1976 |
| |
1967 | 1977 |
| |
|
0 commit comments
Comments
(0)