summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorPeter Geoghegan <pg@bowt.ie>2023-09-28 16:29:27 -0700
committerPeter Geoghegan <pg@bowt.ie>2023-09-28 16:29:27 -0700
commitd4724e94a1ebc5ab5887372b99190d3b112fb06c (patch)
tree03500dc1bfb338fd6724a844353296e3c541b08b /src/include
parent83ba050f92fa893cfd3f3444319b314f314193de (diff)
Fix btmarkpos/btrestrpos array key wraparound bug.
nbtree's mark/restore processing failed to correctly handle an edge case involving array key advancement and related search-type scan key state. Scans with ScalarArrayScalarArrayOpExpr quals requiring mark/restore processing (for a merge join) could incorrectly conclude that an affected array/scan key must not have advanced during the time between marking and restoring the scan's position. As a result of all this, array key handling within btrestrpos could skip a required call to _bt_preprocess_keys(). This confusion allowed later primitive index scans to overlook tuples matching the true current array keys. The scan's search-type scan keys would still have spurious values corresponding to the final array element(s) -- not values matching the first/now-current array element(s). To fix, remember that "array key wraparound" has taken place during the ongoing btrescan in a flag variable stored in the scan's state, and use that information at the point where btrestrpos decides if another call to _bt_preprocess_keys is required. Oversight in commit 70bc5833, which taught nbtree to handle array keys during mark/restore processing, but missed this subtlety. That commit was itself a bug fix for an issue in commit 9e8da0f7, which taught nbtree to handle ScalarArrayOpExpr quals natively. Author: Peter Geoghegan <pg@bowt.ie> Discussion: https://postgr.es/m/CAH2-WzkgP3DDRJxw6DgjCxo-cu-DKrvjEv_ArkP2ctBJatDCYg@mail.gmail.com Backpatch: 11- (all supported branches).
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/nbtree.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/include/access/nbtree.h b/src/include/access/nbtree.h
index 79506c748b2..7a0124b48b0 100644
--- a/src/include/access/nbtree.h
+++ b/src/include/access/nbtree.h
@@ -903,8 +903,10 @@ typedef struct BTArrayKeyInfo
typedef struct BTScanOpaqueData
{
- /* these fields are set by _bt_preprocess_keys(): */
+ /* all fields (except arraysStarted) are set by _bt_preprocess_keys(): */
bool qual_ok; /* false if qual can never be satisfied */
+ bool arraysStarted; /* Started array keys, but have yet to "reach
+ * past the end" of all arrays? */
int numberOfKeys; /* number of preprocessed scan keys */
ScanKey keyData; /* array of preprocessed scan keys */