mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
IN clauses appearing at top level of WHERE can now be handled as joins.
There are two implementation techniques: the executor understands a new JOIN_IN jointype, which emits at most one matching row per left-hand row, or the result of the IN's sub-select can be fed through a DISTINCT filter and then joined as an ordinary relation. Along the way, some minor code cleanup in the optimizer; notably, break out most of the jointree-rearrangement preprocessing in planner.c and put it in a new file prep/prepjointree.c.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.46 2002/12/30 15:21:20 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeHashjoin.c,v 1.47 2003/01/20 18:54:45 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -95,6 +95,15 @@ ExecHashJoin(HashJoinState *node)
|
||||
node->js.ps.ps_TupFromTlist = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're doing an IN join, we want to return at most one row per
|
||||
* outer tuple; so we can stop scanning the inner scan if we matched on
|
||||
* the previous try.
|
||||
*/
|
||||
if (node->js.jointype == JOIN_IN &&
|
||||
node->hj_MatchedOuter)
|
||||
node->hj_NeedNewOuter = true;
|
||||
|
||||
/*
|
||||
* Reset per-tuple memory context to free any expression evaluation
|
||||
* storage allocated in the previous tuple cycle. Note this can't
|
||||
@ -353,6 +362,7 @@ ExecInitHashJoin(HashJoin *node, EState *estate)
|
||||
switch (node->join.jointype)
|
||||
{
|
||||
case JOIN_INNER:
|
||||
case JOIN_IN:
|
||||
break;
|
||||
case JOIN_LEFT:
|
||||
hjstate->hj_NullInnerTupleSlot =
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.55 2002/12/15 16:17:46 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeMergejoin.c,v 1.56 2003/01/20 18:54:45 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -381,6 +381,7 @@ ExecMergeJoin(MergeJoinState *node)
|
||||
switch (node->js.jointype)
|
||||
{
|
||||
case JOIN_INNER:
|
||||
case JOIN_IN:
|
||||
doFillOuter = false;
|
||||
doFillInner = false;
|
||||
break;
|
||||
@ -581,9 +582,15 @@ ExecMergeJoin(MergeJoinState *node)
|
||||
* the econtext's tuple pointers were set up before
|
||||
* checking the merge qual, so we needn't do it again.
|
||||
*/
|
||||
qualResult = (joinqual == NIL ||
|
||||
ExecQual(joinqual, econtext, false));
|
||||
MJ_DEBUG_QUAL(joinqual, qualResult);
|
||||
if (node->js.jointype == JOIN_IN &&
|
||||
node->mj_MatchedOuter)
|
||||
qualResult = false;
|
||||
else
|
||||
{
|
||||
qualResult = (joinqual == NIL ||
|
||||
ExecQual(joinqual, econtext, false));
|
||||
MJ_DEBUG_QUAL(joinqual, qualResult);
|
||||
}
|
||||
|
||||
if (qualResult)
|
||||
{
|
||||
@ -1452,6 +1459,7 @@ ExecInitMergeJoin(MergeJoin *node, EState *estate)
|
||||
switch (node->join.jointype)
|
||||
{
|
||||
case JOIN_INNER:
|
||||
case JOIN_IN:
|
||||
break;
|
||||
case JOIN_LEFT:
|
||||
mergestate->mj_NullInnerTupleSlot =
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeNestloop.c,v 1.29 2002/12/15 16:17:46 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/executor/nodeNestloop.c,v 1.30 2003/01/20 18:54:46 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -101,6 +101,15 @@ ExecNestLoop(NestLoopState *node)
|
||||
node->js.ps.ps_TupFromTlist = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're doing an IN join, we want to return at most one row per
|
||||
* outer tuple; so we can stop scanning the inner scan if we matched on
|
||||
* the previous try.
|
||||
*/
|
||||
if (node->js.jointype == JOIN_IN &&
|
||||
node->nl_MatchedOuter)
|
||||
node->nl_NeedNewOuter = true;
|
||||
|
||||
/*
|
||||
* Reset per-tuple memory context to free any expression evaluation
|
||||
* storage allocated in the previous tuple cycle. Note this can't
|
||||
@ -312,6 +321,7 @@ ExecInitNestLoop(NestLoop *node, EState *estate)
|
||||
switch (node->join.jointype)
|
||||
{
|
||||
case JOIN_INNER:
|
||||
case JOIN_IN:
|
||||
break;
|
||||
case JOIN_LEFT:
|
||||
nlstate->nl_NullInnerTupleSlot =
|
||||
|
Reference in New Issue
Block a user