From: Tom Lane Date: Fri, 17 Sep 2004 18:29:24 +0000 (+0000) Subject: Hashed LEFT JOIN would miss outer tuples with no inner match if the join X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=9ca9c6f4aa9135422f9a7b28d8c0db5b7be83ffa;p=users%2Fbernd%2Fpostgres.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 5b2b080b05..5c492f9743 100644 --- a/src/backend/executor/nodeHashjoin.c +++ b/src/backend/executor/nodeHashjoin.c @@ -568,12 +568,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;