Skip to content

Commit a5713ec

Browse files
committed
Hashed LEFT JOIN would miss outer tuples with no inner match if the join
was large enough to be batched and the tuples fell into a batch where there were no inner tuples at all. Thanks to Xiaoyu Wang for finding a test case that exposed this long-standing bug.
1 parent 054b78b commit a5713ec

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/backend/executor/nodeHashjoin.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.64 2004/08/29 05:06:42 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.65 2004/09/17 18:28:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -603,12 +603,14 @@ ExecHashJoinNewBatch(HashJoinState *hjstate)
603603
}
604604

605605
/*
606-
* We can skip over any batches that are empty on either side. Release
607-
* associated temp files right away.
606+
* Normally we can skip over any batches that are empty on either side
607+
* --- but for JOIN_LEFT, can only skip when left side is empty.
608+
* Release associated temp files right away.
608609
*/
609610
while (newbatch <= nbatch &&
610-
(innerBatchSize[newbatch - 1] == 0L ||
611-
outerBatchSize[newbatch - 1] == 0L))
611+
(outerBatchSize[newbatch - 1] == 0L ||
612+
(innerBatchSize[newbatch - 1] == 0L &&
613+
hjstate->js.jointype != JOIN_LEFT)))
612614
{
613615
BufFileClose(hashtable->innerBatchFile[newbatch - 1]);
614616
hashtable->innerBatchFile[newbatch - 1] = NULL;

0 commit comments

Comments
 (0)