Re: Optimizing nbtree ScalarArrayOp execution, allowing multi-column ordered scans, skip scan
Peter Geoghegan <pg@bowt.ie>
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Move nbtree preprocessing into new .c file.
- 597b1ffbf123 18.0 landed
-
Fix nbtree lookahead overflow bug.
- 09a8407dbfd8 18.0 landed
- 6749d4aabe74 17.0 landed
-
Remove unneeded nbtree array preprocessing assert.
- 480bc6e3ed3a 17.0 landed
-
Don't try to fix eliminated nbtree array scan keys.
- f22e17f76cf5 17.0 landed
-
Remove redundant nbtree preprocessing assertions.
- 3b08133cd13c 17.0 landed
-
Avoid extra lookups with nbtree array inequalities.
- 473411fc5115 17.0 landed
-
Enhance nbtree ScalarArrayOp execution.
- 5bf748b86bc6 17.0 landed
-
Improvements and fixes for e0b1ee17dc
- 7e6fb5da41d8 17.0 cited
-
Skip checking of scan keys required for directional scan in B-tree
- e0b1ee17dc3a 17.0 cited
-
Fix btmarkpos/btrestrpos array key wraparound bug.
- 714780dcddf0 17.0 cited
-
Add nbtree high key "continuescan" optimization.
- 29b64d1de7c7 12.0 cited
-
Consider secondary factors during nbtree splits.
- fab250243387 12.0 cited
-
Make heap TID a tiebreaker nbtree index column.
- dd299df8189b 12.0 cited
-
Fix planning of btree index scans using ScalarArrayOpExpr quals.
- 807a40c551dd 9.3.0 cited
-
Fix btree stop-at-nulls logic properly.
- 882368e854b6 9.2.0 cited
-
Teach btree to handle ScalarArrayOpExpr quals natively.
- 9e8da0f75731 9.2.0 cited
On Wed, Jul 26, 2023 at 5:29 AM Matthias van de Meent <boekewurm+postgres@gmail.com> wrote: > Considering that it caches/reuses the page across SAOP operations, can > (or does) this also improve performance for index scans on the outer > side of a join if the order of join columns matches the order of the > index? It doesn't really cache leaf pages at all. What it does is advance the array keys locally, while the original buffer lock is still held on that same page. > That is, I believe this caches (leaf) pages across scan keys, but can > (or does) it also reuse these already-cached leaf pages across > restarts of the index scan/across multiple index lookups in the same > plan node, so that retrieval of nearby index values does not need to > do an index traversal? I'm not sure what you mean. There is no reason why you need to do more than one single descent of an index to scan many leaf pages using many distinct sets of array keys. Obviously, this depends on being able to observe that we really don't need to redescend the index to advance the array keys, again and again. Note in particularly that this usually works across leaf pages. > I'm not sure I understand. MDAM seems to work on an index level to > return full ranges of values, while "skip scan" seems to try to allow > systems to signal to the index to skip to some other index condition > based on arbitrary cutoffs. This would usually be those of which the > information is not stored in the index, such as "SELECT user_id FROM > orders GROUP BY user_id HAVING COUNT(*) > 10", where the scan would go > though the user_id index and skip to the next user_id value when it > gets enough rows of a matching result (where "enough" is determined > above the index AM's plan node, or otherwise is impossible to > determine with only the scan key info in the index AM). I'm not sure > how this could work without specifically adding skip scan-related > index AM functionality, and I don't see how it fits in with this > MDAM/SAOP system. I think of that as being quite a different thing. Basically, the patch that added that feature had to revise the index AM API, in order to support a mode of operation where scans return groupings rather than tuples. Whereas this patch requires none of that. It makes affected index scans as similar as possible to conventional index scans. > > [...] > > > > Thoughts? > > MDAM seems to require exponential storage for "scan key operations" > for conditions on N columns (to be precise, the product of the number > of distinct conditions on each column); e.g. an index on mytable > (a,b,c,d,e,f,g,h) with conditions "a IN (1, 2) AND b IN (1, 2) AND ... > AND h IN (1, 2)" would require 2^8 entries. Note that I haven't actually changed anything about the way that the state machine generates new sets of single value predicates -- it's still just cycling through each distinct set of array keys in the patch. What you describe is a problem in theory, but I doubt that it's a problem in practice. You don't actually have to materialize the predicates up-front, or at all. Plus you can skip over them using the next index tuple. So skipping works both ways. -- Peter Geoghegan