Commit f2ec57de authored by Tom Lane's avatar Tom Lane

Make sure that hash join's bulk-tuple-transfer loops are interruptible.

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
parent 2b187436
...@@ -720,6 +720,9 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable) ...@@ -720,6 +720,9 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable)
/* next tuple in this chunk */ /* next tuple in this chunk */
idx += MAXALIGN(hashTupleSize); idx += MAXALIGN(hashTupleSize);
/* allow this loop to be cancellable */
CHECK_FOR_INTERRUPTS();
} }
/* we're done with this chunk - free it and proceed to the next one */ /* we're done with this chunk - free it and proceed to the next one */
...@@ -1599,6 +1602,9 @@ ExecHashRemoveNextSkewBucket(HashJoinTable hashtable) ...@@ -1599,6 +1602,9 @@ ExecHashRemoveNextSkewBucket(HashJoinTable hashtable)
} }
hashTuple = nextHashTuple; hashTuple = nextHashTuple;
/* allow this loop to be cancellable */
CHECK_FOR_INTERRUPTS();
} }
/* /*
......
...@@ -856,6 +856,13 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate, ...@@ -856,6 +856,13 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
size_t nread; size_t nread;
MinimalTuple tuple; 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, * Since both the hash value and the MinimalTuple length word are uint32,
* we can read them both in one BufFileRead() call without any type * we can read them both in one BufFileRead() call without any type
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment