From e006a24ad152b3faec748afe8c1ff0829699b2e6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 14 Aug 2008 18:48:00 +0000 Subject: Implement SEMI and ANTI joins in the planner and executor. (Semijoins replace the old JOIN_IN code, but antijoins are new functionality.) Teach the planner to convert appropriate EXISTS and NOT EXISTS subqueries into semi and anti joins respectively. Also, LEFT JOINs with suitable upper-level IS NULL filters are recognized as being anti joins. Unify the InClauseInfo and OuterJoinInfo infrastructure into "SpecialJoinInfo". With that change, it becomes possible to associate a SpecialJoinInfo with every join attempt, which permits some cleanup of join selectivity estimation. That needs to be taken much further than this patch does, but the next step is to change the API for oprjoin selectivity functions, which seems like material for a separate patch. So for the moment the output size estimates for semi and especially anti joins are quite bogus. --- src/backend/executor/nodeMergejoin.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/backend/executor/nodeMergejoin.c') diff --git a/src/backend/executor/nodeMergejoin.c b/src/backend/executor/nodeMergejoin.c index cf1bb7d0a69..e9deb5c8da7 100644 --- a/src/backend/executor/nodeMergejoin.c +++ b/src/backend/executor/nodeMergejoin.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.91 2008/04/13 20:51:20 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.92 2008/08/14 18:47:58 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -757,7 +757,7 @@ ExecMergeJoin(MergeJoinState *node) innerTupleSlot = node->mj_InnerTupleSlot; econtext->ecxt_innertuple = innerTupleSlot; - if (node->js.jointype == JOIN_IN && + if (node->js.jointype == JOIN_SEMI && node->mj_MatchedOuter) qualResult = false; else @@ -772,6 +772,10 @@ ExecMergeJoin(MergeJoinState *node) node->mj_MatchedOuter = true; node->mj_MatchedInner = true; + /* In an antijoin, we never return a matched tuple */ + if (node->js.jointype == JOIN_ANTI) + break; + qualResult = (otherqual == NIL || ExecQual(otherqual, econtext, false)); MJ_DEBUG_QUAL(otherqual, qualResult); @@ -1472,11 +1476,12 @@ ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags) switch (node->join.jointype) { case JOIN_INNER: - case JOIN_IN: + case JOIN_SEMI: mergestate->mj_FillOuter = false; mergestate->mj_FillInner = false; break; case JOIN_LEFT: + case JOIN_ANTI: mergestate->mj_FillOuter = true; mergestate->mj_FillInner = false; mergestate->mj_NullInnerTupleSlot = -- cgit v1.2.3