Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81a2579

Browse files
Clarify nbtree array exhaustion comments.
Strictly speaking, we only need to make sure to leave the scan's array keys in their final positions (final for the current scan direction) to handle SAOP array exhaustion because btgettuple might only return a subset of the items for the final page (final for the current scan direction), before the scan changes direction. While it's typical for so->currPos to be invalidated shortly after the scan's arrays are first exhausted, and while so->currPos invalidation does obviate the need to leave the scan's arrays in any particular state, we can't rely on any of that actually happening when handling array exhaustion. Adjust comments to make all of that a lot clearer. Oversight in commit 5bf748b, which enhanced nbtree ScalarArrayOp execution.
1 parent 849110d commit 81a2579

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/backend/access/nbtree/nbtutils.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,14 +1424,19 @@ _bt_advance_array_keys_increment(IndexScanDesc scan, ScanDirection dir)
14241424
}
14251425

14261426
/*
1427-
* The array keys are now exhausted. (There isn't actually a distinct
1428-
* state that represents array exhaustion, since index scans don't always
1429-
* end after btgettuple returns "false".)
1427+
* The array keys are now exhausted.
14301428
*
14311429
* Restore the array keys to the state they were in immediately before we
14321430
* were called. This ensures that the arrays only ever ratchet in the
1433-
* current scan direction. Without this, scans would overlook matching
1434-
* tuples if and when the scan's direction was subsequently reversed.
1431+
* current scan direction.
1432+
*
1433+
* Without this, scans could overlook matching tuples when the scan
1434+
* direction gets reversed just before btgettuple runs out of items to
1435+
* return, but just after _bt_readpage prepares all the items from the
1436+
* scan's final page in so->currPos. When we're on the final page it is
1437+
* typical for so->currPos to get invalidated once btgettuple finally
1438+
* returns false, which'll effectively invalidate the scan's array keys.
1439+
* That hasn't happened yet, though -- and in general it may never happen.
14351440
*/
14361441
_bt_start_array_keys(scan, -dir);
14371442

0 commit comments

Comments
 (0)