aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeHashjoin.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2004-09-22 19:13:52 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2004-09-22 19:13:52 +0000
commit9fcbe2af11fb966b30117d8ac3c2971d1be14207 (patch)
tree456b8fcfc82600ec866e153a8f06a0f77a614831 /src/backend/executor/nodeHashjoin.c
parent5d9f5c20dd29ac9dde19c283a821709839fae102 (diff)
downloadpostgresql-9fcbe2af11fb966b30117d8ac3c2971d1be14207.tar.gz
postgresql-9fcbe2af11fb966b30117d8ac3c2971d1be14207.zip
Arrange for hash join to skip scanning the outer relation if it detects
that the inner one is completely empty. Per recent discussion. Also some cosmetic cleanups in nearby code.
Diffstat (limited to 'src/backend/executor/nodeHashjoin.c')
-rw-r--r--src/backend/executor/nodeHashjoin.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/backend/executor/nodeHashjoin.c b/src/backend/executor/nodeHashjoin.c
index 53215be6e91..294f481cdf5 100644
--- a/src/backend/executor/nodeHashjoin.c
+++ b/src/backend/executor/nodeHashjoin.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.65 2004/09/17 18:28:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeHashjoin.c,v 1.66 2004/09/22 19:13:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -128,6 +128,17 @@ ExecHashJoin(HashJoinState *node)
(void) ExecProcNode((PlanState *) hashNode);
/*
+ * If the inner relation is completely empty, and we're not doing
+ * an outer join, we can quit without scanning the outer relation.
+ */
+ if (!hashtable->hashNonEmpty && node->js.jointype != JOIN_LEFT)
+ {
+ ExecHashTableDestroy(hashtable);
+ node->hj_HashTable = NULL;
+ return NULL;
+ }
+
+ /*
* Open temp files for outer batches, if needed. Note that file
* buffers are palloc'd in regular executor context.
*/
@@ -138,10 +149,8 @@ ExecHashJoin(HashJoinState *node)
}
/*
- * Now get an outer tuple and probe into the hash table for matches
+ * run the hash join process
*/
- outerTupleSlot = node->js.ps.ps_OuterTupleSlot;
-
for (;;)
{
/*
@@ -226,7 +235,7 @@ ExecHashJoin(HashJoinState *node)
* Only the joinquals determine MatchedOuter status, but all
* quals must pass to actually return the tuple.
*/
- if (ExecQual(joinqual, econtext, false))
+ if (joinqual == NIL || ExecQual(joinqual, econtext, false))
{
node->hj_MatchedOuter = true;