- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit5bf748b
committed
Enhance nbtree ScalarArrayOp execution.
Commit9e8da0f taught nbtree to handle ScalarArrayOpExpr qualsnatively. This works by pushing down the full context (the array keys)to the nbtree index AM, enabling it to execute multiple primitive indexscans that the planner treats as one continuous index scan/index path.This earlier enhancement enabled nbtree ScalarArrayOp index-only scans.It also allowed scans with ScalarArrayOp quals to return ordered results(with some notable restrictions, described further down).Take this general approach a lot further: teach nbtree SAOP index scansto decide how to execute ScalarArrayOp scans (when and where to startthe next primitive index scan) based on physical index characteristics.This can be far more efficient. All SAOP scans will now reliably avoidduplicative leaf page accesses (just like any other nbtree index scan).SAOP scans whose array keys are naturally clustered together now requirefar fewer index descents, since we'll reliably avoid starting a newprimitive scan just to get to a later offset from the same leaf page.The scan's arrays now advance using binary searches for the arrayelement that best matches the next tuple's attribute value. Requiredscan key arrays (i.e. arrays from scan keys that can terminate the scan)ratchet forward in lockstep with the index scan. Non-required arrays(i.e. arrays from scan keys that can only exclude non-matching tuples)"advance" without the process ever rolling over to a higher-order array.Naturally, only required SAOP scan keys trigger skipping over leaf pages(non-required arrays cannot safely end or start primitive index scans).Consequently, even index scans of a composite index with a high-orderinequality scan key (which we'll mark required) and a low-order SAOPscan key (which we won't mark required) now avoid repeating leaf pageaccesses -- that benefit isn't limited to simpler equality-only cases.In general, all nbtree index scans now output tuples as if they were onecontinuous index scan -- even scans that mix a high-order inequalitywith lower-order SAOP equalities reliably output tuples in index order.This allows us to remove a couple of special cases that were appliedwhen building index paths with SAOP clauses during planning.Bugfix commit807a40c taught the planner to avoid generating unsafepath keys: path keys on a multicolumn index path, with a SAOP clause onany attribute beyond the first/most significant attribute. These casesare now all safe, so we go back to generating path keys without regardfor the presence of SAOP clauses (just like with any other clause type).Affected queries can now exploit scan output order in all the usual ways(e.g., certain "ORDER BY ... LIMIT n" queries can now terminate early).Also undo changes from follow-up bugfix commita4523c5, which taughtthe planner to produce alternative index paths, with path keys, butwithout low-order SAOP index quals (filter quals were used instead).We'll no longer generate these alternative paths, since they can nolonger offer any meaningful advantages over standard index qual paths.Affected queries thereby avoid all of the disadvantages that come fromusing filter quals within index scan nodes. They can avoid extra heappage accesses from using filter quals to exclude non-matching tuples(index quals will never have that problem). They can also skip overirrelevant sections of the index in more cases (though only when nbtreedetermines that starting another primitive scan actually makes sense).There is a theoretical risk that removing restrictions on SAOP indexpaths from the planner will break compatibility with amcanorder-basedindex AMs maintained as extensions. Such an index AM could have thesame limitations around ordered SAOP scans as nbtree had up until now.Adding a pro forma incompatibility item about the issue to the Postgres17 release notes seems like a good idea.Author: Peter Geoghegan <pg@bowt.ie>Author: Matthias van de Meent <boekewurm+postgres@gmail.com>Reviewed-By: Heikki Linnakangas <hlinnaka@iki.fi>Reviewed-By: Matthias van de Meent <boekewurm+postgres@gmail.com>Reviewed-By: Tomas Vondra <tomas.vondra@enterprisedb.com>Discussion:https://postgr.es/m/CAH2-Wz=ksvN_sjcnD1+Bt-WtifRA5ok48aDYnq3pkKhxgMQpcw@mail.gmail.com1 parentddd9e43 commit5bf748b
File tree
22 files changed
+3487
-579
lines changed- doc/src/sgml
- src
- backend
- access
- index
- nbtree
- executor
- optimizer/path
- utils/adt
- include
- access
- utils
- test/regress
- expected
- sql
- tools/pgindent
22 files changed
+3487
-579
lines changedLines changed: 9 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
809 | 809 |
| |
810 | 810 |
| |
811 | 811 |
| |
812 |
| - | |
| 812 | + | |
| 813 | + | |
813 | 814 |
| |
814 | 815 |
| |
815 | 816 |
| |
816 | 817 |
| |
817 | 818 |
| |
818 | 819 |
| |
819 | 820 |
| |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
820 | 828 |
| |
821 | 829 |
| |
822 | 830 |
| |
|
Lines changed: 13 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4064 | 4064 |
| |
4065 | 4065 |
| |
4066 | 4066 |
| |
| 4067 | + | |
| 4068 | + | |
| 4069 | + | |
| 4070 | + | |
| 4071 | + | |
| 4072 | + | |
| 4073 | + | |
| 4074 | + | |
| 4075 | + | |
| 4076 | + | |
| 4077 | + | |
| 4078 | + | |
| 4079 | + | |
4067 | 4080 |
| |
4068 | 4081 |
| |
4069 | 4082 |
| |
|
Lines changed: 4 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
449 | 449 |
| |
450 | 450 |
| |
451 | 451 |
| |
452 |
| - | |
453 |
| - | |
454 |
| - | |
455 |
| - | |
456 | 452 |
| |
457 | 453 |
| |
458 |
| - | |
| 454 | + | |
| 455 | + | |
459 | 456 |
| |
460 | 457 |
| |
461 | 458 |
| |
| |||
474 | 471 |
| |
475 | 472 |
| |
476 | 473 |
| |
477 |
| - | |
| 474 | + | |
| 475 | + | |
478 | 476 |
| |
479 | 477 |
| |
480 | 478 |
| |
|
0 commit comments
Comments
(0)