nbtree: Avoid allocating _bt_search stack.
Peter Geoghegan <pg@bowt.ie>
nbtree: Avoid allocating _bt_search stack. Avoid allocating memory for an nbtree descent stack during index scans. We only require a descent stack during inserts, when it is used to determine where to insert a new pivot tuple/downlink into the target leaf page's parent page in the event of a page split. (Page deletion's first phase also performs a _bt_search that requires a descent stack.) This optimization improves performance by minimizing palloc churn. It speeds up index scans that call _bt_search frequently/descend the index many times, especially when the cost of scanning the index dominates (e.g., with index-only skip scans). Testing has shown that the underlying issue causes performance problems for an upcoming patch that will replace btgettuple with a new btgetbatch interface to enable I/O prefetching. Author: Peter Geoghegan <pg@bowt.ie> Reviewed-By: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/CAH2-Wzmy7NMba9k8m_VZ-XNDZJEUQBU8TeLEeL960-rAKb-+tQ@mail.gmail.com
Files
| Path | Change | +/− |
|---|---|---|
| contrib/amcheck/verify_nbtree.c | modified | +1 −3 |
| src/backend/access/nbtree/nbtinsert.c | modified | +18 −1 |
| src/backend/access/nbtree/nbtpage.c | modified | +1 −1 |
| src/backend/access/nbtree/nbtsearch.c | modified | +18 −17 |
| src/backend/access/nbtree/nbtutils.c | modified | +0 −16 |
| src/include/access/nbtree.h | modified | +1 −2 |
Discussion
- index prefetching 492 messages · 2023-06-08 → 2026-07-07