Skip to content

Commit 6a4941f

Browse files
committed
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
1 parent b167d57 commit 6a4941f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/backend/executor/nodeHash.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,9 @@ ExecHashIncreaseNumBatches(HashJoinTable hashtable)
667667
}
668668

669669
tuple = nexttuple;
670+
671+
/* allow this loop to be cancellable */
672+
CHECK_FOR_INTERRUPTS();
670673
}
671674
}
672675

@@ -1438,6 +1441,9 @@ ExecHashRemoveNextSkewBucket(HashJoinTable hashtable)
14381441
}
14391442

14401443
hashTuple = nextHashTuple;
1444+
1445+
/* allow this loop to be cancellable */
1446+
CHECK_FOR_INTERRUPTS();
14411447
}
14421448

14431449
/*

src/backend/executor/nodeHashjoin.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,13 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
911911
size_t nread;
912912
MinimalTuple tuple;
913913

914+
/*
915+
* We check for interrupts here because this is typically taken as an
916+
* alternative code path to an ExecProcNode() call, which would include
917+
* such a check.
918+
*/
919+
CHECK_FOR_INTERRUPTS();
920+
914921
/*
915922
* Since both the hash value and the MinimalTuple length word are uint32,
916923
* we can read them both in one BufFileRead() call without any type

0 commit comments

Comments
 (0)