From: Tom Lane Date: Fri, 17 Sep 2004 18:29:10 +0000 (+0000) Subject: Hashed LEFT JOIN would miss outer tuples with no inner match if the join X-Git-Tag: REL7_4_6~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=50ff8067003ff637d6de566759a8be077a28b2d4;p=thirdparty%2Fpostgresql.git 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. --- diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c index 3d43b7d02b0..b680bfd9ae7 100644 --- a/src/backend/executor/nodeHashjoin.c +++ b/src/backend/executor/nodeHashjoin.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.57.2.1 2003/11/25 19:17:16 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.57.2.2 2004/09/17 18:29:10 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -602,12 +602,14 @@ ExecHashJoinNewBatch(HashJoinState *hjstate) } /* - * We can skip over any batches that are empty on either side. Release - * associated temp files right away. + * Normally we can skip over any batches that are empty on either side + * --- but for JOIN_LEFT, can only skip when left side is empty. + * Release associated temp files right away. */ while (newbatch <= nbatch && - (innerBatchSize[newbatch - 1] == 0L || - outerBatchSize[newbatch - 1] == 0L)) + (outerBatchSize[newbatch - 1] == 0L || + (innerBatchSize[newbatch - 1] == 0L && + hjstate->js.jointype != JOIN_LEFT))) { BufFileClose(hashtable->innerBatchFile[newbatch - 1]); hashtable->innerBatchFile[newbatch - 1] = NULL;