Make sure that hash join's bulk-tuple-transfer loops are interruptible.
authorTom Lane <[email protected]>
Wed, 15 Feb 2017 21:40:06 +0000 (16:40 -0500)
committerTom Lane <[email protected]>
Wed, 15 Feb 2017 21:40:06 +0000 (16:40 -0500)
The loops in ExecHashJoinNewBatch(), ExecHashIncreaseNumBatches(), and
ExecHashRemoveNextSkewBucket() are all capable of iterating over many
tuples without ever doing a CHECK_FOR_INTERRUPTS, so that the backend
might fail to respond to SIGINT or SIGTERM for an unreasonably long time.
Fix that.  In the case of ExecHashJoinNewBatch(), it seems useful to put
the added CHECK_FOR_INTERRUPTS into ExecHashJoinGetSavedTuple() rather
than directly in the loop, because that will also ensure that both
principal code paths through ExecHashJoinOuterGetTuple() will do a
CHECK_FOR_INTERRUPTS, which seems like a good idea to avoid surprises.

Back-patch to all supported branches.

Tom Lane and Thomas Munro

Discussion: https://postgr.es/m/6044.1487121720@sss.pgh.pa.us

src/backend/executor/nodeHash.c
src/backend/executor/nodeHashjoin.c

index b10a58b42488925f718b044f13c66311d0ddea95..f86b84ef5204fe5bd9162fd59aa21e2d9c291646 100644 (file)
@@ -666,6 +666,9 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable)
            }
 
            tuple = nexttuple;
+
+           /* allow this loop to be cancellable */
+           CHECK_FOR_INTERRUPTS();
        }
    }
 
@@ -1437,6 +1440,9 @@ ExecHashRemoveNextSkewBucket(HashJoinTable hashtable)
        }
 
        hashTuple = nextHashTuple;
+
+       /* allow this loop to be cancellable */
+       CHECK_FOR_INTERRUPTS();
    }
 
    /*
index fbdda9c8ee16dcdd3ac95cb2ea124e536c7ab994..34e9f59efad9c77778f7a99bc50b98781b555399 100644 (file)
@@ -910,6 +910,13 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
    size_t      nread;
    MinimalTuple tuple;
 
+   /*
+    * We check for interrupts here because this is typically taken as an
+    * alternative code path to an ExecProcNode() call, which would include
+    * such a check.
+    */
+   CHECK_FOR_INTERRUPTS();
+
    /*
     * Since both the hash value and the MinimalTuple length word are uint32,
     * we can read them both in one BufFileRead() call without any type