🌐 AI搜索 & 代理 主页
Skip to content

Commit bee763a

Browse files
nbtree: Always set skipScan flag on rescan.
The TimescaleDB extension expects to be able to change an nbtree scan's keys across rescans. The issue arises in the extension's implementation of loose index scan. This is arguably a misuse of the index AM API, though apparently it worked until recently. It stopped working when the skipScan flag was added to BTScanOpaqueData by commit 8a51027, though. The flag wouldn't reliably track whether the scan (actually, the current rescan) has any skip arrays, leading to confusion in _bt_set_startikey. nbtree preprocessing will now defensively initialize the scan's skipScan flag in all cases, including the case where _bt_preprocess_array_keys returns early due to the (re)scan not using arrays. While nbtree isn't obligated to support this use case (at least not according to my reading of the index AM API), it still seems like a good idea to be consistent here, on general robustness grounds. Author: Peter Geoghegan <pg@bowt.ie> Reported-By: Natalya Aksman <natalya@timescale.com> Discussion: https://postgr.es/m/CAJumhcirfMojbk20+W0YimbNDkwdECvJprQGQ-XqK--ph09nQw@mail.gmail.com Backpatch-through: 18
1 parent 8023086 commit bee763a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/backend/access/nbtree/nbtpreprocesskeys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,7 @@ _bt_preprocess_array_keys(IndexScanDesc scan, int *new_numberOfKeys)
18521852
* (also checks if we should add extra skip arrays based on input keys)
18531853
*/
18541854
numArrayKeys = _bt_num_array_keys(scan, skip_eq_ops, &numSkipArrayKeys);
1855+
so->skipScan = (numSkipArrayKeys > 0);
18551856

18561857
/* Quit if nothing to do. */
18571858
if (numArrayKeys == 0)
@@ -1881,7 +1882,6 @@ _bt_preprocess_array_keys(IndexScanDesc scan, int *new_numberOfKeys)
18811882
arrayKeyData = (ScanKey) palloc(numArrayKeyData * sizeof(ScanKeyData));
18821883

18831884
/* Allocate space for per-array data in the workspace context */
1884-
so->skipScan = (numSkipArrayKeys > 0);
18851885
so->arrayKeys = (BTArrayKeyInfo *) palloc(numArrayKeys * sizeof(BTArrayKeyInfo));
18861886

18871887
/* Allocate space for ORDER procs used to help _bt_checkkeys */

0 commit comments

Comments
 (0)