From 2d6cf8e79aa6d5b6c9fd203443fd1fbb972b05c7 Mon Sep 17 00:00:00 2001 From: Naisila Puka <37271756+naisila@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:07:18 +0300 Subject: [PATCH] PG16 compatibility - one more outer join check (#7126) PG16 compatibility - part 11 Check out part 1 https://github.com/citusdata/citus/commit/42d956888d5be65153ccf24cb039027ecd7c0192 part 2 https://github.com/citusdata/citus/commit/0d503dd5ac5547ca71cd0147e53236d8d8a22fce part 3 https://github.com/citusdata/citus/commit/907d72e60d4043924f52200b24d281fe7b79f75f part 4 https://github.com/citusdata/citus/commit/7c6b4ce1035491ff5a31a9d15bb8b28f3c0dd5b3 part 5 https://github.com/citusdata/citus/commit/6056cb2c2931ae33b42f009872385af518cf2f8b part 6 https://github.com/citusdata/citus/commit/b36c431abbe3f70ba18de5610570adfa9d72d56d part 7 https://github.com/citusdata/citus/commit/ee3153fe5062821e8b83fb7bf62a67a20bbb5098 part 8 https://github.com/citusdata/citus/commit/2c50b5f7ff5e0c08c92a93b2b3292c403826a32a part 9 https://github.com/citusdata/citus/commit/b2291374b4e894b00c1b166ac424072ff8c29bee part 10 https://github.com/citusdata/citus/commit/a2315fdc677675b420913ca4f81116e165d52397 part 11 https://github.com/citusdata/citus/commit/9fa72545e247bc40afbbbdc752f1b8a327199ac5 This commit is in the series of PG16 compatibility commits. We already took care of the majority of necessary outer join checks in part 4 https://github.com/citusdata/citus/commit/7c6b4ce1035491ff5a31a9d15bb8b28f3c0dd5b3 However, In RelationInfoContainsOnlyRecurringTuples, we need to add one more check of whether we are dealing with an outer join RTE using IsRelOptOuterJoin function. This prevents an outer join crash in sqlancer_failures.sql test. We expect one more commit of PG compatibility with Citus's current features are regression tests sanity. --- .../planner/query_pushdown_planning.c | 6 ++++++ .../planner/relation_restriction_equivalence.c | 16 +++++++--------- .../relation_restriction_equivalence.h | 1 + 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/backend/distributed/planner/query_pushdown_planning.c b/src/backend/distributed/planner/query_pushdown_planning.c index 200509974..3bad73459 100644 --- a/src/backend/distributed/planner/query_pushdown_planning.c +++ b/src/backend/distributed/planner/query_pushdown_planning.c @@ -1414,6 +1414,12 @@ RelationInfoContainsOnlyRecurringTuples(PlannerInfo *plannerInfo, Relids relids) while ((relationId = bms_next_member(relids, relationId)) >= 0) { + /* outer join RTE check in PG16 */ + if (IsRelOptOuterJoin(plannerInfo, relationId)) + { + continue; + } + RangeTblEntry *rangeTableEntry = plannerInfo->simple_rte_array[relationId]; if (FindNodeMatchingCheckFunctionInRangeTableList(list_make1(rangeTableEntry), diff --git a/src/backend/distributed/planner/relation_restriction_equivalence.c b/src/backend/distributed/planner/relation_restriction_equivalence.c index af2443b19..368ba2026 100644 --- a/src/backend/distributed/planner/relation_restriction_equivalence.c +++ b/src/backend/distributed/planner/relation_restriction_equivalence.c @@ -171,8 +171,6 @@ static bool FindQueryContainingRTEIdentityInternal(Node *node, static int ParentCountPriorToAppendRel(List *appendRelList, AppendRelInfo *appendRelInfo); -static bool IsVarRelOptOuterJoin(PlannerInfo *root, Var *varToBeAdded); - /* * AllDistributionKeysInQueryAreEqual returns true if either @@ -1241,7 +1239,7 @@ AddToAttributeEquivalenceClass(AttributeEquivalenceClass *attributeEquivalenceCl } /* outer join checks in PG16 */ - if (IsVarRelOptOuterJoin(root, varToBeAdded)) + if (IsRelOptOuterJoin(root, varToBeAdded->varno)) { return; } @@ -1388,19 +1386,19 @@ GetTargetSubquery(PlannerInfo *root, RangeTblEntry *rangeTableEntry, Var *varToB /* - * IsVarRelOptOuterJoin returns true if the Var to be added - * is an outer join, false otherwise. + * IsRelOptOuterJoin returns true if the RelOpt referenced + * by varNo is an outer join, false otherwise. */ -static bool -IsVarRelOptOuterJoin(PlannerInfo *root, Var *varToBeAdded) +bool +IsRelOptOuterJoin(PlannerInfo *root, int varNo) { #if PG_VERSION_NUM >= PG_VERSION_16 - if (root->simple_rel_array_size <= varToBeAdded->varno) + if (root->simple_rel_array_size <= varNo) { return true; } - RelOptInfo *rel = root->simple_rel_array[varToBeAdded->varno]; + RelOptInfo *rel = root->simple_rel_array[varNo]; if (rel == NULL) { /* must be an outer join */ diff --git a/src/include/distributed/relation_restriction_equivalence.h b/src/include/distributed/relation_restriction_equivalence.h index 42b2b801f..f3a7e2b94 100644 --- a/src/include/distributed/relation_restriction_equivalence.h +++ b/src/include/distributed/relation_restriction_equivalence.h @@ -20,6 +20,7 @@ extern bool AllDistributionKeysInQueryAreEqual(Query *originalQuery, PlannerRestrictionContext * plannerRestrictionContext); +extern bool IsRelOptOuterJoin(PlannerInfo *root, int varNo); extern bool SafeToPushdownUnionSubquery(Query *originalQuery, PlannerRestrictionContext * plannerRestrictionContext); extern bool ContainsUnionSubquery(Query *queryTree);