Update parallel BTree scan state when the scan keys can't be satisfied.
authorAmit Kapila <[email protected]>
Thu, 17 Sep 2020 09:46:46 +0000 (15:16 +0530)
committerAmit Kapila <[email protected]>
Thu, 17 Sep 2020 10:41:48 +0000 (16:11 +0530)
For parallel btree scan to work for array of scan keys, it should reach
BTPARALLEL_DONE state once for every distinct combination of array keys.
This is required to ensure that the parallel workers don't try to seize
blocks at the same time for different scan keys. We missed to update this
state when we discovered that the scan keys can't be satisfied.

Author: James Hunter
Reviewed-by: Amit Kapila
Tested-by: Justin Pryzby
Backpatch-through: 10, where it was introduced
Discussion: https://postgr.es/m/4248CABC-25E3-4809-B4D0-128E1BAABC3C@amazon.com

src/backend/access/nbtree/nbtsearch.c

index 1e628a33d77ecec5beba30ad06a07ae5cd5bc4bd..8f6575fdf15c2b008163419b24ac87c6bf5dd2e6 100644 (file)
@@ -880,7 +880,11 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
     * never be satisfied (eg, x == 1 AND x > 2).
     */
    if (!so->qual_ok)
+   {
+       /* Notify any other workers that we're done with this scan key. */
+       _bt_parallel_done(scan);
        return false;
+   }
 
    /*
     * For parallel scans, get the starting page from shared state. If the