Skip to content

Commit b75fedc

Browse files
Make NULL tuple values always advance skip arrays.
_bt_check_compare neglected to handle a case that can arise when the scan's keys are temporarily treated as nonrequired, as an optimization: whenever a NULL tuple value was encountered that had a skip array whose current element wasn't already NULL, _bt_check_compare failed to advance the array to the NULL element. This allowed _bt_check_compare to fail to return matching tuples containing a NULL value (though only with an array column that came before a skip array column with NULLs, and only during _bt_readpage calls that set pstate.forcenonrequired=true on a page where the higher-order column also had to advance). To fix, teach _bt_check_compare to handle this case just like any other case where a skip array key is unsatisfied and must be advanced directly (due to the key being considered a nonrequired key). Oversight in commit 8a51027, which optimized nbtree search scan key comparisons with skip arrays. Author: Peter Geoghegan <pg@bowt.ie> Reported-By: Mark Dilger <mark.dilger@enterprisedb.com> Discussion: https://postgr.es/m/CAHgHdKtLFWZcjr87hMH0hYDHgcifu4Tj7iHz-xh8qsJREt5cqA@mail.gmail.com
1 parent 0e13b13 commit b75fedc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/backend/access/nbtree/nbtutils.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -2920,6 +2920,17 @@ _bt_check_compare(IndexScanDesc scan, ScanDirection dir,
29202920

29212921
if (isNull)
29222922
{
2923+
/*
2924+
* Scalar scan key isn't satisfied by NULL tuple value.
2925+
*
2926+
* If we're treating scan keys as nonrequired, and key is for a
2927+
* skip array, then we must attempt to advance the array to NULL
2928+
* (if we're successful then the tuple might match the qual).
2929+
*/
2930+
if (unlikely(forcenonrequired && key->sk_flags & SK_BT_SKIP))
2931+
return _bt_advance_array_keys(scan, NULL, tuple, tupnatts,
2932+
tupdesc, *ikey, false);
2933+
29232934
if (key->sk_flags & SK_BT_NULLS_FIRST)
29242935
{
29252936
/*
@@ -2958,7 +2969,7 @@ _bt_check_compare(IndexScanDesc scan, ScanDirection dir,
29582969
}
29592970

29602971
/*
2961-
* In any case, this indextuple doesn't match the qual.
2972+
* This indextuple doesn't match the qual.
29622973
*/
29632974
return false;
29642975
}

0 commit comments

Comments
 (0)