]> granicus.if.org Git - postgresql/commitdiff
Hashed LEFT JOIN would miss outer tuples with no inner match if the join
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Sep 2004 18:29:24 +0000 (18:29 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 17 Sep 2004 18:29:24 +0000 (18:29 +0000)
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.

src/backend/executor/nodeHashjoin.c

index f1484c4a0545769f2f46b80fff147e2b01298168..49abeffce6c1492dc27dfe9d908b24f7149e6e47 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.41 2002/09/02 02:47:02 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.41.2.1 2004/09/17 18:29:24 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -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;