1/*-------------------------------------------------------------------------
4 * routines supporting merge joins
6 * Portions Copyright (c) 1996-2025, 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
103 * States of the ExecMergeJoin state machine
105 #define EXEC_MJ_INITIALIZE_OUTER 1
106 #define EXEC_MJ_INITIALIZE_INNER 2
107 #define EXEC_MJ_JOINTUPLES 3
108 #define EXEC_MJ_NEXTOUTER 4
109 #define EXEC_MJ_TESTOUTER 5
110 #define EXEC_MJ_NEXTINNER 6
111 #define EXEC_MJ_SKIP_TEST 7
112 #define EXEC_MJ_SKIPOUTER_ADVANCE 8
113 #define EXEC_MJ_SKIPINNER_ADVANCE 9
114 #define EXEC_MJ_ENDOUTER 10
115 #define EXEC_MJ_ENDINNER 11
118 * Runtime data for each mergejoin clause
122 /* Executable expression trees */
127 * If we have a current left or right input tuple, the values of the
128 * expressions are loaded into these fields:
136 * Everything we need to know to compare the left and right values is
142/* Result type for MJEvalOuterValues and MJEvalInnerValues */
151 #define MarkInnerTuple(innerTupleSlot, mergestate) \
152 ExecCopySlot((mergestate)->mj_MarkedTupleSlot, (innerTupleSlot))
158 * This deconstructs the list of mergejoinable expressions, which is given
159 * to us by the planner in the form of a list of "leftexpr = rightexpr"
160 * expression trees in the order matching the sort columns of the inputs.
161 * We build an array of MergeJoinClause structs containing the information
162 * we will need at runtime. Each struct essentially tells us how to compare
163 * the two expressions from the original clause.
165 * In addition to the expressions themselves, the planner passes the btree
166 * opfamily OID, collation OID, btree strategy number (BTLessStrategyNumber or
167 * BTGreaterStrategyNumber), and nulls-first flag that identify the intended
168 * sort ordering for each merge key. The mergejoinable operator is an
169 * equality operator in the opfamily, and the two inputs are guaranteed to be
170 * ordered in either increasing or decreasing (respectively) order according
171 * to the opfamily and collation, with nulls at the indicated end of the range.
172 * This allows us to obtain the needed comparison function from the opfamily.
177 Oid *mergecollations,
178 bool *mergereversals,
179 bool *mergenullsfirst,
190 foreach(cl, mergeclauses)
194 Oid opfamily = mergefamilies[iClause];
195 Oid collation = mergecollations[iClause];
196 bool reversed = mergereversals[iClause];
197 bool nulls_first = mergenullsfirst[iClause];
204 elog(
ERROR,
"mergejoin clause is not an OpExpr");
207 * Prepare the input expressions for execution.
212 /* Set up sort support data */
218 /* Extract the operator's declared left/right datatypes */
224 elog(
ERROR,
"cannot merge using non-equality operator %u",
228 * sortsupport routine must know if abbreviation optimization is
229 * applicable in principle. It is never applicable for merge joins
230 * because there is no convenient opportunity to convert to
231 * alternative representation.
235 /* And get the matching support or comparison function */
243 /* The sort support function can provide a comparator */
248 /* support not available, get comparison func */
253 if (!
OidIsValid(sortfunc))
/* should not happen */
254 elog(
ERROR,
"missing support function %d(%u,%u) in opfamily %u",
256 /* We'll use a shim to call the old-style btree comparator */
269 * Compute the values of the mergejoined expressions for the current
270 * outer tuple. We also detect whether it's impossible for the current
271 * outer tuple to match anything --- this is true if it yields a NULL
272 * input, since we assume mergejoin operators are strict. If the NULL
273 * is in the first join column, and that column sorts nulls last, then
274 * we can further conclude that no following tuple can match anything
275 * either, since they must all have nulls in the first column. However,
276 * that case is only interesting if we're not in FillOuter mode, else
277 * we have to visit all the tuples anyway.
279 * For the convenience of callers, we also make this routine responsible
280 * for testing for end-of-input (null outer tuple), and returning
281 * MJEVAL_ENDOFJOIN when that's seen. This allows the same code to be used
282 * for both real end-of-input and the effective end-of-input represented by
283 * a first-column NULL.
285 * We evaluate the values in OuterEContext, which can be reset each
286 * time we move to a new tuple.
296 /* Check for end of outer subplan */
314 /* match is impossible; can we end the join early? */
331 * Same as above, but for the inner tuple. Here, we have to be prepared
332 * to load data from either the true current inner, or the marked inner,
333 * so caller must tell us which slot to load from.
343 /* Check for end of inner subplan */
361 /* match is impossible; can we end the join early? */
378 * Compare the mergejoinable values of the current two input tuples
379 * and return 0 if they are equal (ie, the mergejoin equalities all
380 * succeed), >0 if outer > inner, <0 if outer < inner.
382 * MJEvalOuterValues and MJEvalInnerValues must already have been called
383 * for the current outer and inner tuples, respectively.
389 bool nulleqnull =
false;
395 * Call the comparison functions in short-lived context, in case they leak
407 * Special case for NULL-vs-NULL, else use standard comparison.
411 nulleqnull =
true;
/* NULL "=" NULL */
424 * If we had any NULL-vs-NULL inputs, we do not want to report that the
425 * tuples are equal. Instead, if result is still 0, change it to +1. This
426 * will result in advancing the inner side of the join.
428 * Likewise, if there was a constant-false joinqual, do not report
429 * equality. We have to check this as part of the mergequals, else the
430 * rescan logic will do the wrong thing.
443 * Generate a fake join tuple with nulls for the inner tuple,
444 * and return it if it passes the non-join quals.
460 * qualification succeeded. now form the desired projection tuple and
461 * return the slot containing it.
463 MJ_printf(
"ExecMergeJoin: returning outer fill tuple\n");
474 * Generate a fake join tuple with nulls for the outer tuple,
475 * and return it if it passes the non-join quals.
491 * qualification succeeded. now form the desired projection tuple and
492 * return the slot containing it.
494 MJ_printf(
"ExecMergeJoin: returning inner fill tuple\n");
506 * Check that a qual condition is constant true or constant false.
507 * If it is constant false (or null), set *is_const_false to true.
509 * Constant true would normally be represented by a NIL list, but we allow an
510 * actual bool Const as well. We do expect that the planner will have thrown
511 * away any non-constant terms that have been ANDed with a constant false.
525 *is_const_false =
true;
531/* ----------------------------------------------------------------
534 * This function is called through the MJ_dump() macro
535 * when EXEC_MERGEJOINDEBUG is defined
536 * ----------------------------------------------------------------
538#ifdef EXEC_MERGEJOINDEBUG
545 printf(
"==== outer tuple ====\n");
557 printf(
"==== inner tuple ====\n");
569 printf(
"==== marked tuple ====\n");
579 printf(
"******** ExecMergeTupleDump ********\n");
581 ExecMergeTupleDumpOuter(mergestate);
582 ExecMergeTupleDumpInner(mergestate);
583 ExecMergeTupleDumpMarked(mergestate);
589/* ----------------------------------------------------------------
591 * ----------------------------------------------------------------
612 * get information from node
623 * Reset per-tuple memory context to free any expression evaluation
624 * storage allocated in the previous tuple cycle.
629 * ok, everything is setup.. let's go to work
636 * get the current state of the join and do things accordingly.
641 * EXEC_MJ_INITIALIZE_OUTER means that this is the first time
642 * ExecMergeJoin() has been called and so we have to fetch the
643 * first matchable tuple for both outer and inner subplans. We
644 * do the outer side in INITIALIZE_OUTER state, then advance
645 * to INITIALIZE_INNER state for the inner subplan.
648 MJ_printf(
"ExecMergeJoin: EXEC_MJ_INITIALIZE_OUTER\n");
653 /* Compute join values and check for unmatchability */
657 /* OK to go get the first inner tuple */
661 /* Stay in same state to fetch next outer tuple */
665 * Generate a fake join tuple with nulls for the
666 * inner tuple, and return it if it passes the
677 /* No more outer tuples */
678 MJ_printf(
"ExecMergeJoin: nothing in outer subplan\n");
682 * Need to emit right-join tuples for remaining
683 * inner tuples. We set MatchedInner = true to
684 * force the ENDOUTER state to advance inner.
690 /* Otherwise we're done. */
696 MJ_printf(
"ExecMergeJoin: EXEC_MJ_INITIALIZE_INNER\n");
701 /* Compute join values and check for unmatchability */
707 * OK, we have the initial tuples. Begin by skipping
708 * non-matching tuples.
713 /* Mark before advancing, if wanted */
716 /* Stay in same state to fetch next inner tuple */
720 * Generate a fake join tuple with nulls for the
721 * outer tuple, and return it if it passes the
732 /* No more inner tuples */
733 MJ_printf(
"ExecMergeJoin: nothing in inner subplan\n");
737 * Need to emit left-join tuples for all outer
738 * tuples, including the one we just fetched. We
739 * set MatchedOuter = false to force the ENDINNER
740 * state to emit first tuple before advancing
747 /* Otherwise we're done. */
753 * EXEC_MJ_JOINTUPLES means we have two tuples which satisfied
754 * the merge clause so we join them and then proceed to get
755 * the next inner tuple (EXEC_MJ_NEXTINNER).
758 MJ_printf(
"ExecMergeJoin: EXEC_MJ_JOINTUPLES\n");
761 * Set the next state machine state. The right things will
762 * happen whether we return this join tuple or just fall
763 * through to continue the state machine execution.
768 * Check the extra qual conditions to see if we actually want
769 * to return this join tuple. If not, can proceed with merge.
770 * We must distinguish the additional joinquals (which must
771 * pass to consider the tuples "matched" for outer-join logic)
772 * from the otherquals (which must pass before we actually
775 * We don't bother with a ResetExprContext here, on the
776 * assumption that we just did one while checking the merge
777 * qual. One per tuple should be sufficient. We do have to
778 * set up the econtext links to the tuples for ExecQual to
786 qualResult = (joinqual == NULL ||
795 /* In an antijoin, we never return a matched tuple */
803 * If we only need to consider the first matching inner
804 * tuple, then advance to next outer tuple after we've
805 * processed this one.
811 * In a right-antijoin, we never return a matched tuple.
812 * If it's not an inner_unique join, we need to stay on
813 * the current outer tuple to continue scanning the inner
819 qualResult = (otherqual == NULL ||
826 * qualification succeeded. now form the desired
827 * projection tuple and return the slot containing it.
829 MJ_printf(
"ExecMergeJoin: returning tuple\n");
841 * EXEC_MJ_NEXTINNER means advance the inner scan to the next
842 * tuple. If the tuple is not nil, we then proceed to test it
843 * against the join qualification.
845 * Before advancing, we check to see if we must emit an
846 * outer-join fill tuple for this inner tuple.
849 MJ_printf(
"ExecMergeJoin: EXEC_MJ_NEXTINNER\n");
854 * Generate a fake join tuple with nulls for the outer
855 * tuple, and return it if it passes the non-join quals.
867 * now we get the next inner tuple, if any. If there's none,
868 * advance to next outer tuple (which may be able to join to
869 * previously marked tuples).
871 * NB: must NOT do "extraMarks" here, since we may need to
872 * return to previously marked tuples.
879 /* Compute join values and check for unmatchability */
885 * Test the new inner tuple to see if it matches
888 * If they do match, then we join them and move on to
889 * the next inner tuple (EXEC_MJ_JOINTUPLES).
891 * If they do not match then advance to next outer
897 if (compareResult == 0)
899 else if (compareResult < 0)
901 else /* compareResult > 0 should not happen */
902 elog(
ERROR,
"mergejoin input data is out of order");
907 * It contains a NULL and hence can't match any outer
908 * tuple, so we can skip the comparison and assume the
909 * new tuple is greater than current outer.
916 * No more inner tuples. However, this might be only
917 * effective and not physical end of inner plan, so
918 * force mj_InnerTupleSlot to null to make sure we
919 * don't fetch more inner tuples. (We need this hack
920 * because we are not transiting to a state where the
921 * inner plan is assumed to be exhausted.)
929 /*-------------------------------------------
930 * EXEC_MJ_NEXTOUTER means
933 * outer tuple - 5 5 - marked tuple
938 * we know we just bumped into the
939 * first inner tuple > current outer tuple (or possibly
940 * the end of the inner stream)
941 * so get a new outer tuple and then
942 * proceed to test it against the marked tuple
943 * (EXEC_MJ_TESTOUTER)
945 * Before advancing, we check to see if we must emit an
946 * outer-join fill tuple for this outer tuple.
947 *------------------------------------------------
950 MJ_printf(
"ExecMergeJoin: EXEC_MJ_NEXTOUTER\n");
955 * Generate a fake join tuple with nulls for the inner
956 * tuple, and return it if it passes the non-join quals.
968 * now we get the next outer tuple, if any
975 /* Compute join values and check for unmatchability */
979 /* Go test the new tuple against the marked tuple */
983 /* Can't match, so fetch next outer tuple */
987 /* No more outer tuples */
988 MJ_printf(
"ExecMergeJoin: end of outer subplan\n");
990 if (doFillInner && !
TupIsNull(innerTupleSlot))
993 * Need to emit right-join tuples for remaining
999 /* Otherwise we're done. */
1004 /*--------------------------------------------------------
1005 * EXEC_MJ_TESTOUTER If the new outer tuple and the marked
1006 * tuple satisfy the merge clause then we know we have
1007 * duplicates in the outer scan so we have to restore the
1008 * inner scan to the marked tuple and proceed to join the
1009 * new outer tuple with the inner tuples.
1011 * This is the case when
1013 * 4 5 - marked tuple
1015 * new outer tuple - 5 5
1019 * new outer tuple == marked tuple
1021 * If the outer tuple fails the test, then we are done
1022 * with the marked tuples, and we have to look for a
1023 * match to the current inner tuple. So we will
1024 * proceed to skip outer tuples until outer >= inner
1025 * (EXEC_MJ_SKIP_TEST).
1027 * This is the case when
1030 * 5 5 - marked tuple
1032 * new outer tuple - 6 8 - inner tuple
1035 * new outer tuple > marked tuple
1037 *---------------------------------------------------------
1040 MJ_printf(
"ExecMergeJoin: EXEC_MJ_TESTOUTER\n");
1043 * Here we must compare the outer tuple with the marked inner
1044 * tuple. (We can ignore the result of MJEvalInnerValues,
1045 * since the marked inner tuple is certainly matchable.)
1053 if (compareResult == 0)
1056 * the merge clause matched so now we restore the inner
1057 * scan position to the first mark, and go join that tuple
1058 * (and any following ones) to the new outer.
1060 * If we were able to determine mark and restore are not
1061 * needed, then we don't have to back up; the current
1062 * inner is already the first possible match.
1064 * NOTE: we do not need to worry about the MatchedInner
1065 * state for the rescanned inner tuples. We know all of
1066 * them will match this new outer tuple and therefore
1067 * won't be emitted as fill tuples. This works *only*
1068 * because we require the extra joinquals to be constant
1069 * when doing a right, right-anti or full join ---
1070 * otherwise some of the rescanned tuples might fail the
1071 * extra joinquals. This obviously won't happen for a
1072 * constant-true extra joinqual, while the constant-false
1073 * case is handled by forcing the merge clause to never
1074 * match, so we never get here.
1081 * ExecRestrPos probably should give us back a new
1082 * Slot, but since it doesn't, use the marked slot.
1083 * (The previously returned mj_InnerTupleSlot cannot
1084 * be assumed to hold the required tuple.)
1087 /* we need not do MJEvalInnerValues again */
1092 else if (compareResult > 0)
1095 * if the new outer tuple didn't match the marked inner
1096 * tuple then we have a case like:
1099 * 4 4 - marked tuple
1104 * which means that all subsequent outer tuples will be
1105 * larger than our marked inner tuples. So we need not
1106 * revisit any of the marked tuples but can proceed to
1107 * look for a match to the current inner. If there's
1108 * no more inners, no more matches are possible.
1113 /* reload comparison data for current inner */
1117 /* proceed to compare it to the current outer */
1123 * current inner can't possibly match any outer;
1124 * better to advance the inner scan than the
1130 /* No more inner tuples */
1134 * Need to emit left-join tuples for remaining
1140 /* Otherwise we're done. */
1144 else /* compareResult < 0 should not happen */
1145 elog(
ERROR,
"mergejoin input data is out of order");
1148 /*----------------------------------------------------------
1149 * EXEC_MJ_SKIP_TEST means compare tuples and if they do not
1150 * match, skip whichever is lesser.
1157 * outer tuple - 6 8 - inner tuple
1161 * we have to advance the outer scan
1162 * until we find the outer 8.
1164 * On the other hand:
1169 * outer tuple - 12 8 - inner tuple
1173 * we have to advance the inner scan
1174 * until we find the inner 12.
1175 *----------------------------------------------------------
1178 MJ_printf(
"ExecMergeJoin: EXEC_MJ_SKIP_TEST\n");
1181 * before we advance, make sure the current tuples do not
1182 * satisfy the mergeclauses. If they do, then we update the
1183 * marked tuple position and go join them.
1188 if (compareResult == 0)
1197 else if (compareResult < 0)
1200 /* compareResult > 0 */
1205 * EXEC_MJ_SKIPOUTER_ADVANCE: advance over an outer tuple that
1206 * is known not to join to any inner tuple.
1208 * Before advancing, we check to see if we must emit an
1209 * outer-join fill tuple for this outer tuple.
1212 MJ_printf(
"ExecMergeJoin: EXEC_MJ_SKIPOUTER_ADVANCE\n");
1217 * Generate a fake join tuple with nulls for the inner
1218 * tuple, and return it if it passes the non-join quals.
1230 * now we get the next outer tuple, if any
1237 /* Compute join values and check for unmatchability */
1241 /* Go test the new tuple against the current inner */
1245 /* Can't match, so fetch next outer tuple */
1249 /* No more outer tuples */
1250 MJ_printf(
"ExecMergeJoin: end of outer subplan\n");
1252 if (doFillInner && !
TupIsNull(innerTupleSlot))
1255 * Need to emit right-join tuples for remaining
1261 /* Otherwise we're done. */
1267 * EXEC_MJ_SKIPINNER_ADVANCE: advance over an inner tuple that
1268 * is known not to join to any outer tuple.
1270 * Before advancing, we check to see if we must emit an
1271 * outer-join fill tuple for this inner tuple.
1274 MJ_printf(
"ExecMergeJoin: EXEC_MJ_SKIPINNER_ADVANCE\n");
1279 * Generate a fake join tuple with nulls for the outer
1280 * tuple, and return it if it passes the non-join quals.
1291 /* Mark before advancing, if wanted */
1296 * now we get the next inner tuple, if any
1303 /* Compute join values and check for unmatchability */
1307 /* proceed to compare it to the current outer */
1313 * current inner can't possibly match any outer;
1314 * better to advance the inner scan than the outer.
1319 /* No more inner tuples */
1320 MJ_printf(
"ExecMergeJoin: end of inner subplan\n");
1322 if (doFillOuter && !
TupIsNull(outerTupleSlot))
1325 * Need to emit left-join tuples for remaining
1331 /* Otherwise we're done. */
1337 * EXEC_MJ_ENDOUTER means we have run out of outer tuples, but
1338 * are doing a right/right-anti/full join and therefore must
1339 * null-fill any remaining unmatched inner tuples.
1342 MJ_printf(
"ExecMergeJoin: EXEC_MJ_ENDOUTER\n");
1349 * Generate a fake join tuple with nulls for the outer
1350 * tuple, and return it if it passes the non-join quals.
1361 /* Mark before advancing, if wanted */
1366 * now we get the next inner tuple, if any
1375 MJ_printf(
"ExecMergeJoin: end of inner subplan\n");
1379 /* Else remain in ENDOUTER state and process next tuple. */
1383 * EXEC_MJ_ENDINNER means we have run out of inner tuples, but
1384 * are doing a left/full join and therefore must null- fill
1385 * any remaining unmatched outer tuples.
1388 MJ_printf(
"ExecMergeJoin: EXEC_MJ_ENDINNER\n");
1395 * Generate a fake join tuple with nulls for the inner
1396 * tuple, and return it if it passes the non-join quals.
1408 * now we get the next outer tuple, if any
1417 MJ_printf(
"ExecMergeJoin: end of outer subplan\n");
1421 /* Else remain in ENDINNER state and process next tuple. */
1425 * broken state value?
1428 elog(
ERROR,
"unrecognized mergejoin state: %d",
1434/* ----------------------------------------------------------------
1436 * ----------------------------------------------------------------
1446 /* check for unsupported flags */
1450 "initializing node");
1453 * create state structure
1463 * Miscellaneous initialization
1465 * create expression context for node
1470 * we need two additional econtexts in which we can compute the join
1471 * expressions from the left and right input tuples. The node's regular
1472 * econtext won't do because it gets reset too often.
1478 * initialize child nodes
1480 * inner child must support MARK/RESTORE, unless we have detected that we
1481 * don't need that. Note that skip_mark_restore must never be set if
1482 * there are non-mergeclause joinquals, since the logic wouldn't work.
1496 * For certain types of inner child nodes, it is advantageous to issue
1497 * MARK every time we advance past an inner tuple we will never return to.
1498 * For other types, MARK on a tuple we cannot return to is a waste of
1499 * cycles. Detect which case applies and set mj_ExtraMarks if we want to
1500 * issue "unnecessary" MARK calls.
1502 * Currently, only Material wants the extra MARKs, and it will be helpful
1503 * only if eflags doesn't specify REWIND.
1505 * Note that for IndexScan and IndexOnlyScan, it is *necessary* that we
1506 * not set mj_ExtraMarks; otherwise we might attempt to set a mark before
1507 * the first inner tuple, which they do not support.
1517 * Initialize result slot, type and projection.
1523 * tuple table initialization
1530 * initialize child expressions
1536 /* mergeclauses are handled below */
1539 * detect whether we need only consider the first matching inner tuple
1544 /* set up null tuples for outer joins, if needed */
1567 * Can't handle right, right-anti or full join with non-constant
1568 * extra joinclauses. This should have been caught by planner.
1573 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1574 errmsg(
"RIGHT JOIN is only supported with merge-joinable join conditions")));
1585 * Can't handle right, right-anti or full join with non-constant
1586 * extra joinclauses. This should have been caught by planner.
1591 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1592 errmsg(
"FULL JOIN is only supported with merge-joinable join conditions")));
1595 elog(
ERROR,
"unrecognized join type: %d",
1600 * preprocess the merge clauses
1604 node->mergeFamilies,
1605 node->mergeCollations,
1606 node->mergeReversals,
1607 node->mergeNullsFirst,
1611 * initialize join state
1620 * initialization successful
1623 "node initialized");
1628/* ----------------------------------------------------------------
1632 * frees storage allocated through C routines.
1633 * ----------------------------------------------------------------
1639 "ending node processing");
1642 * shut down the subplans
1648 "node processing ended");
1666 * if chgParam of subnodes is not null then plans will be re-scanned by
1667 * first ExecProcNode.
CompareType IndexAmTranslateStrategy(StrategyNumber strategy, Oid amoid, Oid opfamily, bool missing_ok)
#define OidIsValid(objectId)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void ExecMarkPos(PlanState *node)
void ExecReScan(PlanState *node)
void ExecRestrPos(PlanState *node)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
ExprState * ExecInitQual(List *qual, PlanState *parent)
void ExecEndNode(PlanState *node)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
const TupleTableSlotOps TTSOpsVirtual
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
TupleTableSlot * ExecInitNullTupleSlot(EState *estate, TupleDesc tupType, const TupleTableSlotOps *tts_ops)
TupleDesc ExecGetResultType(PlanState *planstate)
ExprContext * CreateExprContext(EState *estate)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
#define MJ_DEBUG_COMPARE(res)
#define MJ_DEBUG_QUAL(clause, res)
#define MJ_DEBUG_PROC_NODE(slot)
#define MJ_debugtup(slot)
#define InstrCountFiltered1(node, delta)
#define outerPlanState(node)
#define InstrCountFiltered2(node, delta)
#define innerPlanState(node)
struct MergeJoinClauseData * MergeJoinClause
#define EXEC_FLAG_BACKWARD
static TupleTableSlot * ExecProject(ProjectionInfo *projInfo)
#define ResetExprContext(econtext)
static bool ExecQual(ExprState *state, ExprContext *econtext)
static TupleTableSlot * ExecProcNode(PlanState *node)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
#define OidFunctionCall1(functionId, arg1)
Assert(PointerIsAligned(start, uint64))
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
Oid get_opfamily_method(Oid opfid)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
#define BTSORTSUPPORT_PROC
static MergeJoinClause MJExamineQuals(List *mergeclauses, Oid *mergefamilies, Oid *mergecollations, bool *mergereversals, bool *mergenullsfirst, PlanState *parent)
static int MJCompare(MergeJoinState *mergestate)
struct MergeJoinClauseData MergeJoinClauseData
#define EXEC_MJ_SKIP_TEST
#define EXEC_MJ_JOINTUPLES
static TupleTableSlot * ExecMergeJoin(PlanState *pstate)
#define EXEC_MJ_SKIPOUTER_ADVANCE
#define MarkInnerTuple(innerTupleSlot, mergestate)
#define EXEC_MJ_TESTOUTER
static TupleTableSlot * MJFillOuter(MergeJoinState *node)
void ExecReScanMergeJoin(MergeJoinState *node)
static MJEvalResult MJEvalOuterValues(MergeJoinState *mergestate)
#define EXEC_MJ_INITIALIZE_OUTER
#define EXEC_MJ_SKIPINNER_ADVANCE
MergeJoinState * ExecInitMergeJoin(MergeJoin *node, EState *estate, int eflags)
#define EXEC_MJ_NEXTOUTER
void ExecEndMergeJoin(MergeJoinState *node)
#define EXEC_MJ_INITIALIZE_INNER
static MJEvalResult MJEvalInnerValues(MergeJoinState *mergestate, TupleTableSlot *innerslot)
#define EXEC_MJ_NEXTINNER
static TupleTableSlot * MJFillInner(MergeJoinState *node)
static bool check_constant_qual(List *qual, bool *is_const_false)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int list_length(const List *l)
static bool DatumGetBool(Datum X)
static Datum PointerGetDatum(const void *X)
void PrepareSortSupportComparisonShim(Oid cmpFunc, SortSupport ssup)
static int ApplySortComparator(Datum datum1, bool isNull1, Datum datum2, bool isNull2, SortSupport ssup)
MemoryContext ecxt_per_tuple_memory
TupleTableSlot * ecxt_innertuple
TupleTableSlot * ecxt_outertuple
TupleTableSlot * mj_MarkedTupleSlot
TupleTableSlot * mj_NullInnerTupleSlot
ExprContext * mj_InnerEContext
TupleTableSlot * mj_NullOuterTupleSlot
MergeJoinClause mj_Clauses
TupleTableSlot * mj_InnerTupleSlot
ExprContext * mj_OuterEContext
TupleTableSlot * mj_OuterTupleSlot
ExprContext * ps_ExprContext
ProjectionInfo * ps_ProjInfo
ExecProcNodeMtd ExecProcNode
int(* comparator)(Datum x, Datum y, SortSupport ssup)
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)