Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41486c4

Browse files
Fix btmarkpos/btrestrpos array key wraparound bug.
nbtree's mark/restore processing failed to correctly handle an edge caseinvolving array key advancement and related search-type scan key state.Scans with ScalarArrayScalarArrayOpExpr quals requiring mark/restoreprocessing (for a merge join) could incorrectly conclude that anaffected array/scan key must not have advanced during the time betweenmarking and restoring the scan's position.As a result of all this, array key handling within btrestrpos could skipa required call to _bt_preprocess_keys(). This confusion allowed laterprimitive index scans to overlook tuples matching the true current arraykeys. The scan's search-type scan keys would still have spurious valuescorresponding to the final array element(s) -- not values matching thefirst/now-current array element(s).To fix, remember that "array key wraparound" has taken place during theongoing btrescan in a flag variable stored in the scan's state, and usethat information at the point where btrestrpos decides if another callto _bt_preprocess_keys is required.Oversight in commit70bc583, which taught nbtree to handle array keysduring mark/restore processing, but missed this subtlety. That commitwas itself a bug fix for an issue in commit9e8da0f, which taughtnbtree to handle ScalarArrayOpExpr quals natively.Author: Peter Geoghegan <pg@bowt.ie>Discussion:https://postgr.es/m/CAH2-WzkgP3DDRJxw6DgjCxo-cu-DKrvjEv_ArkP2ctBJatDCYg@mail.gmail.comBackpatch: 11- (all supported branches).
1 parent9d6d8d7 commit41486c4

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

‎src/backend/access/nbtree/nbtree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ btbeginscan(Relation rel, int nkeys, int norderbys)
360360
so->keyData=NULL;
361361

362362
so->arrayKeyData=NULL;/* assume no array keys for now */
363+
so->arraysStarted= false;
363364
so->numArrayKeys=0;
364365
so->arrayKeys=NULL;
365366
so->arrayContext=NULL;

‎src/backend/access/nbtree/nbtutils.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir)
532532
curArrayKey->cur_elem=0;
533533
skey->sk_argument=curArrayKey->elem_values[curArrayKey->cur_elem];
534534
}
535+
536+
so->arraysStarted= true;
535537
}
536538

537539
/*
@@ -591,6 +593,14 @@ _bt_advance_array_keys(IndexScanDesc scan, ScanDirection dir)
591593
if (scan->parallel_scan!=NULL)
592594
_bt_parallel_advance_array_keys(scan);
593595

596+
/*
597+
* When no new array keys were found, the scan is "past the end" of the
598+
* array keys. _bt_start_array_keys can still "restart" the array keys if
599+
* a rescan is required.
600+
*/
601+
if (!found)
602+
so->arraysStarted= false;
603+
594604
returnfound;
595605
}
596606

@@ -644,8 +654,13 @@ _bt_restore_array_keys(IndexScanDesc scan)
644654
* If we changed any keys, we must redo _bt_preprocess_keys. That might
645655
* sound like overkill, but in cases with multiple keys per index column
646656
* it seems necessary to do the full set of pushups.
657+
*
658+
* Also do this whenever the scan's set of array keys "wrapped around" at
659+
* the end of the last primitive index scan. There won't have been a call
660+
* to _bt_preprocess_keys from some other place following wrap around, so
661+
* we do it for ourselves.
647662
*/
648-
if (changed)
663+
if (changed|| !so->arraysStarted)
649664
{
650665
_bt_preprocess_keys(scan);
651666
/* The mark should have been set on a consistent set of keys... */

‎src/include/access/nbtree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,10 @@ typedef struct BTArrayKeyInfo
10291029

10301030
typedefstructBTScanOpaqueData
10311031
{
1032-
/*these fields are set by _bt_preprocess_keys(): */
1032+
/*all fields (except arraysStarted) are set by _bt_preprocess_keys(): */
10331033
boolqual_ok;/* false if qual can never be satisfied */
1034+
boolarraysStarted;/* Started array keys, but have yet to "reach
1035+
* past the end" of all arrays? */
10341036
intnumberOfKeys;/* number of preprocessed scan keys */
10351037
ScanKeykeyData;/* array of preprocessed scan keys */
10361038

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp