1 /*-------------------------------------------------------------------------
4 * routines supporting merge joins
6 * Portions Copyright (c) 1996-2010, 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 "catalog/pg_amop.h"
97 #include "executor/execdebug.h"
98 #include "executor/nodeMergejoin.h"
99 #include "miscadmin.h"
100 #include "utils/acl.h"
101 #include "utils/lsyscache.h"
102 #include "utils/memutils.h"
103 #include "utils/syscache.h"
107 * States of the ExecMergeJoin state machine
109 #define EXEC_MJ_INITIALIZE_OUTER 1
110 #define EXEC_MJ_INITIALIZE_INNER 2
111 #define EXEC_MJ_JOINTUPLES 3
112 #define EXEC_MJ_NEXTOUTER 4
113 #define EXEC_MJ_TESTOUTER 5
114 #define EXEC_MJ_NEXTINNER 6
115 #define EXEC_MJ_SKIP_TEST 7
116 #define EXEC_MJ_SKIPOUTER_ADVANCE 8
117 #define EXEC_MJ_SKIPINNER_ADVANCE 9
118 #define EXEC_MJ_ENDOUTER 10
119 #define EXEC_MJ_ENDINNER 11
122 * Runtime data for each mergejoin clause
124 typedef struct MergeJoinClauseData
126 /* Executable expression trees */
127 ExprState *lexpr; /* left-hand (outer) input expression */
128 ExprState *rexpr; /* right-hand (inner) input expression */
131 * If we have a current left or right input tuple, the values of the
132 * expressions are loaded into these fields:
134 Datum ldatum; /* current left-hand value */
135 Datum rdatum; /* current right-hand value */
136 bool lisnull; /* and their isnull flags */
140 * The comparison strategy in use, and the lookup info to let us call the
141 * btree comparison support function.
143 bool reverse; /* if true, negate the cmpfn's output */
144 bool nulls_first; /* if true, nulls sort low */
146 } MergeJoinClauseData;
148 /* Result type for MJEvalOuterValues and MJEvalInnerValues */
151 MJEVAL_MATCHABLE, /* normal, potentially matchable tuple */
152 MJEVAL_NONMATCHABLE, /* tuple cannot join because it has a null */
153 MJEVAL_ENDOFJOIN /* end of input (physical or effective) */
157 #define MarkInnerTuple(innerTupleSlot, mergestate) \
158 ExecCopySlot((mergestate)->mj_MarkedTupleSlot, (innerTupleSlot))
164 * This deconstructs the list of mergejoinable expressions, which is given
165 * to us by the planner in the form of a list of "leftexpr = rightexpr"
166 * expression trees in the order matching the sort columns of the inputs.
167 * We build an array of MergeJoinClause structs containing the information
168 * we will need at runtime. Each struct essentially tells us how to compare
169 * the two expressions from the original clause.
171 * In addition to the expressions themselves, the planner passes the btree
172 * opfamily OID, btree strategy number (BTLessStrategyNumber or
173 * BTGreaterStrategyNumber), and nulls-first flag that identify the intended
174 * sort ordering for each merge key. The mergejoinable operator is an
175 * equality operator in this opfamily, and the two inputs are guaranteed to be
176 * ordered in either increasing or decreasing (respectively) order according
177 * to this opfamily, with nulls at the indicated end of the range. This
178 * allows us to obtain the needed comparison function from the opfamily.
180 static MergeJoinClause
181 MJExamineQuals(List *mergeclauses,
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 StrategyNumber opstrategy = mergestrategies[iClause];
201 bool nulls_first = mergenullsfirst[iClause];
205 RegProcedure cmpproc;
208 if (!IsA(qual, OpExpr))
209 elog(ERROR, "mergejoin clause is not an OpExpr");
212 * Prepare the input expressions for execution.
214 clause->lexpr = ExecInitExpr((Expr *) linitial(qual->args), parent);
215 clause->rexpr = ExecInitExpr((Expr *) lsecond(qual->args), parent);
217 /* Extract the operator's declared left/right datatypes */
218 get_op_opfamily_properties(qual->opno, opfamily, false,
222 if (op_strategy != BTEqualStrategyNumber) /* should not happen */
223 elog(ERROR, "cannot merge using non-equality operator %u",
226 /* And get the matching support procedure (comparison function) */
227 cmpproc = get_opfamily_proc(opfamily,
231 if (!RegProcedureIsValid(cmpproc)) /* should not happen */
232 elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
233 BTORDER_PROC, op_lefttype, op_righttype, opfamily);
235 /* Check permission to call cmp function */
236 aclresult = pg_proc_aclcheck(cmpproc, GetUserId(), ACL_EXECUTE);
237 if (aclresult != ACLCHECK_OK)
238 aclcheck_error(aclresult, ACL_KIND_PROC,
239 get_func_name(cmpproc));
241 /* Set up the fmgr lookup information */
242 fmgr_info(cmpproc, &(clause->cmpfinfo));
244 /* Fill the additional comparison-strategy flags */
245 if (opstrategy == BTLessStrategyNumber)
246 clause->reverse = false;
247 else if (opstrategy == BTGreaterStrategyNumber)
248 clause->reverse = true;
249 else /* planner screwed up */
250 elog(ERROR, "unsupported mergejoin strategy %d", opstrategy);
252 clause->nulls_first = nulls_first;
263 * Compute the values of the mergejoined expressions for the current
264 * outer tuple. We also detect whether it's impossible for the current
265 * outer tuple to match anything --- this is true if it yields a NULL
266 * input, since we assume mergejoin operators are strict. If the NULL
267 * is in the first join column, and that column sorts nulls last, then
268 * we can further conclude that no following tuple can match anything
269 * either, since they must all have nulls in the first column. However,
270 * that case is only interesting if we're not in FillOuter mode, else
271 * we have to visit all the tuples anyway.
273 * For the convenience of callers, we also make this routine responsible
274 * for testing for end-of-input (null outer tuple), and returning
275 * MJEVAL_ENDOFJOIN when that's seen. This allows the same code to be used
276 * for both real end-of-input and the effective end-of-input represented by
277 * a first-column NULL.
279 * We evaluate the values in OuterEContext, which can be reset each
280 * time we move to a new tuple.
283 MJEvalOuterValues(MergeJoinState *mergestate)
285 ExprContext *econtext = mergestate->mj_OuterEContext;
286 MJEvalResult result = MJEVAL_MATCHABLE;
288 MemoryContext oldContext;
290 /* Check for end of outer subplan */
291 if (TupIsNull(mergestate->mj_OuterTupleSlot))
292 return MJEVAL_ENDOFJOIN;
294 ResetExprContext(econtext);
296 oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
298 econtext->ecxt_outertuple = mergestate->mj_OuterTupleSlot;
300 for (i = 0; i < mergestate->mj_NumClauses; i++)
302 MergeJoinClause clause = &mergestate->mj_Clauses[i];
304 clause->ldatum = ExecEvalExpr(clause->lexpr, econtext,
305 &clause->lisnull, NULL);
308 /* match is impossible; can we end the join early? */
309 if (i == 0 && !clause->nulls_first && !mergestate->mj_FillOuter)
310 result = MJEVAL_ENDOFJOIN;
311 else if (result == MJEVAL_MATCHABLE)
312 result = MJEVAL_NONMATCHABLE;
316 MemoryContextSwitchTo(oldContext);
324 * Same as above, but for the inner tuple. Here, we have to be prepared
325 * to load data from either the true current inner, or the marked inner,
326 * so caller must tell us which slot to load from.
329 MJEvalInnerValues(MergeJoinState *mergestate, TupleTableSlot *innerslot)
331 ExprContext *econtext = mergestate->mj_InnerEContext;
332 MJEvalResult result = MJEVAL_MATCHABLE;
334 MemoryContext oldContext;
336 /* Check for end of inner subplan */
337 if (TupIsNull(innerslot))
338 return MJEVAL_ENDOFJOIN;
340 ResetExprContext(econtext);
342 oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
344 econtext->ecxt_innertuple = innerslot;
346 for (i = 0; i < mergestate->mj_NumClauses; i++)
348 MergeJoinClause clause = &mergestate->mj_Clauses[i];
350 clause->rdatum = ExecEvalExpr(clause->rexpr, econtext,
351 &clause->risnull, NULL);
354 /* match is impossible; can we end the join early? */
355 if (i == 0 && !clause->nulls_first && !mergestate->mj_FillInner)
356 result = MJEVAL_ENDOFJOIN;
357 else if (result == MJEVAL_MATCHABLE)
358 result = MJEVAL_NONMATCHABLE;
362 MemoryContextSwitchTo(oldContext);
370 * Compare the mergejoinable values of the current two input tuples
371 * and return 0 if they are equal (ie, the mergejoin equalities all
372 * succeed), +1 if outer > inner, -1 if outer < inner.
374 * MJEvalOuterValues and MJEvalInnerValues must already have been called
375 * for the current outer and inner tuples, respectively.
378 MJCompare(MergeJoinState *mergestate)
381 bool nulleqnull = false;
382 ExprContext *econtext = mergestate->js.ps.ps_ExprContext;
384 MemoryContext oldContext;
385 FunctionCallInfoData fcinfo;
388 * Call the comparison functions in short-lived context, in case they leak
391 ResetExprContext(econtext);
393 oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
395 for (i = 0; i < mergestate->mj_NumClauses; i++)
397 MergeJoinClause clause = &mergestate->mj_Clauses[i];
401 * Deal with null inputs.
407 nulleqnull = true; /* NULL "=" NULL */
410 if (clause->nulls_first)
411 result = -1; /* NULL "<" NOT_NULL */
413 result = 1; /* NULL ">" NOT_NULL */
418 if (clause->nulls_first)
419 result = 1; /* NOT_NULL ">" NULL */
421 result = -1; /* NOT_NULL "<" NULL */
426 * OK to call the comparison function.
428 InitFunctionCallInfoData(fcinfo, &(clause->cmpfinfo), 2,
430 fcinfo.arg[0] = clause->ldatum;
431 fcinfo.arg[1] = clause->rdatum;
432 fcinfo.argnull[0] = false;
433 fcinfo.argnull[1] = false;
434 fresult = FunctionCallInvoke(&fcinfo);
437 nulleqnull = true; /* treat like NULL = NULL */
440 result = DatumGetInt32(fresult);
450 * If we had any null comparison results or NULL-vs-NULL inputs, we do not
451 * want to report that the tuples are equal. Instead, if result is still
452 * 0, change it to +1. This will result in advancing the inner side of
455 * Likewise, if there was a constant-false joinqual, do not report
456 * equality. We have to check this as part of the mergequals, else the
457 * rescan logic will do the wrong thing.
460 (nulleqnull || mergestate->mj_ConstFalseJoin))
463 MemoryContextSwitchTo(oldContext);
470 * Generate a fake join tuple with nulls for the inner tuple,
471 * and return it if it passes the non-join quals.
473 static TupleTableSlot *
474 MJFillOuter(MergeJoinState *node)
476 ExprContext *econtext = node->js.ps.ps_ExprContext;
477 List *otherqual = node->js.ps.qual;
479 ResetExprContext(econtext);
481 econtext->ecxt_outertuple = node->mj_OuterTupleSlot;
482 econtext->ecxt_innertuple = node->mj_NullInnerTupleSlot;
484 if (ExecQual(otherqual, econtext, false))
487 * qualification succeeded. now form the desired projection tuple and
488 * return the slot containing it.
490 TupleTableSlot *result;
493 MJ_printf("ExecMergeJoin: returning outer fill tuple\n");
495 result = ExecProject(node->js.ps.ps_ProjInfo, &isDone);
497 if (isDone != ExprEndResult)
499 node->js.ps.ps_TupFromTlist =
500 (isDone == ExprMultipleResult);
509 * Generate a fake join tuple with nulls for the outer tuple,
510 * and return it if it passes the non-join quals.
512 static TupleTableSlot *
513 MJFillInner(MergeJoinState *node)
515 ExprContext *econtext = node->js.ps.ps_ExprContext;
516 List *otherqual = node->js.ps.qual;
518 ResetExprContext(econtext);
520 econtext->ecxt_outertuple = node->mj_NullOuterTupleSlot;
521 econtext->ecxt_innertuple = node->mj_InnerTupleSlot;
523 if (ExecQual(otherqual, econtext, false))
526 * qualification succeeded. now form the desired projection tuple and
527 * return the slot containing it.
529 TupleTableSlot *result;
532 MJ_printf("ExecMergeJoin: returning inner fill tuple\n");
534 result = ExecProject(node->js.ps.ps_ProjInfo, &isDone);
536 if (isDone != ExprEndResult)
538 node->js.ps.ps_TupFromTlist =
539 (isDone == ExprMultipleResult);
549 * Check that a qual condition is constant true or constant false.
550 * If it is constant false (or null), set *is_const_false to TRUE.
552 * Constant true would normally be represented by a NIL list, but we allow an
553 * actual bool Const as well. We do expect that the planner will have thrown
554 * away any non-constant terms that have been ANDed with a constant false.
557 check_constant_qual(List *qual, bool *is_const_false)
563 Const *con = (Const *) lfirst(lc);
565 if (!con || !IsA(con, Const))
567 if (con->constisnull || !DatumGetBool(con->constvalue))
568 *is_const_false = true;
574 /* ----------------------------------------------------------------
577 * This function is called through the MJ_dump() macro
578 * when EXEC_MERGEJOINDEBUG is defined
579 * ----------------------------------------------------------------
581 #ifdef EXEC_MERGEJOINDEBUG
584 ExecMergeTupleDumpOuter(MergeJoinState *mergestate)
586 TupleTableSlot *outerSlot = mergestate->mj_OuterTupleSlot;
588 printf("==== outer tuple ====\n");
589 if (TupIsNull(outerSlot))
592 MJ_debugtup(outerSlot);
596 ExecMergeTupleDumpInner(MergeJoinState *mergestate)
598 TupleTableSlot *innerSlot = mergestate->mj_InnerTupleSlot;
600 printf("==== inner tuple ====\n");
601 if (TupIsNull(innerSlot))
604 MJ_debugtup(innerSlot);
608 ExecMergeTupleDumpMarked(MergeJoinState *mergestate)
610 TupleTableSlot *markedSlot = mergestate->mj_MarkedTupleSlot;
612 printf("==== marked tuple ====\n");
613 if (TupIsNull(markedSlot))
616 MJ_debugtup(markedSlot);
620 ExecMergeTupleDump(MergeJoinState *mergestate)
622 printf("******** ExecMergeTupleDump ********\n");
624 ExecMergeTupleDumpOuter(mergestate);
625 ExecMergeTupleDumpInner(mergestate);
626 ExecMergeTupleDumpMarked(mergestate);
628 printf("******** \n");
632 /* ----------------------------------------------------------------
634 * ----------------------------------------------------------------
637 ExecMergeJoin(MergeJoinState *node)
644 PlanState *innerPlan;
645 TupleTableSlot *innerTupleSlot;
646 PlanState *outerPlan;
647 TupleTableSlot *outerTupleSlot;
648 ExprContext *econtext;
653 * get information from node
655 estate = node->js.ps.state;
656 innerPlan = innerPlanState(node);
657 outerPlan = outerPlanState(node);
658 econtext = node->js.ps.ps_ExprContext;
659 joinqual = node->js.joinqual;
660 otherqual = node->js.ps.qual;
661 doFillOuter = node->mj_FillOuter;
662 doFillInner = node->mj_FillInner;
665 * Check to see if we're still projecting out tuples from a previous join
666 * tuple (because there is a function-returning-set in the projection
667 * expressions). If so, try to project another one.
669 if (node->js.ps.ps_TupFromTlist)
671 TupleTableSlot *result;
674 result = ExecProject(node->js.ps.ps_ProjInfo, &isDone);
675 if (isDone == ExprMultipleResult)
677 /* Done with that source tuple... */
678 node->js.ps.ps_TupFromTlist = false;
682 * Reset per-tuple memory context to free any expression evaluation
683 * storage allocated in the previous tuple cycle. Note this can't happen
684 * until we're done projecting out tuples from a join tuple.
686 ResetExprContext(econtext);
689 * ok, everything is setup.. let's go to work
696 * get the current state of the join and do things accordingly.
698 switch (node->mj_JoinState)
701 * EXEC_MJ_INITIALIZE_OUTER means that this is the first time
702 * ExecMergeJoin() has been called and so we have to fetch the
703 * first matchable tuple for both outer and inner subplans. We
704 * do the outer side in INITIALIZE_OUTER state, then advance
705 * to INITIALIZE_INNER state for the inner subplan.
707 case EXEC_MJ_INITIALIZE_OUTER:
708 MJ_printf("ExecMergeJoin: EXEC_MJ_INITIALIZE_OUTER\n");
710 outerTupleSlot = ExecProcNode(outerPlan);
711 node->mj_OuterTupleSlot = outerTupleSlot;
713 /* Compute join values and check for unmatchability */
714 switch (MJEvalOuterValues(node))
716 case MJEVAL_MATCHABLE:
717 /* OK to go get the first inner tuple */
718 node->mj_JoinState = EXEC_MJ_INITIALIZE_INNER;
720 case MJEVAL_NONMATCHABLE:
721 /* Stay in same state to fetch next outer tuple */
725 * Generate a fake join tuple with nulls for the
726 * inner tuple, and return it if it passes the
729 TupleTableSlot *result;
731 result = MJFillOuter(node);
736 case MJEVAL_ENDOFJOIN:
737 /* No more outer tuples */
738 MJ_printf("ExecMergeJoin: nothing in outer subplan\n");
742 * Need to emit right-join tuples for remaining
743 * inner tuples. We set MatchedInner = true to
744 * force the ENDOUTER state to advance inner.
746 node->mj_JoinState = EXEC_MJ_ENDOUTER;
747 node->mj_MatchedInner = true;
750 /* Otherwise we're done. */
755 case EXEC_MJ_INITIALIZE_INNER:
756 MJ_printf("ExecMergeJoin: EXEC_MJ_INITIALIZE_INNER\n");
758 innerTupleSlot = ExecProcNode(innerPlan);
759 node->mj_InnerTupleSlot = innerTupleSlot;
761 /* Compute join values and check for unmatchability */
762 switch (MJEvalInnerValues(node, innerTupleSlot))
764 case MJEVAL_MATCHABLE:
767 * OK, we have the initial tuples. Begin by skipping
768 * non-matching tuples.
770 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
772 case MJEVAL_NONMATCHABLE:
773 /* Mark before advancing, if wanted */
774 if (node->mj_ExtraMarks)
775 ExecMarkPos(innerPlan);
776 /* Stay in same state to fetch next inner tuple */
780 * Generate a fake join tuple with nulls for the
781 * outer tuple, and return it if it passes the
784 TupleTableSlot *result;
786 result = MJFillInner(node);
791 case MJEVAL_ENDOFJOIN:
792 /* No more inner tuples */
793 MJ_printf("ExecMergeJoin: nothing in inner subplan\n");
797 * Need to emit left-join tuples for all outer
798 * tuples, including the one we just fetched. We
799 * set MatchedOuter = false to force the ENDINNER
800 * state to emit first tuple before advancing
803 node->mj_JoinState = EXEC_MJ_ENDINNER;
804 node->mj_MatchedOuter = false;
807 /* Otherwise we're done. */
813 * EXEC_MJ_JOINTUPLES means we have two tuples which satisfied
814 * the merge clause so we join them and then proceed to get
815 * the next inner tuple (EXEC_MJ_NEXTINNER).
817 case EXEC_MJ_JOINTUPLES:
818 MJ_printf("ExecMergeJoin: EXEC_MJ_JOINTUPLES\n");
821 * Set the next state machine state. The right things will
822 * happen whether we return this join tuple or just fall
823 * through to continue the state machine execution.
825 node->mj_JoinState = EXEC_MJ_NEXTINNER;
828 * Check the extra qual conditions to see if we actually want
829 * to return this join tuple. If not, can proceed with merge.
830 * We must distinguish the additional joinquals (which must
831 * pass to consider the tuples "matched" for outer-join logic)
832 * from the otherquals (which must pass before we actually
835 * We don't bother with a ResetExprContext here, on the
836 * assumption that we just did one while checking the merge
837 * qual. One per tuple should be sufficient. We do have to
838 * set up the econtext links to the tuples for ExecQual to
841 outerTupleSlot = node->mj_OuterTupleSlot;
842 econtext->ecxt_outertuple = outerTupleSlot;
843 innerTupleSlot = node->mj_InnerTupleSlot;
844 econtext->ecxt_innertuple = innerTupleSlot;
846 qualResult = (joinqual == NIL ||
847 ExecQual(joinqual, econtext, false));
848 MJ_DEBUG_QUAL(joinqual, qualResult);
852 node->mj_MatchedOuter = true;
853 node->mj_MatchedInner = true;
855 /* In an antijoin, we never return a matched tuple */
856 if (node->js.jointype == JOIN_ANTI)
858 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
863 * In a semijoin, we'll consider returning the first
864 * match, but after that we're done with this outer tuple.
866 if (node->js.jointype == JOIN_SEMI)
867 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
869 qualResult = (otherqual == NIL ||
870 ExecQual(otherqual, econtext, false));
871 MJ_DEBUG_QUAL(otherqual, qualResult);
876 * qualification succeeded. now form the desired
877 * projection tuple and return the slot containing it.
879 TupleTableSlot *result;
882 MJ_printf("ExecMergeJoin: returning tuple\n");
884 result = ExecProject(node->js.ps.ps_ProjInfo,
887 if (isDone != ExprEndResult)
889 node->js.ps.ps_TupFromTlist =
890 (isDone == ExprMultipleResult);
898 * EXEC_MJ_NEXTINNER means advance the inner scan to the next
899 * tuple. If the tuple is not nil, we then proceed to test it
900 * against the join qualification.
902 * Before advancing, we check to see if we must emit an
903 * outer-join fill tuple for this inner tuple.
905 case EXEC_MJ_NEXTINNER:
906 MJ_printf("ExecMergeJoin: EXEC_MJ_NEXTINNER\n");
908 if (doFillInner && !node->mj_MatchedInner)
911 * Generate a fake join tuple with nulls for the outer
912 * tuple, and return it if it passes the non-join quals.
914 TupleTableSlot *result;
916 node->mj_MatchedInner = true; /* do it only once */
918 result = MJFillInner(node);
924 * now we get the next inner tuple, if any. If there's none,
925 * advance to next outer tuple (which may be able to join to
926 * previously marked tuples).
928 * NB: must NOT do "extraMarks" here, since we may need to
929 * return to previously marked tuples.
931 innerTupleSlot = ExecProcNode(innerPlan);
932 node->mj_InnerTupleSlot = innerTupleSlot;
933 MJ_DEBUG_PROC_NODE(innerTupleSlot);
934 node->mj_MatchedInner = false;
936 /* Compute join values and check for unmatchability */
937 switch (MJEvalInnerValues(node, innerTupleSlot))
939 case MJEVAL_MATCHABLE:
942 * Test the new inner tuple to see if it matches
945 * If they do match, then we join them and move on to
946 * the next inner tuple (EXEC_MJ_JOINTUPLES).
948 * If they do not match then advance to next outer
951 compareResult = MJCompare(node);
952 MJ_DEBUG_COMPARE(compareResult);
954 if (compareResult == 0)
955 node->mj_JoinState = EXEC_MJ_JOINTUPLES;
958 Assert(compareResult < 0);
959 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
962 case MJEVAL_NONMATCHABLE:
965 * It contains a NULL and hence can't match any outer
966 * tuple, so we can skip the comparison and assume the
967 * new tuple is greater than current outer.
969 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
971 case MJEVAL_ENDOFJOIN:
974 * No more inner tuples. However, this might be only
975 * effective and not physical end of inner plan, so
976 * force mj_InnerTupleSlot to null to make sure we
977 * don't fetch more inner tuples. (We need this hack
978 * because we are not transiting to a state where the
979 * inner plan is assumed to be exhausted.)
981 node->mj_InnerTupleSlot = NULL;
982 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
987 /*-------------------------------------------
988 * EXEC_MJ_NEXTOUTER means
991 * outer tuple - 5 5 - marked tuple
996 * we know we just bumped into the
997 * first inner tuple > current outer tuple (or possibly
998 * the end of the inner stream)
999 * so get a new outer tuple and then
1000 * proceed to test it against the marked tuple
1001 * (EXEC_MJ_TESTOUTER)
1003 * Before advancing, we check to see if we must emit an
1004 * outer-join fill tuple for this outer tuple.
1005 *------------------------------------------------
1007 case EXEC_MJ_NEXTOUTER:
1008 MJ_printf("ExecMergeJoin: EXEC_MJ_NEXTOUTER\n");
1010 if (doFillOuter && !node->mj_MatchedOuter)
1013 * Generate a fake join tuple with nulls for the inner
1014 * tuple, and return it if it passes the non-join quals.
1016 TupleTableSlot *result;
1018 node->mj_MatchedOuter = true; /* do it only once */
1020 result = MJFillOuter(node);
1026 * now we get the next outer tuple, if any
1028 outerTupleSlot = ExecProcNode(outerPlan);
1029 node->mj_OuterTupleSlot = outerTupleSlot;
1030 MJ_DEBUG_PROC_NODE(outerTupleSlot);
1031 node->mj_MatchedOuter = false;
1033 /* Compute join values and check for unmatchability */
1034 switch (MJEvalOuterValues(node))
1036 case MJEVAL_MATCHABLE:
1037 /* Go test the new tuple against the marked tuple */
1038 node->mj_JoinState = EXEC_MJ_TESTOUTER;
1040 case MJEVAL_NONMATCHABLE:
1041 /* Can't match, so fetch next outer tuple */
1042 node->mj_JoinState = EXEC_MJ_NEXTOUTER;
1044 case MJEVAL_ENDOFJOIN:
1045 /* No more outer tuples */
1046 MJ_printf("ExecMergeJoin: end of outer subplan\n");
1047 innerTupleSlot = node->mj_InnerTupleSlot;
1048 if (doFillInner && !TupIsNull(innerTupleSlot))
1051 * Need to emit right-join tuples for remaining
1054 node->mj_JoinState = EXEC_MJ_ENDOUTER;
1057 /* Otherwise we're done. */
1062 /*--------------------------------------------------------
1063 * EXEC_MJ_TESTOUTER If the new outer tuple and the marked
1064 * tuple satisfy the merge clause then we know we have
1065 * duplicates in the outer scan so we have to restore the
1066 * inner scan to the marked tuple and proceed to join the
1067 * new outer tuple with the inner tuples.
1069 * This is the case when
1071 * 4 5 - marked tuple
1073 * new outer tuple - 5 5
1077 * new outer tuple == marked tuple
1079 * If the outer tuple fails the test, then we are done
1080 * with the marked tuples, and we have to look for a
1081 * match to the current inner tuple. So we will
1082 * proceed to skip outer tuples until outer >= inner
1083 * (EXEC_MJ_SKIP_TEST).
1085 * This is the case when
1088 * 5 5 - marked tuple
1090 * new outer tuple - 6 8 - inner tuple
1093 * new outer tuple > marked tuple
1095 *---------------------------------------------------------
1097 case EXEC_MJ_TESTOUTER:
1098 MJ_printf("ExecMergeJoin: EXEC_MJ_TESTOUTER\n");
1101 * Here we must compare the outer tuple with the marked inner
1102 * tuple. (We can ignore the result of MJEvalInnerValues,
1103 * since the marked inner tuple is certainly matchable.)
1105 innerTupleSlot = node->mj_MarkedTupleSlot;
1106 (void) MJEvalInnerValues(node, innerTupleSlot);
1108 compareResult = MJCompare(node);
1109 MJ_DEBUG_COMPARE(compareResult);
1111 if (compareResult == 0)
1114 * the merge clause matched so now we restore the inner
1115 * scan position to the first mark, and go join that tuple
1116 * (and any following ones) to the new outer.
1118 * NOTE: we do not need to worry about the MatchedInner
1119 * state for the rescanned inner tuples. We know all of
1120 * them will match this new outer tuple and therefore
1121 * won't be emitted as fill tuples. This works *only*
1122 * because we require the extra joinquals to be constant
1123 * when doing a right or full join --- otherwise some of
1124 * the rescanned tuples might fail the extra joinquals.
1125 * This obviously won't happen for a constant-true extra
1126 * joinqual, while the constant-false case is handled by
1127 * forcing the merge clause to never match, so we never
1130 ExecRestrPos(innerPlan);
1133 * ExecRestrPos probably should give us back a new Slot,
1134 * but since it doesn't, use the marked slot. (The
1135 * previously returned mj_InnerTupleSlot cannot be assumed
1136 * to hold the required tuple.)
1138 node->mj_InnerTupleSlot = innerTupleSlot;
1139 /* we need not do MJEvalInnerValues again */
1141 node->mj_JoinState = EXEC_MJ_JOINTUPLES;
1146 * if the new outer tuple didn't match the marked inner
1147 * tuple then we have a case like:
1150 * 4 4 - marked tuple
1155 * which means that all subsequent outer tuples will be
1156 * larger than our marked inner tuples. So we need not
1157 * revisit any of the marked tuples but can proceed to
1158 * look for a match to the current inner. If there's
1159 * no more inners, no more matches are possible.
1162 Assert(compareResult > 0);
1163 innerTupleSlot = node->mj_InnerTupleSlot;
1165 /* reload comparison data for current inner */
1166 switch (MJEvalInnerValues(node, innerTupleSlot))
1168 case MJEVAL_MATCHABLE:
1169 /* proceed to compare it to the current outer */
1170 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
1172 case MJEVAL_NONMATCHABLE:
1175 * current inner can't possibly match any outer;
1176 * better to advance the inner scan than the
1179 node->mj_JoinState = EXEC_MJ_SKIPINNER_ADVANCE;
1181 case MJEVAL_ENDOFJOIN:
1182 /* No more inner tuples */
1186 * Need to emit left-join tuples for remaining
1189 node->mj_JoinState = EXEC_MJ_ENDINNER;
1192 /* Otherwise we're done. */
1198 /*----------------------------------------------------------
1199 * EXEC_MJ_SKIP means compare tuples and if they do not
1200 * match, skip whichever is lesser.
1207 * outer tuple - 6 8 - inner tuple
1211 * we have to advance the outer scan
1212 * until we find the outer 8.
1214 * On the other hand:
1219 * outer tuple - 12 8 - inner tuple
1223 * we have to advance the inner scan
1224 * until we find the inner 12.
1225 *----------------------------------------------------------
1227 case EXEC_MJ_SKIP_TEST:
1228 MJ_printf("ExecMergeJoin: EXEC_MJ_SKIP_TEST\n");
1231 * before we advance, make sure the current tuples do not
1232 * satisfy the mergeclauses. If they do, then we update the
1233 * marked tuple position and go join them.
1235 compareResult = MJCompare(node);
1236 MJ_DEBUG_COMPARE(compareResult);
1238 if (compareResult == 0)
1240 ExecMarkPos(innerPlan);
1242 MarkInnerTuple(node->mj_InnerTupleSlot, node);
1244 node->mj_JoinState = EXEC_MJ_JOINTUPLES;
1246 else if (compareResult < 0)
1247 node->mj_JoinState = EXEC_MJ_SKIPOUTER_ADVANCE;
1249 /* compareResult > 0 */
1250 node->mj_JoinState = EXEC_MJ_SKIPINNER_ADVANCE;
1254 * SKIPOUTER_ADVANCE: advance over an outer tuple that is
1255 * known not to join to any inner tuple.
1257 * Before advancing, we check to see if we must emit an
1258 * outer-join fill tuple for this outer tuple.
1260 case EXEC_MJ_SKIPOUTER_ADVANCE:
1261 MJ_printf("ExecMergeJoin: EXEC_MJ_SKIPOUTER_ADVANCE\n");
1263 if (doFillOuter && !node->mj_MatchedOuter)
1266 * Generate a fake join tuple with nulls for the inner
1267 * tuple, and return it if it passes the non-join quals.
1269 TupleTableSlot *result;
1271 node->mj_MatchedOuter = true; /* do it only once */
1273 result = MJFillOuter(node);
1279 * now we get the next outer tuple, if any
1281 outerTupleSlot = ExecProcNode(outerPlan);
1282 node->mj_OuterTupleSlot = outerTupleSlot;
1283 MJ_DEBUG_PROC_NODE(outerTupleSlot);
1284 node->mj_MatchedOuter = false;
1286 /* Compute join values and check for unmatchability */
1287 switch (MJEvalOuterValues(node))
1289 case MJEVAL_MATCHABLE:
1290 /* Go test the new tuple against the current inner */
1291 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
1293 case MJEVAL_NONMATCHABLE:
1294 /* Can't match, so fetch next outer tuple */
1295 node->mj_JoinState = EXEC_MJ_SKIPOUTER_ADVANCE;
1297 case MJEVAL_ENDOFJOIN:
1298 /* No more outer tuples */
1299 MJ_printf("ExecMergeJoin: end of outer subplan\n");
1300 innerTupleSlot = node->mj_InnerTupleSlot;
1301 if (doFillInner && !TupIsNull(innerTupleSlot))
1304 * Need to emit right-join tuples for remaining
1307 node->mj_JoinState = EXEC_MJ_ENDOUTER;
1310 /* Otherwise we're done. */
1316 * SKIPINNER_ADVANCE: advance over an inner tuple that is
1317 * known not to join to any outer tuple.
1319 * Before advancing, we check to see if we must emit an
1320 * outer-join fill tuple for this inner tuple.
1322 case EXEC_MJ_SKIPINNER_ADVANCE:
1323 MJ_printf("ExecMergeJoin: EXEC_MJ_SKIPINNER_ADVANCE\n");
1325 if (doFillInner && !node->mj_MatchedInner)
1328 * Generate a fake join tuple with nulls for the outer
1329 * tuple, and return it if it passes the non-join quals.
1331 TupleTableSlot *result;
1333 node->mj_MatchedInner = true; /* do it only once */
1335 result = MJFillInner(node);
1340 /* Mark before advancing, if wanted */
1341 if (node->mj_ExtraMarks)
1342 ExecMarkPos(innerPlan);
1345 * now we get the next inner tuple, if any
1347 innerTupleSlot = ExecProcNode(innerPlan);
1348 node->mj_InnerTupleSlot = innerTupleSlot;
1349 MJ_DEBUG_PROC_NODE(innerTupleSlot);
1350 node->mj_MatchedInner = false;
1352 /* Compute join values and check for unmatchability */
1353 switch (MJEvalInnerValues(node, innerTupleSlot))
1355 case MJEVAL_MATCHABLE:
1356 /* proceed to compare it to the current outer */
1357 node->mj_JoinState = EXEC_MJ_SKIP_TEST;
1359 case MJEVAL_NONMATCHABLE:
1362 * current inner can't possibly match any outer;
1363 * better to advance the inner scan than the outer.
1365 node->mj_JoinState = EXEC_MJ_SKIPINNER_ADVANCE;
1367 case MJEVAL_ENDOFJOIN:
1368 /* No more inner tuples */
1369 MJ_printf("ExecMergeJoin: end of inner subplan\n");
1370 outerTupleSlot = node->mj_OuterTupleSlot;
1371 if (doFillOuter && !TupIsNull(outerTupleSlot))
1374 * Need to emit left-join tuples for remaining
1377 node->mj_JoinState = EXEC_MJ_ENDINNER;
1380 /* Otherwise we're done. */
1386 * EXEC_MJ_ENDOUTER means we have run out of outer tuples, but
1387 * are doing a right/full join and therefore must null-fill
1388 * any remaing unmatched inner tuples.
1390 case EXEC_MJ_ENDOUTER:
1391 MJ_printf("ExecMergeJoin: EXEC_MJ_ENDOUTER\n");
1393 Assert(doFillInner);
1395 if (!node->mj_MatchedInner)
1398 * Generate a fake join tuple with nulls for the outer
1399 * tuple, and return it if it passes the non-join quals.
1401 TupleTableSlot *result;
1403 node->mj_MatchedInner = true; /* do it only once */
1405 result = MJFillInner(node);
1410 /* Mark before advancing, if wanted */
1411 if (node->mj_ExtraMarks)
1412 ExecMarkPos(innerPlan);
1415 * now we get the next inner tuple, if any
1417 innerTupleSlot = ExecProcNode(innerPlan);
1418 node->mj_InnerTupleSlot = innerTupleSlot;
1419 MJ_DEBUG_PROC_NODE(innerTupleSlot);
1420 node->mj_MatchedInner = false;
1422 if (TupIsNull(innerTupleSlot))
1424 MJ_printf("ExecMergeJoin: end of inner subplan\n");
1428 /* Else remain in ENDOUTER state and process next tuple. */
1432 * EXEC_MJ_ENDINNER means we have run out of inner tuples, but
1433 * are doing a left/full join and therefore must null- fill
1434 * any remaing unmatched outer tuples.
1436 case EXEC_MJ_ENDINNER:
1437 MJ_printf("ExecMergeJoin: EXEC_MJ_ENDINNER\n");
1439 Assert(doFillOuter);
1441 if (!node->mj_MatchedOuter)
1444 * Generate a fake join tuple with nulls for the inner
1445 * tuple, and return it if it passes the non-join quals.
1447 TupleTableSlot *result;
1449 node->mj_MatchedOuter = true; /* do it only once */
1451 result = MJFillOuter(node);
1457 * now we get the next outer tuple, if any
1459 outerTupleSlot = ExecProcNode(outerPlan);
1460 node->mj_OuterTupleSlot = outerTupleSlot;
1461 MJ_DEBUG_PROC_NODE(outerTupleSlot);
1462 node->mj_MatchedOuter = false;
1464 if (TupIsNull(outerTupleSlot))
1466 MJ_printf("ExecMergeJoin: end of outer subplan\n");
1470 /* Else remain in ENDINNER state and process next tuple. */
1474 * broken state value?
1477 elog(ERROR, "unrecognized mergejoin state: %d",
1478 (int) node->mj_JoinState);
1483 /* ----------------------------------------------------------------
1485 * ----------------------------------------------------------------
1488 ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags)
1490 MergeJoinState *mergestate;
1492 /* check for unsupported flags */
1493 Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
1495 MJ1_printf("ExecInitMergeJoin: %s\n",
1496 "initializing node");
1499 * create state structure
1501 mergestate = makeNode(MergeJoinState);
1502 mergestate->js.ps.plan = (Plan *) node;
1503 mergestate->js.ps.state = estate;
1506 * Miscellaneous initialization
1508 * create expression context for node
1510 ExecAssignExprContext(estate, &mergestate->js.ps);
1513 * we need two additional econtexts in which we can compute the join
1514 * expressions from the left and right input tuples. The node's regular
1515 * econtext won't do because it gets reset too often.
1517 mergestate->mj_OuterEContext = CreateExprContext(estate);
1518 mergestate->mj_InnerEContext = CreateExprContext(estate);
1521 * initialize child expressions
1523 mergestate->js.ps.targetlist = (List *)
1524 ExecInitExpr((Expr *) node->join.plan.targetlist,
1525 (PlanState *) mergestate);
1526 mergestate->js.ps.qual = (List *)
1527 ExecInitExpr((Expr *) node->join.plan.qual,
1528 (PlanState *) mergestate);
1529 mergestate->js.jointype = node->join.jointype;
1530 mergestate->js.joinqual = (List *)
1531 ExecInitExpr((Expr *) node->join.joinqual,
1532 (PlanState *) mergestate);
1533 mergestate->mj_ConstFalseJoin = false;
1534 /* mergeclauses are handled below */
1537 * initialize child nodes
1539 * inner child must support MARK/RESTORE.
1541 outerPlanState(mergestate) = ExecInitNode(outerPlan(node), estate, eflags);
1542 innerPlanState(mergestate) = ExecInitNode(innerPlan(node), estate,
1543 eflags | EXEC_FLAG_MARK);
1546 * For certain types of inner child nodes, it is advantageous to issue
1547 * MARK every time we advance past an inner tuple we will never return to.
1548 * For other types, MARK on a tuple we cannot return to is a waste of
1549 * cycles. Detect which case applies and set mj_ExtraMarks if we want to
1550 * issue "unnecessary" MARK calls.
1552 * Currently, only Material wants the extra MARKs, and it will be helpful
1553 * only if eflags doesn't specify REWIND.
1555 if (IsA(innerPlan(node), Material) &&
1556 (eflags & EXEC_FLAG_REWIND) == 0)
1557 mergestate->mj_ExtraMarks = true;
1559 mergestate->mj_ExtraMarks = false;
1562 * tuple table initialization
1564 ExecInitResultTupleSlot(estate, &mergestate->js.ps);
1566 mergestate->mj_MarkedTupleSlot = ExecInitExtraTupleSlot(estate);
1567 ExecSetSlotDescriptor(mergestate->mj_MarkedTupleSlot,
1568 ExecGetResultType(innerPlanState(mergestate)));
1570 switch (node->join.jointype)
1574 mergestate->mj_FillOuter = false;
1575 mergestate->mj_FillInner = false;
1579 mergestate->mj_FillOuter = true;
1580 mergestate->mj_FillInner = false;
1581 mergestate->mj_NullInnerTupleSlot =
1582 ExecInitNullTupleSlot(estate,
1583 ExecGetResultType(innerPlanState(mergestate)));
1586 mergestate->mj_FillOuter = false;
1587 mergestate->mj_FillInner = true;
1588 mergestate->mj_NullOuterTupleSlot =
1589 ExecInitNullTupleSlot(estate,
1590 ExecGetResultType(outerPlanState(mergestate)));
1593 * Can't handle right or full join with non-constant extra
1594 * joinclauses. This should have been caught by planner.
1596 if (!check_constant_qual(node->join.joinqual,
1597 &mergestate->mj_ConstFalseJoin))
1599 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1600 errmsg("RIGHT JOIN is only supported with merge-joinable join conditions")));
1603 mergestate->mj_FillOuter = true;
1604 mergestate->mj_FillInner = true;
1605 mergestate->mj_NullOuterTupleSlot =
1606 ExecInitNullTupleSlot(estate,
1607 ExecGetResultType(outerPlanState(mergestate)));
1608 mergestate->mj_NullInnerTupleSlot =
1609 ExecInitNullTupleSlot(estate,
1610 ExecGetResultType(innerPlanState(mergestate)));
1613 * Can't handle right or full join with non-constant extra
1614 * joinclauses. This should have been caught by planner.
1616 if (!check_constant_qual(node->join.joinqual,
1617 &mergestate->mj_ConstFalseJoin))
1619 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1620 errmsg("FULL JOIN is only supported with merge-joinable join conditions")));
1623 elog(ERROR, "unrecognized join type: %d",
1624 (int) node->join.jointype);
1628 * initialize tuple type and projection info
1630 ExecAssignResultTypeFromTL(&mergestate->js.ps);
1631 ExecAssignProjectionInfo(&mergestate->js.ps, NULL);
1634 * preprocess the merge clauses
1636 mergestate->mj_NumClauses = list_length(node->mergeclauses);
1637 mergestate->mj_Clauses = MJExamineQuals(node->mergeclauses,
1638 node->mergeFamilies,
1639 node->mergeStrategies,
1640 node->mergeNullsFirst,
1641 (PlanState *) mergestate);
1644 * initialize join state
1646 mergestate->mj_JoinState = EXEC_MJ_INITIALIZE_OUTER;
1647 mergestate->js.ps.ps_TupFromTlist = false;
1648 mergestate->mj_MatchedOuter = false;
1649 mergestate->mj_MatchedInner = false;
1650 mergestate->mj_OuterTupleSlot = NULL;
1651 mergestate->mj_InnerTupleSlot = NULL;
1654 * initialization successful
1656 MJ1_printf("ExecInitMergeJoin: %s\n",
1657 "node initialized");
1662 /* ----------------------------------------------------------------
1666 * frees storage allocated through C routines.
1667 * ----------------------------------------------------------------
1670 ExecEndMergeJoin(MergeJoinState *node)
1672 MJ1_printf("ExecEndMergeJoin: %s\n",
1673 "ending node processing");
1676 * Free the exprcontext
1678 ExecFreeExprContext(&node->js.ps);
1681 * clean out the tuple table
1683 ExecClearTuple(node->js.ps.ps_ResultTupleSlot);
1684 ExecClearTuple(node->mj_MarkedTupleSlot);
1687 * shut down the subplans
1689 ExecEndNode(innerPlanState(node));
1690 ExecEndNode(outerPlanState(node));
1692 MJ1_printf("ExecEndMergeJoin: %s\n",
1693 "node processing ended");
1697 ExecReScanMergeJoin(MergeJoinState *node)
1699 ExecClearTuple(node->mj_MarkedTupleSlot);
1701 node->mj_JoinState = EXEC_MJ_INITIALIZE_OUTER;
1702 node->js.ps.ps_TupFromTlist = false;
1703 node->mj_MatchedOuter = false;
1704 node->mj_MatchedInner = false;
1705 node->mj_OuterTupleSlot = NULL;
1706 node->mj_InnerTupleSlot = NULL;
1709 * if chgParam of subnodes is not null then plans will be re-scanned by
1710 * first ExecProcNode.
1712 if (node->js.ps.lefttree->chgParam == NULL)
1713 ExecReScan(node->js.ps.lefttree);
1714 if (node->js.ps.righttree->chgParam == NULL)
1715 ExecReScan(node->js.ps.righttree);