diff options
Diffstat (limited to 'src/backend/executor/nodeNestloop.c')
-rw-r--r-- | src/backend/executor/nodeNestloop.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/backend/executor/nodeNestloop.c b/src/backend/executor/nodeNestloop.c index 53977e0b329..69d245358e6 100644 --- a/src/backend/executor/nodeNestloop.c +++ b/src/backend/executor/nodeNestloop.c @@ -219,10 +219,11 @@ ExecNestLoop(NestLoopState *node) } /* - * In a semijoin, we'll consider returning the first match, but - * after that we're done with this outer tuple. + * If we only need to join to the first matching inner tuple, then + * consider returning this one, but after that continue with next + * outer tuple. */ - if (node->js.jointype == JOIN_SEMI) + if (node->js.single_match) node->nl_NeedNewOuter = true; if (otherqual == NULL || ExecQual(otherqual, econtext)) @@ -309,6 +310,13 @@ ExecInitNestLoop(NestLoop *node, EState *estate, int eflags) */ ExecInitResultTupleSlot(estate, &nlstate->js.ps); + /* + * detect whether we need only consider the first matching inner tuple + */ + nlstate->js.single_match = (node->join.inner_unique || + node->join.jointype == JOIN_SEMI); + + /* set up null tuples for outer joins, if needed */ switch (node->join.jointype) { case JOIN_INNER: |