8000 Hashed LEFT JOIN would miss outer tuples with no inner match if the join · postgres/postgres@44ed69c · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 44ed69c

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 a59084f commit 44ed69c

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-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.39 2001/10/25 05:49:28 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.39.2.1 2004/09/17 18:29:40 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -569,12 +569,14 @@ ExecHashJoinNewBatch(HashJoinState *hjstate)
569569
}
570570

571571
/*
572-
* We can skip over any batches that are empty on either side. Release
573-
* associated temp files right away.
572+
* Normally we can skip over any batches that are empty on either side
573+
* --- but for JOIN_LEFT, can only skip when left side is empty.
574+
* Release associated temp files right away.
574575
*/
575576
while (newbatch <= nbatch &&
576-
(innerBatchSize[newbatch - 1] == 0L ||
577-
outerBatchSize[newbatch - 1] == 0L))
577+
(outerBatchSize[newbatch - 1] == 0L ||
578+
(innerBatchSize[newbatch - 1] == 0L &&
579+
hjstate->js.jointype != JOIN_LEFT)))
578580
{
579581
BufFileClose(hashtable->innerBatchFile[newbatch - 1]);
580582
hashtable->innerBatchFile[newbatch - 1] = NULL;

0 commit comments

Comments
 (0)
0