Rewrite btree index scans to work a page at a time in all cases (both
Tom Lane <tgl@sss.pgh.pa.us>
Rewrite btree index scans to work a page at a time in all cases (both btgettuple and btgetmulti). This eliminates the problem of "re-finding" the exact stopping point, since the stopping point is effectively always a page boundary, and index items are never moved across pre-existing page boundaries. A small penalty is that the keys_are_unique optimization is effectively disabled (and, therefore, is removed in this patch), causing us to apply _bt_checkkeys() to at least one more tuple than necessary when looking up a unique key. However, the advantages for non-unique cases seem great enough to accept this tradeoff. Aside from simplifying and (sometimes) speeding up the indexscan code, this will allow us to reimplement btbulkdelete as a largely sequential scan instead of index-order traversal, thereby significantly reducing the cost of VACUUM. Those changes will come in a separate patch. Original patch by Heikki Linnakangas, rework by Tom Lane.
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/access/index/genam.c | modified | +1 −6 |
| src/backend/access/index/indexam.c | modified | +4 −85 |
| src/backend/access/nbtree/nbtree.c | modified | +93 −226 |
| src/backend/access/nbtree/nbtsearch.c | modified | +310 −239 |
| src/backend/access/nbtree/nbtutils.c | modified | +87 −23 |
| src/backend/access/nbtree/README | modified | +45 −17 |
| src/include/access/itup.h | modified | +12 −1 |
| src/include/access/nbtree.h | modified | +69 −17 |
| src/include/access/relscan.h | modified | +3 −15 |