1 /*-------------------------------------------------------------------------
4 * routines supporting merge joins
6 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/executor/nodeMergejoin.c
13 *-------------------------------------------------------------------------
17 * ExecMergeJoin mergejoin outer and inner relations.
18 * ExecInitMergeJoin creates and initializes run time states
19 * ExecEndMergeJoin cleans up the node.
23 * Merge-join is done by joining the inner and outer tuples satisfying
24 * join clauses of the form ((= outerKey innerKey) ...).
25 * The join clause list is provided by the query planner and may contain
26 * more than one (= outerKey innerKey) clause (for composite sort key).
28 * However, the query executor needs to know whether an outer
29 * tuple is "greater/smaller" than an inner tuple so that it can
30 * "synchronize" the two relations. For example, consider the following
33 * outer: (0 ^1 1 2 5 5 5 6 6 7) current tuple: 1
34 * inner: (1 ^3 5 5 5 5 6) current tuple: 3
36 * To continue the merge-join, the executor needs to scan both inner
37 * and outer relations till the matching tuples 5. It needs to know
38 * that currently inner tuple 3 is "greater" than outer tuple 1 and
39 * therefore it should scan the outer relation first to find a
40 * matching tuple and so on.
42 * Therefore, rather than directly executing the merge join clauses,
43 * we evaluate the left and right key expressions separately and then
44 * compare the columns one at a time (see MJCompare). The planner
45 * passes us enough information about the sort ordering of the inputs
46 * to allow us to determine how to make the comparison. We may use the
47 * appropriate btree comparison function, since Postgres' only notion
48 * of ordering is specified by btree opfamilies.
51 * Consider the above relations and suppose that the executor has
52 * just joined the first outer "5" with the last inner "5". The
53 * next step is of course to join the second outer "5" with all
54 * the inner "5's". This requires repositioning the inner "cursor"
55 * to point at the first inner "5". This is done by "marking" the
56 * first inner 5 so we can restore the "cursor" to it before joining
57 * with the second outer 5. The access method interface provides
58 * routines to mark and restore to a tuple.
61 * Essential operation of the merge join algorithm is as follows:
64 * get initial outer and inner tuples INITIALIZE
66 * while (outer != inner) { SKIP_TEST
68 * advance outer SKIPOUTER_ADVANCE
70 * advance inner SKIPINNER_ADVANCE
72 * mark inner position SKIP_TEST
74 * while (outer == inner) {
75 * join tuples JOINTUPLES
76 * advance inner position NEXTINNER
78 * advance outer position NEXTOUTER
79 * if (outer == mark) TESTOUTER
80 * restore inner position to mark TESTOUTER
82 * break // return to top of outer loop
87 * The merge join operation is coded in the fashion
88 * of a state machine. At each state, we do something and then
89 * proceed to another state. This state is stored in the node's
90 * execution state information and is preserved across calls to
91 * ExecMergeJoin. -cim 10/31/89
95 #include "access/nbtree.h"
96 #include "executor/execdebug.h"
97 #include "executor/nodeMergejoin.h"
98 #include "miscadmin.h"
99 #include "utils/acl.h"
100 #include "utils/lsyscache.h"
101 #include "utils/memutils.h"
105 * States of the ExecMergeJoin state machine
107 #define EXEC_MJ_INITIALIZE_OUTER 1
108 #define EXEC_MJ_INITIALIZE_INNER 2
109 #define EXEC_MJ_JOINTUPLES 3
110 #define EXEC_MJ_NEXTOUTER 4
111 #define EXEC_MJ_TESTOUTER 5
112 #define EXEC_MJ_NEXTINNER 6
113 #define EXEC_MJ_SKIP_TEST 7
114 #define EXEC_MJ_SKIPOUTER_ADVANCE 8
115 #define EXEC_MJ_SKIPINNER_ADVANCE 9
116 #define EXEC_MJ_ENDOUTER 10
117 #define EXEC_MJ_ENDINNER 11
120 * Runtime data for each mergejoin clause
122 typedef struct MergeJoinClauseData
124 /* Executable expression trees */
125 ExprState *lexpr; /* left-hand (outer) input expression */
126 ExprState *rexpr; /* right-hand (inner) input expression */
129 * If we have a current left or right input tuple, the values of the
130 * expressions are loaded into these fields:
132 Datum ldatum; /* current left-hand value */
133 Datum rdatum; /* current right-hand value */
134 bool lisnull; /* and their isnull flags */
138 * The comparison strategy in use, and the lookup info to let us call the
139 * btree comparison support function, and the collation to use.
141 bool reverse; /* if true, negate the cmpfn's output */
142 bool nulls_first; /* if true, nulls sort low */
145 } MergeJoinClauseData;
147 /* Result type for MJEvalOuterValues and MJEvalInnerValues */
150 MJEVAL_MATCHABLE, /* normal, potentially matchable tuple */
151 MJEVAL_NONMATCHABLE, /* tuple cannot join because it has a null */
152 MJEVAL_ENDOFJOIN /* end of input (physical or effective) */
156 #define MarkInnerTuple(innerTupleSlot, mergestate) \
157 ExecCopySlot((mergestate)->mj_MarkedTupleSlot, (innerTupleSlot))
163 * This deconstructs the list of mergejoinable expressions, which is given
164 * to us by the planner in the form of a list of "leftexpr = rightexpr"
165 * expression trees in the order matching the sort columns of the inputs.
166 * We build an array of MergeJoinClause structs containing the information
167 * we will need at runtime. Each struct essentially tells us how to compare
168 * the two expressions from the original clause.
170 * In addition to the expressions themselves, the planner passes the btree
171 * opfamily OID, collation OID, btree strategy number (BTLessStrategyNumber or
172 * BTGreaterStrategyNumber), and nulls-first flag that identify the intended
173 * sort ordering for each merge key. The mergejoinable operator is an
174 * equality operator in the opfamily, and the two inputs are guaranteed to be
175 * ordered in either increasing or decreasing (respectively) order according
176 * to the opfamily and collation, with nulls at the indicated end of the range.
177 * This allows us to obtain the needed comparison function from the opfamily.
179 static MergeJoinClause
180 MJExamineQuals(List *mergeclauses,
182 Oid *mergecollations,
183 int *mergestrategies,
184 bool *mergenullsfirst,
187 MergeJoinClause clauses;
188 int nClauses = list_length(mergeclauses);
192 clauses = (MergeJoinClause) palloc0(nClauses * sizeof(MergeJoinClauseData));
195 foreach(cl, mergeclauses)
197 OpExpr *qual = (OpExpr *) lfirst(cl);
198 MergeJoinClause clause = &clauses[iClause];
199 Oid opfamily = mergefamilies[iClause];
200 Oid collation = mergecollations[iClause];
201 StrategyNumber opstrategy = mergestrategies[iClause];
202 bool nulls_first = mergenullsfirst[iClause];
206 RegProcedure cmpproc;
209 if (!IsA(qual, OpExpr))
210 elog(ERROR, "mergejoin clause is not an OpExpr");
213 * Prepare the input expressions for execution.
215 clause->lexpr = ExecInitExpr((Expr *) linitial(qual->args), parent);
216 clause->rexpr = ExecInitExpr((Expr *) lsecond(qual->args), parent);
218 /* Extract the operator's declared left/right datatypes */
219 get_op_opfamily_properties(qual->opno, opfamily, false,
223 if (op_strategy != BTEqualStrategyNumber) /* should not happen */
224 elog(ERROR, "cannot merge using non-equality operator %u",
227 /* And get the matching support procedure (comparison function) */
228 cmpproc = get_opfamily_proc(opfamily,
232 if (!RegProcedureIsValid(cmpproc)) /* should not happen */
233 elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
234 BTORDER_PROC, op_lefttype, op_righttype, opfamily);
236 /* Check permission to call cmp function */
237 aclresult = pg_proc_aclcheck(cmpproc, GetUserId(), ACL_EXECUTE);
238 if (aclresult != ACLCHECK_OK)
239 aclcheck_error(aclresult, ACL_KIND_PROC,
240 get_func_name(cmpproc));
242 /* Set up the fmgr lookup information */
243 fmgr_info(cmpproc, &(clause->cmpfinfo));
245 /* Fill the additional comparison-strategy flags */
246 if (opstrategy == BTLessStrategyNumber)
247 clause->reverse = false;
248 else if (opstrategy == BTGreaterStrategyNumber)
249 clause->reverse = true;
250 else /* planner screwed up */
251 elog(ERROR, "unsupported mergejoin strategy %d", opstrategy);
253 clause->nulls_first = nulls_first;
255 /* ... and the collation too */
256 clause->collation = collation;
267 * Compute the values of the mergejoined expressions for the current
268 * outer tuple. We also detect whether it's impossible for the current
269 * outer tuple to match anything --- this is true if it yields a NULL
270 * input, since we assume mergejoin operators are strict. If the NULL
271 * is in the first join column, and that column sorts nulls last, then
272 * we can further conclude that no following tuple can match anything
273 * either, since they must all have nulls in the first column. However,
274 * that case is only interesting if we're not in FillOuter mode, else
275 * we have to visit all the tuples anyway.
277 * For the convenience of callers, we also make this routine responsible
278 * for testing for end-of-input (null outer tuple), and returning
279 * MJEVAL_ENDOFJOIN when that's seen. This allows the same code to be used
280 * for both real end-of-input and the effective end-of-input represented by
281 * a first-column NULL.
283 * We evaluate the values in OuterEContext, which can be reset each
284 * time we move to a new tuple.
287 MJEvalOuterValues(MergeJoinState *mergestate)
289 ExprContext *econtext = mergestate->mj_OuterEContext;
290 MJEvalResult result = MJEVAL_MATCHABLE;
292 MemoryContext oldContext;
294 /* Check for end of outer subplan */
295 if (TupIsNull(mergestate->mj_OuterTupleSlot))
296 return MJEVAL_ENDOFJOIN;
298 ResetExprContext(econtext);
300 oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
302 econtext->ecxt_outertuple = mergestate->mj_OuterTupleSlot;
304 for (i = 0; i < mergestate->mj_NumClauses; i++)
306 MergeJoinClause clause = &mergestate->mj_Clauses[i];
308 clause->ldatum = ExecEvalExpr(clause->lexpr, econtext,
309 &clause->lisnull, NULL);
312 /* match is impossible; can we end the join early? */
313 if (i == 0 && !clause->nulls_first && !mergestate->mj_FillOuter)
314 result = MJEVAL_ENDOFJOIN;
315 else if (result == MJEVAL_MATCHABLE)
316 result = MJEVAL_NONMATCHABLE;
320 MemoryContextSwitchTo(oldContext);
328 * Same as above, but for the inner tuple. Here, we have to be prepared
329 * to load data from either the true current inner, or the marked inner,
330 * so caller must tell us which slot to load from.
333 MJEvalInnerValues(MergeJoinState *mergestate, TupleTableSlot *innerslot)
335 ExprContext *econtext = mergestate->mj_InnerEContext;
336 MJEvalResult result = MJEVAL_MATCHABLE;
338 MemoryContext oldContext;
340 /* Check for end of inner subplan */
341 if (TupIsNull(innerslot))
342 return MJEVAL_ENDOFJOIN;
344 ResetExprContext(econtext);
346 oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
348 econtext->ecxt_innertuple = innerslot;
350 for (i = 0; i < mergestate->mj_NumClauses; i++)
352 MergeJoinClause clause = &mergestate->mj_Clauses[i];
354 clause->rdatum = ExecEvalExpr(clause->rexpr, econtext,
355 &clause->risnull, NULL);
358 /* match is impossible; can we end the join early? */
359 if (i == 0 && !clause->nulls_first && !mergestate->mj_FillInner)
360 result = MJEVAL_ENDOFJOIN;
361 else if (result == MJEVAL_MATCHABLE)
362 result = MJEVAL_NONMATCHABLE;
366 MemoryContextSwitchTo(oldContext);
374 * Compare the mergejoinable values of the current two input tuples
375 * and return 0 if they are equal (ie, the mergejoin equalities all
376 * succeed), +1 if outer > inner, -1 if outer < inner.
378 * MJEvalOuterValues and MJEvalInnerValues must already have been called
379 * for the current outer and inner tuples, respectively.
382 MJCompare(MergeJoinState *mergestate)
385 bool nulleqnull = false;
386 ExprContext *econtext = mergestate->js.ps.ps_ExprContext;
388 MemoryContext oldContext;
389 FunctionCallInfoData fcinfo;
392 * Call the comparison functions in short-lived context, in case they leak
395 ResetExprContext(econtext);
397 oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
399 for (i = 0; i < mergestate->mj_NumClauses; i++)
401 MergeJoinClause clause = &mergestate->mj_Clauses[i];
405 * Deal with null inputs.
411 nulleqnull = true; /* NULL "=" NULL */
414 if (clause->nulls_first)
415 result = -1; /* NULL "<" NOT_NULL */
417 result = 1; /* NULL ">" NOT_NULL */
422 if (clause->nulls_first)
423 result = 1; /* NOT_NULL ">" NULL */
425 result = -1; /* NOT_NULL "<" NULL */
430 * OK to call the comparison function.
432 InitFunctionCallInfoData(fcinfo, &(clause->cmpfinfo), 2,
433 clause->collation, NULL, NULL);
434 fcinfo.arg[0] = clause->ldatum;
435 fcinfo.arg[1] = clause->rdatum;
436 fcinfo.argnull[0] = false;
437 fcinfo.argnull[1] = false;
438 fresult = FunctionCallInvoke(&fcinfo);
441 nulleqnull = true; /* treat like NULL = NULL */
444 result = DatumGetInt32(fresult);
454 * If we had any null comparison results or NULL-vs-NULL inputs, we do not
455 * want to report that the tuples are equal. Instead, if result is still
456 * 0, change it to +1. This will result in advancing the inner side of
459 * Likewise, if there was a constant-false joinqual, do not report
460 * equality. We have to check this as part of the mergequals, else the
461 * rescan logic will do the wrong thing.
464 (nulleqnull || mergestate->mj_ConstFalseJoin))
467 MemoryContextSwitchTo(oldContext);
474 * Generate a fake join tuple with nulls for the inner tuple,
475 * and return it if it passes the non-join quals.
477 static TupleTableSlot *
478 MJFillOuter(MergeJoinState *node)
480 ExprContext *econtext = node->js.ps.ps_ExprContext;
481 List *otherqual = node->js.ps.qual;
483 ResetExprContext(econtext);
485 econtext->ecxt_outertuple = node->mj_OuterTupleSlot;
486 econtext->ecxt_innertuple = node->mj_NullInnerTupleSlot;
488 if (ExecQual(otherqual, econtext, false))
491 * qualification succeeded. now form the desired projection tuple and
492 * return the slot containing it.
494 TupleTableSlot *result;
497 MJ_printf("ExecMergeJoin: returning outer fill tuple\n");
499 result = ExecProject(node->js.ps.ps_ProjInfo, &isDone);
501 if (isDone != ExprEndResult)
503 node->js.ps.ps_TupFromTlist =
504 (isDone == ExprMultipleResult);
509 InstrCountFiltered2(node, 1);
515 * Generate a fake join tuple with nulls for the outer tuple,
516 * and return it if it passes the non-join quals.
518 static TupleTableSlot *
519 MJFillInner(MergeJoinState *node)
521 ExprContext *econtext = node->js.ps.ps_ExprContext;
522 List *otherqual = node->js.ps.qual;
524 ResetExprContext(econtext);
526 econtext->ecxt_outertuple = node->mj_NullOuterTupleSlot;
527 econtext->ecxt_innertuple = node->mj_InnerTupleSlot;
529 if (ExecQual(otherqual, econtext, false))
532 * qualification succeeded. now form the desired projection tuple and
533 * return the slot containing it.
535 TupleTableSlot *result;
538 MJ_printf("ExecMergeJoin: returning inner fill tuple\n");
540 result = ExecProject(node->js.ps.ps_ProjInfo, &isDone);
542 if (isDone != ExprEndResult)
544 node->js.ps.ps_TupFromTlist =
545 (isDone == ExprMultipleResult);
550 InstrCountFiltered2(node, 1);
557 * Check that a qual condition is constant true or constant false.
558 * If it is constant false (or null), set *is_const_false to TRUE.
560 * Constant true would normally be represented by a NIL list, but we allow an
561 * actual bool Const as well. We do expect that the planner will have thrown
562 * away any non-constant terms that have been ANDed with a constant false.
565 check_constant_qual(List *qual, bool *is_const_false)
571 Const *con = (Const *) lfirst(lc);
573 if (!con || !IsA(con, Const))
575 if (con->constisnull || !DatumGetBool(con->constvalue))
576 *is_const_false = true;
582 /* ----------------------------------------------------------------
585 * This function is called through the MJ_dump() macro
586 * when EXEC_MERGEJOINDEBUG is defined
587 * ----------------------------------------------------------------
589 #ifdef EXEC_MERGEJOINDEBUG
592 ExecMergeTupleDumpOuter(MergeJoinState *mergestate)
594 TupleTableSlot *outerSlot = mergestate->mj_OuterTupleSlot;
596 printf("==== outer tuple ====\n");
597 if (TupIsNull(outerSlot))
600 MJ_debugtup(outerSlot);
604 ExecMergeTupleDumpInner(MergeJoinState *mergestate)
606 TupleTableSlot *innerSlot = mergestate->mj_InnerTupleSlot;
608 printf("==== inner tuple ====\n");
609 if (TupIsNull(innerSlot))
612 MJ_debugtup(innerSlot);
616 ExecMergeTupleDumpMarked(MergeJoinState *mergestate)
618 TupleTableSlot *markedSlot = mergestate->mj_MarkedTupleSlot;
620 printf("==== marked tuple ====\n");
621 if (TupIsNull(markedSlot))
624 MJ_debugtup(markedSlot);
628 ExecMergeTupleDump(MergeJoinState *mergestate)
630 printf("******** ExecMergeTupleDump ********\n");
632 ExecMergeTupleDumpOuter(mergestate);
633 ExecMergeTupleDumpInner(mergestate);
634 ExecMergeTupleDumpMarked(mergestate);
636 printf("******** \n");
640 /* ----------------------------------------------------------------
642 * ----------------------------------------------------------------
645 ExecMergeJoin(MergeJoinState *node)
651 PlanState *innerPlan;
652 TupleTableSlot *innerTupleSlot;
653 PlanState *outerPlan;
654 TupleTableSlot *outerTupleSlot;
655 ExprContext *econtext;
660 * get information from node
662 innerPlan = innerPlanState(node);
663 outerPlan = outerPlanState(node);
664 econtext = node->js.ps.ps_ExprContext;
665 joinqual = node->js.joinqual;
666 otherqual = node->js.ps.qual;
667 doFillOuter = node->mj_FillOuter;
668 doFillInner = node->mj_FillInner;
671 * Check to see if we're still projecting out tuples from a previous join
672 * tuple (because there is a function-returning-set in the projection
673 * expressions). If so, try to project another one.
675 if (node->js.ps.ps_TupFromTlist)
677 TupleTableSlot *result;
680 result = ExecProject(node->js.ps.ps_ProjInfo, &isDone);
681 if (isDone == ExprMultipleResult)
683 /* Done with that source tuple... */
684 node->js.ps.ps_TupFromTlist = false;
688 * Reset per-tuple memory context to free any expression evaluation
689 * storage allocated in the previous tuple cycle. Note this can't happen
690 * until we're done projecting out tuples from a join tuple.
692 ResetExprContext(econtext);
695 * ok, everything is setup.. let's go to work
702 * get the current state of the join and do things accordingly.
704 switch (node->mj_JoinState)
707 * EXEC_MJ_INITIALIZE_OUTER means that this is the first time
708 * ExecMergeJoin() has been called and so we have to fetch the
709 * first matchable tuple for both outer and inner subplans. We
710 * do the outer side in INITIALIZE_OUTER state, then advance
711 * to INITIALIZE_INNER state for the inner subplan.
713 case EXEC_MJ_INITIALIZE_OUTER:
714 MJ_printf("ExecMergeJoin: EXEC_MJ_INITIALIZE_OUTER\n");
716 outerTupleSlot = ExecProcNode(outerPlan);
717 node->mj_OuterTupleSlot = outerTupleSlot;
719 /* Compute join values and check for unmatchability */
720 switch (MJEvalOuterValues(node))
722 case MJEVAL_MATCHABLE:
723 /* OK to go get the first inner tuple */
724 node->mj_JoinState = EXEC_MJ_INITIALIZE_INNER;
726 case MJEVAL_NONMATCHABLE:
727 /* Stay in same state to fetch next outer tuple */
731 * Generate a fake join tuple with nulls for the
732 * inner tuple, and return it if it passes the
735 TupleTableSlot *result;
737 result = MJFillOuter(node);
742 case MJEVAL_ENDOFJOIN:
743 /* No more outer tuples */
744 MJ_printf("ExecMergeJoin: nothing in outer subplan\n");
748 * Need to emit right-join tuples for remaining
749 * inner tuples. We set MatchedInner = true to
750 * force the ENDOUTER state to advance inner.
752 node->mj_JoinState = EXEC_MJ_ENDOUTER;
753 node->mj_MatchedInner = true;
756 /* Otherwise we're done. */
761 case EXEC_MJ_INITIALIZE_INNER:
762 MJ_printf("ExecMergeJoin: EXEC_MJ_INITIALIZE_INNER\n");
764 innerTupleSlot = ExecProcNode(innerPlan);
765 node->mj_InnerTupleSlot = innerTupleSlot;
767 /* Compute join values and check for unmatchability */
768 switch (MJEvalInnerValues(node, innerTupleSlot))
770 case MJEVAL_MATCHABLE:
773 * OK, we have the initial tuples. Begin by skipping
774 * non-matching tuples.
776 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
778 case MJEVAL_NONMATCHABLE:
779 /* Mark before advancing, if wanted */
780 if (node->mj_ExtraMarks)
781 ExecMarkPos(innerPlan);
782 /* Stay in same state to fetch next inner tuple */
786 * Generate a fake join tuple with nulls for the
787 * outer tuple, and return it if it passes the
790 TupleTableSlot *result;
792 result = MJFillInner(node);
797 case MJEVAL_ENDOFJOIN:
798 /* No more inner tuples */
799 MJ_printf("ExecMergeJoin: nothing in inner subplan\n");
803 * Need to emit left-join tuples for all outer
804 * tuples, including the one we just fetched. We
805 * set MatchedOuter = false to force the ENDINNER
806 * state to emit first tuple before advancing
809 node->mj_JoinState = EXEC_MJ_ENDINNER;
810 node->mj_MatchedOuter = false;
813 /* Otherwise we're done. */
819 * EXEC_MJ_JOINTUPLES means we have two tuples which satisfied
820 * the merge clause so we join them and then proceed to get
821 * the next inner tuple (EXEC_MJ_NEXTINNER).
823 case EXEC_MJ_JOINTUPLES:
824 MJ_printf("ExecMergeJoin: EXEC_MJ_JOINTUPLES\n");
827 * Set the next state machine state. The right things will
828 * happen whether we return this join tuple or just fall
829 * through to continue the state machine execution.
831 node->mj_JoinState = EXEC_MJ_NEXTINNER;
834 * Check the extra qual conditions to see if we actually want
835 * to return this join tuple. If not, can proceed with merge.
836 * We must distinguish the additional joinquals (which must
837 * pass to consider the tuples "matched" for outer-join logic)
838 * from the otherquals (which must pass before we actually
841 * We don't bother with a ResetExprContext here, on the
842 * assumption that we just did one while checking the merge
843 * qual. One per tuple should be sufficient. We do have to
844 * set up the econtext links to the tuples for ExecQual to
847 outerTupleSlot = node->mj_OuterTupleSlot;
848 econtext->ecxt_outertuple = outerTupleSlot;
849 innerTupleSlot = node->mj_InnerTupleSlot;
850 econtext->ecxt_innertuple = innerTupleSlot;
852 qualResult = (joinqual == NIL ||
853 ExecQual(joinqual, econtext, false));
854 MJ_DEBUG_QUAL(joinqual, qualResult);
858 node->mj_MatchedOuter = true;
859 node->mj_MatchedInner = true;
861 /* In an antijoin, we never return a matched tuple */
862 if (node->js.jointype == JOIN_ANTI)
864 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
869 * In a semijoin, we'll consider returning the first
870 * match, but after that we're done with this outer tuple.
872 if (node->js.jointype == JOIN_SEMI)
873 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
875 qualResult = (otherqual == NIL ||
876 ExecQual(otherqual, econtext, false));
877 MJ_DEBUG_QUAL(otherqual, qualResult);
882 * qualification succeeded. now form the desired
883 * projection tuple and return the slot containing it.
885 TupleTableSlot *result;
888 MJ_printf("ExecMergeJoin: returning tuple\n");
890 result = ExecProject(node->js.ps.ps_ProjInfo,
893 if (isDone != ExprEndResult)
895 node->js.ps.ps_TupFromTlist =
896 (isDone == ExprMultipleResult);
901 InstrCountFiltered2(node, 1);
904 InstrCountFiltered1(node, 1);
908 * EXEC_MJ_NEXTINNER means advance the inner scan to the next
909 * tuple. If the tuple is not nil, we then proceed to test it
910 * against the join qualification.
912 * Before advancing, we check to see if we must emit an
913 * outer-join fill tuple for this inner tuple.
915 case EXEC_MJ_NEXTINNER:
916 MJ_printf("ExecMergeJoin: EXEC_MJ_NEXTINNER\n");
918 if (doFillInner && !node->mj_MatchedInner)
921 * Generate a fake join tuple with nulls for the outer
922 * tuple, and return it if it passes the non-join quals.
924 TupleTableSlot *result;
926 node->mj_MatchedInner = true; /* do it only once */
928 result = MJFillInner(node);
934 * now we get the next inner tuple, if any. If there's none,
935 * advance to next outer tuple (which may be able to join to
936 * previously marked tuples).
938 * NB: must NOT do "extraMarks" here, since we may need to
939 * return to previously marked tuples.
941 innerTupleSlot = ExecProcNode(innerPlan);
942 node->mj_InnerTupleSlot = innerTupleSlot;
943 MJ_DEBUG_PROC_NODE(innerTupleSlot);
944 node->mj_MatchedInner = false;
946 /* Compute join values and check for unmatchability */
947 switch (MJEvalInnerValues(node, innerTupleSlot))
949 case MJEVAL_MATCHABLE:
952 * Test the new inner tuple to see if it matches
955 * If they do match, then we join them and move on to
956 * the next inner tuple (EXEC_MJ_JOINTUPLES).
958 * If they do not match then advance to next outer
961 compareResult = MJCompare(node);
962 MJ_DEBUG_COMPARE(compareResult);
964 if (compareResult == 0)
965 node->mj_JoinState = EXEC_MJ_JOINTUPLES;
968 Assert(compareResult < 0);
969 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
972 case MJEVAL_NONMATCHABLE:
975 * It contains a NULL and hence can't match any outer
976 * tuple, so we can skip the comparison and assume the
977 * new tuple is greater than current outer.
979 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
981 case MJEVAL_ENDOFJOIN:
984 * No more inner tuples. However, this might be only
985 * effective and not physical end of inner plan, so
986 * force mj_InnerTupleSlot to null to make sure we
987 * don't fetch more inner tuples. (We need this hack
988 * because we are not transiting to a state where the
989 * inner plan is assumed to be exhausted.)
991 node->mj_InnerTupleSlot = NULL;
992 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
997 /*-------------------------------------------
998 * EXEC_MJ_NEXTOUTER means
1001 * outer tuple - 5 5 - marked tuple
1006 * we know we just bumped into the
1007 * first inner tuple > current outer tuple (or possibly
1008 * the end of the inner stream)
1009 * so get a new outer tuple and then
1010 * proceed to test it against the marked tuple
1011 * (EXEC_MJ_TESTOUTER)
1013 * Before advancing, we check to see if we must emit an
1014 * outer-join fill tuple for this outer tuple.
1015 *------------------------------------------------
1017 case EXEC_MJ_NEXTOUTER:
1018 MJ_printf("ExecMergeJoin: EXEC_MJ_NEXTOUTER\n");
1020 if (doFillOuter && !node->mj_MatchedOuter)
1023 * Generate a fake join tuple with nulls for the inner
1024 * tuple, and return it if it passes the non-join quals.
1026 TupleTableSlot *result;
1028 node->mj_MatchedOuter = true; /* do it only once */
1030 result = MJFillOuter(node);
1036 * now we get the next outer tuple, if any
1038 outerTupleSlot = ExecProcNode(outerPlan);
1039 node->mj_OuterTupleSlot = outerTupleSlot;
1040 MJ_DEBUG_PROC_NODE(outerTupleSlot);
1041 node->mj_MatchedOuter = false;
1043 /* Compute join values and check for unmatchability */
1044 switch (MJEvalOuterValues(node))
1046 case MJEVAL_MATCHABLE:
1047 /* Go test the new tuple against the marked tuple */
1048 node->mj_JoinState = EXEC_MJ_TESTOUTER;
1050 case MJEVAL_NONMATCHABLE:
1051 /* Can't match, so fetch next outer tuple */
1052 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
1054 case MJEVAL_ENDOFJOIN:
1055 /* No more outer tuples */
1056 MJ_printf("ExecMergeJoin: end of outer subplan\n");
1057 innerTupleSlot = node->mj_InnerTupleSlot;
1058 if (doFillInner && !TupIsNull(innerTupleSlot))
1061 * Need to emit right-join tuples for remaining
1064 node->mj_JoinState = EXEC_MJ_ENDOUTER;
1067 /* Otherwise we're done. */
1072 /*--------------------------------------------------------
1073 * EXEC_MJ_TESTOUTER If the new outer tuple and the marked
1074 * tuple satisfy the merge clause then we know we have
1075 * duplicates in the outer scan so we have to restore the
1076 * inner scan to the marked tuple and proceed to join the
1077 * new outer tuple with the inner tuples.
1079 * This is the case when
1081 * 4 5 - marked tuple
1083 * new outer tuple - 5 5
1087 * new outer tuple == marked tuple
1089 * If the outer tuple fails the test, then we are done
1090 * with the marked tuples, and we have to look for a
1091 * match to the current inner tuple. So we will
1092 * proceed to skip outer tuples until outer >= inner
1093 * (EXEC_MJ_SKIP_TEST).
1095 * This is the case when
1098 * 5 5 - marked tuple
1100 * new outer tuple - 6 8 - inner tuple
1103 * new outer tuple > marked tuple
1105 *---------------------------------------------------------
1107 case EXEC_MJ_TESTOUTER:
1108 MJ_printf("ExecMergeJoin: EXEC_MJ_TESTOUTER\n");
1111 * Here we must compare the outer tuple with the marked inner
1112 * tuple. (We can ignore the result of MJEvalInnerValues,
1113 * since the marked inner tuple is certainly matchable.)
1115 innerTupleSlot = node->mj_MarkedTupleSlot;
1116 (void) MJEvalInnerValues(node, innerTupleSlot);
1118 compareResult = MJCompare(node);
1119 MJ_DEBUG_COMPARE(compareResult);
1121 if (compareResult == 0)
1124 * the merge clause matched so now we restore the inner
1125 * scan position to the first mark, and go join that tuple
1126 * (and any following ones) to the new outer.
1128 * NOTE: we do not need to worry about the MatchedInner
1129 * state for the rescanned inner tuples. We know all of
1130 * them will match this new outer tuple and therefore
1131 * won't be emitted as fill tuples. This works *only*
1132 * because we require the extra joinquals to be constant
1133 * when doing a right or full join --- otherwise some of
1134 * the rescanned tuples might fail the extra joinquals.
1135 * This obviously won't happen for a constant-true extra
1136 * joinqual, while the constant-false case is handled by
1137 * forcing the merge clause to never match, so we never
1140 ExecRestrPos(innerPlan);
1143 * ExecRestrPos probably should give us back a new Slot,
1144 * but since it doesn't, use the marked slot. (The
1145 * previously returned mj_InnerTupleSlot cannot be assumed
1146 * to hold the required tuple.)
1148 node->mj_InnerTupleSlot = innerTupleSlot;
1149 /* we need not do MJEvalInnerValues again */
1151 node->mj_JoinState = EXEC_MJ_JOINTUPLES;
1156 * if the new outer tuple didn't match the marked inner
1157 * tuple then we have a case like:
1160 * 4 4 - marked tuple
1165 * which means that all subsequent outer tuples will be
1166 * larger than our marked inner tuples. So we need not
1167 * revisit any of the marked tuples but can proceed to
1168 * look for a match to the current inner. If there's
1169 * no more inners, no more matches are possible.
1172 Assert(compareResult > 0);
1173 innerTupleSlot = node->mj_InnerTupleSlot;
1175 /* reload comparison data for current inner */
1176 switch (MJEvalInnerValues(node, innerTupleSlot))
1178 case MJEVAL_MATCHABLE:
1179 /* proceed to compare it to the current outer */
1180 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
1182 case MJEVAL_NONMATCHABLE:
1185 * current inner can't possibly match any outer;
1186 * better to advance the inner scan than the
1189 node->mj_JoinState = EXEC_MJ_SKIPINNER_ADVANCE;
1191 case MJEVAL_ENDOFJOIN:
1192 /* No more inner tuples */
1196 * Need to emit left-join tuples for remaining
1199 node->mj_JoinState = EXEC_MJ_ENDINNER;
1202 /* Otherwise we're done. */
1208 /*----------------------------------------------------------
1209 * EXEC_MJ_SKIP means compare tuples and if they do not
1210 * match, skip whichever is lesser.
1217 * outer tuple - 6 8 - inner tuple
1221 * we have to advance the outer scan
1222 * until we find the outer 8.
1224 * On the other hand:
1229 * outer tuple - 12 8 - inner tuple
1233 * we have to advance the inner scan
1234 * until we find the inner 12.
1235 *----------------------------------------------------------
1237 case EXEC_MJ_SKIP_TEST:
1238 MJ_printf("ExecMergeJoin: EXEC_MJ_SKIP_TEST\n");
1241 * before we advance, make sure the current tuples do not
1242 * satisfy the mergeclauses. If they do, then we update the
1243 * marked tuple position and go join them.
1245 compareResult = MJCompare(node);
1246 MJ_DEBUG_COMPARE(compareResult);
1248 if (compareResult == 0)
1250 ExecMarkPos(innerPlan);
1252 MarkInnerTuple(node->mj_InnerTupleSlot, node);
1254 node->mj_JoinState = EXEC_MJ_JOINTUPLES;
1256 else if (compareResult < 0)
1257 node->mj_JoinState = EXEC_MJ_SKIPOUTER_ADVANCE;
1259 /* compareResult > 0 */
1260 node->mj_JoinState = EXEC_MJ_SKIPINNER_ADVANCE;
1264 * SKIPOUTER_ADVANCE: advance over an outer tuple that is
1265 * known not to join to any inner tuple.
1267 * Before advancing, we check to see if we must emit an
1268 * outer-join fill tuple for this outer tuple.
1270 case EXEC_MJ_SKIPOUTER_ADVANCE:
1271 MJ_printf("ExecMergeJoin: EXEC_MJ_SKIPOUTER_ADVANCE\n");
1273 if (doFillOuter && !node->mj_MatchedOuter)
1276 * Generate a fake join tuple with nulls for the inner
1277 * tuple, and return it if it passes the non-join quals.
1279 TupleTableSlot *result;
1281 node->mj_MatchedOuter = true; /* do it only once */
1283 result = MJFillOuter(node);
1289 * now we get the next outer tuple, if any
1291 outerTupleSlot = ExecProcNode(outerPlan);
1292 node->mj_OuterTupleSlot = outerTupleSlot;
1293 MJ_DEBUG_PROC_NODE(outerTupleSlot);
1294 node->mj_MatchedOuter = false;
1296 /* Compute join values and check for unmatchability */
1297 switch (MJEvalOuterValues(node))
1299 case MJEVAL_MATCHABLE:
1300 /* Go test the new tuple against the current inner */
1301 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
1303 case MJEVAL_NONMATCHABLE:
1304 /* Can't match, so fetch next outer tuple */
1305 node->mj_JoinState = EXEC_MJ_SKIPOUTER_ADVANCE;
1307 case MJEVAL_ENDOFJOIN:
1308 /* No more outer tuples */
1309 MJ_printf("ExecMergeJoin: end of outer subplan\n");
1310 innerTupleSlot = node->mj_InnerTupleSlot;
1311 if (doFillInner && !TupIsNull(innerTupleSlot))
1314 * Need to emit right-join tuples for remaining
1317 node->mj_JoinState = EXEC_MJ_ENDOUTER;
1320 /* Otherwise we're done. */
1326 * SKIPINNER_ADVANCE: advance over an inner tuple that is
1327 * known not to join to any outer tuple.
1329 * Before advancing, we check to see if we must emit an
1330 * outer-join fill tuple for this inner tuple.
1332 case EXEC_MJ_SKIPINNER_ADVANCE:
1333 MJ_printf("ExecMergeJoin: EXEC_MJ_SKIPINNER_ADVANCE\n");
1335 if (doFillInner && !node->mj_MatchedInner)
1338 * Generate a fake join tuple with nulls for the outer
1339 * tuple, and return it if it passes the non-join quals.
1341 TupleTableSlot *result;
1343 node->mj_MatchedInner = true; /* do it only once */
1345 result = MJFillInner(node);
1350 /* Mark before advancing, if wanted */
1351 if (node->mj_ExtraMarks)
1352 ExecMarkPos(innerPlan);
1355 * now we get the next inner tuple, if any
1357 innerTupleSlot = ExecProcNode(innerPlan);
1358 node->mj_InnerTupleSlot = innerTupleSlot;
1359 MJ_DEBUG_PROC_NODE(innerTupleSlot);
1360 node->mj_MatchedInner = false;
1362 /* Compute join values and check for unmatchability */
1363 switch (MJEvalInnerValues(node, innerTupleSlot))
1365 case MJEVAL_MATCHABLE:
1366 /* proceed to compare it to the current outer */
1367 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
1369 case MJEVAL_NONMATCHABLE:
1372 * current inner can't possibly match any outer;
1373 * better to advance the inner scan than the outer.
1375 node->mj_JoinState = EXEC_MJ_SKIPINNER_ADVANCE;
1377 case MJEVAL_ENDOFJOIN:
1378 /* No more inner tuples */
1379 MJ_printf("ExecMergeJoin: end of inner subplan\n");
1380 outerTupleSlot = node->mj_OuterTupleSlot;
1381 if (doFillOuter && !TupIsNull(outerTupleSlot))
1384 * Need to emit left-join tuples for remaining
1387 node->mj_JoinState = EXEC_MJ_ENDINNER;
1390 /* Otherwise we're done. */
1396 * EXEC_MJ_ENDOUTER means we have run out of outer tuples, but
1397 * are doing a right/full join and therefore must null-fill
1398 * any remaing unmatched inner tuples.
1400 case EXEC_MJ_ENDOUTER:
1401 MJ_printf("ExecMergeJoin: EXEC_MJ_ENDOUTER\n");
1403 Assert(doFillInner);
1405 if (!node->mj_MatchedInner)
1408 * Generate a fake join tuple with nulls for the outer
1409 * tuple, and return it if it passes the non-join quals.
1411 TupleTableSlot *result;
1413 node->mj_MatchedInner = true; /* do it only once */
1415 result = MJFillInner(node);
1420 /* Mark before advancing, if wanted */
1421 if (node->mj_ExtraMarks)
1422 ExecMarkPos(innerPlan);
1425 * now we get the next inner tuple, if any
1427 innerTupleSlot = ExecProcNode(innerPlan);
1428 node->mj_InnerTupleSlot = innerTupleSlot;
1429 MJ_DEBUG_PROC_NODE(innerTupleSlot);
1430 node->mj_MatchedInner = false;
1432 if (TupIsNull(innerTupleSlot))
1434 MJ_printf("ExecMergeJoin: end of inner subplan\n");
1438 /* Else remain in ENDOUTER state and process next tuple. */
1442 * EXEC_MJ_ENDINNER means we have run out of inner tuples, but
1443 * are doing a left/full join and therefore must null- fill
1444 * any remaing unmatched outer tuples.
1446 case EXEC_MJ_ENDINNER:
1447 MJ_printf("ExecMergeJoin: EXEC_MJ_ENDINNER\n");
1449 Assert(doFillOuter);
1451 if (!node->mj_MatchedOuter)
1454 * Generate a fake join tuple with nulls for the inner
1455 * tuple, and return it if it passes the non-join quals.
1457 TupleTableSlot *result;
1459 node->mj_MatchedOuter = true; /* do it only once */
1461 result = MJFillOuter(node);
1467 * now we get the next outer tuple, if any
1469 outerTupleSlot = ExecProcNode(outerPlan);
1470 node->mj_OuterTupleSlot = outerTupleSlot;
1471 MJ_DEBUG_PROC_NODE(outerTupleSlot);
1472 node->mj_MatchedOuter = false;
1474 if (TupIsNull(outerTupleSlot))
1476 MJ_printf("ExecMergeJoin: end of outer subplan\n");
1480 /* Else remain in ENDINNER state and process next tuple. */
1484 * broken state value?
1487 elog(ERROR, "unrecognized mergejoin state: %d",
1488 (int) node->mj_JoinState);
1493 /* ----------------------------------------------------------------
1495 * ----------------------------------------------------------------
1498 ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags)
1500 MergeJoinState *mergestate;
1502 /* check for unsupported flags */
1503 Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
1505 MJ1_printf("ExecInitMergeJoin: %s\n",
1506 "initializing node");
1509 * create state structure
1511 mergestate = makeNode(MergeJoinState);
1512 mergestate->js.ps.plan = (Plan *) node;
1513 mergestate->js.ps.state = estate;
1516 * Miscellaneous initialization
1518 * create expression context for node
1520 ExecAssignExprContext(estate, &mergestate->js.ps);
1523 * we need two additional econtexts in which we can compute the join
1524 * expressions from the left and right input tuples. The node's regular
1525 * econtext won't do because it gets reset too often.
1527 mergestate->mj_OuterEContext = CreateExprContext(estate);
1528 mergestate->mj_InnerEContext = CreateExprContext(estate);
1531 * initialize child expressions
1533 mergestate->js.ps.targetlist = (List *)
1534 ExecInitExpr((Expr *) node->join.plan.targetlist,
1535 (PlanState *) mergestate);
1536 mergestate->js.ps.qual = (List *)
1537 ExecInitExpr((Expr *) node->join.plan.qual,
1538 (PlanState *) mergestate);
1539 mergestate->js.jointype = node->join.jointype;
1540 mergestate->js.joinqual = (List *)
1541 ExecInitExpr((Expr *) node->join.joinqual,
1542 (PlanState *) mergestate);
1543 mergestate->mj_ConstFalseJoin = false;
1544 /* mergeclauses are handled below */
1547 * initialize child nodes
1549 * inner child must support MARK/RESTORE.
1551 outerPlanState(mergestate) = ExecInitNode(outerPlan(node), estate, eflags);
1552 innerPlanState(mergestate) = ExecInitNode(innerPlan(node), estate,
1553 eflags | EXEC_FLAG_MARK);
1556 * For certain types of inner child nodes, it is advantageous to issue
1557 * MARK every time we advance past an inner tuple we will never return to.
1558 * For other types, MARK on a tuple we cannot return to is a waste of
1559 * cycles. Detect which case applies and set mj_ExtraMarks if we want to
1560 * issue "unnecessary" MARK calls.
1562 * Currently, only Material wants the extra MARKs, and it will be helpful
1563 * only if eflags doesn't specify REWIND.
1565 if (IsA(innerPlan(node), Material) &&
1566 (eflags & EXEC_FLAG_REWIND) == 0)
1567 mergestate->mj_ExtraMarks = true;
1569 mergestate->mj_ExtraMarks = false;
1572 * tuple table initialization
1574 ExecInitResultTupleSlot(estate, &mergestate->js.ps);
1576 mergestate->mj_MarkedTupleSlot = ExecInitExtraTupleSlot(estate);
1577 ExecSetSlotDescriptor(mergestate->mj_MarkedTupleSlot,
1578 ExecGetResultType(innerPlanState(mergestate)));
1580 switch (node->join.jointype)
1584 mergestate->mj_FillOuter = false;
1585 mergestate->mj_FillInner = false;
1589 mergestate->mj_FillOuter = true;
1590 mergestate->mj_FillInner = false;
1591 mergestate->mj_NullInnerTupleSlot =
1592 ExecInitNullTupleSlot(estate,
1593 ExecGetResultType(innerPlanState(mergestate)));
1596 mergestate->mj_FillOuter = false;
1597 mergestate->mj_FillInner = true;
1598 mergestate->mj_NullOuterTupleSlot =
1599 ExecInitNullTupleSlot(estate,
1600 ExecGetResultType(outerPlanState(mergestate)));
1603 * Can't handle right or full join with non-constant extra
1604 * joinclauses. This should have been caught by planner.
1606 if (!check_constant_qual(node->join.joinqual,
1607 &mergestate->mj_ConstFalseJoin))
1609 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1610 errmsg("RIGHT JOIN is only supported with merge-joinable join conditions")));
1613 mergestate->mj_FillOuter = true;
1614 mergestate->mj_FillInner = true;
1615 mergestate->mj_NullOuterTupleSlot =
1616 ExecInitNullTupleSlot(estate,
1617 ExecGetResultType(outerPlanState(mergestate)));
1618 mergestate->mj_NullInnerTupleSlot =
1619 ExecInitNullTupleSlot(estate,
1620 ExecGetResultType(innerPlanState(mergestate)));
1623 * Can't handle right or full join with non-constant extra
1624 * joinclauses. This should have been caught by planner.
1626 if (!check_constant_qual(node->join.joinqual,
1627 &mergestate->mj_ConstFalseJoin))
1629 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1630 errmsg("FULL JOIN is only supported with merge-joinable join conditions")));
1633 elog(ERROR, "unrecognized join type: %d",
1634 (int) node->join.jointype);
1638 * initialize tuple type and projection info
1640 ExecAssignResultTypeFromTL(&mergestate->js.ps);
1641 ExecAssignProjectionInfo(&mergestate->js.ps, NULL);
1644 * preprocess the merge clauses
1646 mergestate->mj_NumClauses = list_length(node->mergeclauses);
1647 mergestate->mj_Clauses = MJExamineQuals(node->mergeclauses,
1648 node->mergeFamilies,
1649 node->mergeCollations,
1650 node->mergeStrategies,
1651 node->mergeNullsFirst,
1652 (PlanState *) mergestate);
1655 * initialize join state
1657 mergestate->mj_JoinState = EXEC_MJ_INITIALIZE_OUTER;
1658 mergestate->js.ps.ps_TupFromTlist = false;
1659 mergestate->mj_MatchedOuter = false;
1660 mergestate->mj_MatchedInner = false;
1661 mergestate->mj_OuterTupleSlot = NULL;
1662 mergestate->mj_InnerTupleSlot = NULL;
1665 * initialization successful
1667 MJ1_printf("ExecInitMergeJoin: %s\n",
1668 "node initialized");
1673 /* ----------------------------------------------------------------
1677 * frees storage allocated through C routines.
1678 * ----------------------------------------------------------------
1681 ExecEndMergeJoin(MergeJoinState *node)
1683 MJ1_printf("ExecEndMergeJoin: %s\n",
1684 "ending node processing");
1687 * Free the exprcontext
1689 ExecFreeExprContext(&node->js.ps);
1692 * clean out the tuple table
1694 ExecClearTuple(node->js.ps.ps_ResultTupleSlot);
1695 ExecClearTuple(node->mj_MarkedTupleSlot);
1698 * shut down the subplans
1700 ExecEndNode(innerPlanState(node));
1701 ExecEndNode(outerPlanState(node));
1703 MJ1_printf("ExecEndMergeJoin: %s\n",
1704 "node processing ended");
1708 ExecReScanMergeJoin(MergeJoinState *node)
1710 ExecClearTuple(node->mj_MarkedTupleSlot);
1712 node->mj_JoinState = EXEC_MJ_INITIALIZE_OUTER;
1713 node->js.ps.ps_TupFromTlist = false;
1714 node->mj_MatchedOuter = false;
1715 node->mj_MatchedInner = false;
1716 node->mj_OuterTupleSlot = NULL;
1717 node->mj_InnerTupleSlot = NULL;
1720 * if chgParam of subnodes is not null then plans will be re-scanned by
1721 * first ExecProcNode.
1723 if (node->js.ps.lefttree->chgParam == NULL)
1724 ExecReScan(node->js.ps.lefttree);
1725 if (node->js.ps.righttree->chgParam == NULL)
1726 ExecReScan(node->js.ps.righttree);