diff --git a/src/backend/distributed/planner/deparse_shard_query.c b/src/backend/distributed/planner/deparse_shard_query.c index 2c91df2a1..b47154535 100644 --- a/src/backend/distributed/planner/deparse_shard_query.c +++ b/src/backend/distributed/planner/deparse_shard_query.c @@ -222,8 +222,8 @@ DefineQualsForShardInterval(RelationShard *relationShard, int attnum, int rtinde /* * Add constraints for the relation identified by rtindex, specifically on its column at attnum. - * Create a Var node representing this column, which will be used to compare against the partition - * column for shard interval qualification. + * Create a Var node representing this column, which will be used to compare against the bounds + * from the partition column of shard interval. */ Var *outerTablePartitionColumnVar = makeVar( @@ -371,6 +371,7 @@ UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList) * outerRtIndex : RT index whose column we will constrain, * outerRte / innerRte, * attnum : attribute number (partition column) on outer side. + * This is compared to partition column of innerRte. * 3. Find the RelationShard for the inner distributed table (innerRte->relid) * in relationShardList; skip if absent (no fixed shard chosen). * 4. Build the shard qualification with DefineQualsForShardInterval(): @@ -385,7 +386,7 @@ UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList) void UpdateWhereClauseForOuterJoin(Query *query, List *relationShardList) { - if (query == NULL || query->jointree == NULL || query->jointree->fromlist == NIL) + if (query == NULL) { return; } diff --git a/src/backend/distributed/planner/multi_physical_planner.c b/src/backend/distributed/planner/multi_physical_planner.c index 15d48d821..ff7796429 100644 --- a/src/backend/distributed/planner/multi_physical_planner.c +++ b/src/backend/distributed/planner/multi_physical_planner.c @@ -2357,8 +2357,6 @@ QueryPushdownSqlTaskList(Query *query, uint64 jobId, * * The function also sets outerPartHasDistributedTable if the outer part * of the corresponding join has a distributed table. - * - * The function returns true only if all three conditions above hold true. */ static bool IsInnerTableOfOuterJoin(RelationRestriction *relationRestriction, @@ -2598,17 +2596,11 @@ QueryPushdownTaskCreate(Query *originalQuery, int shardIndex, */ UpdateRelationToShardNames((Node *) taskQuery, relationShardList); - if (updateQualsForOuterJoin) - { - UpdateWhereClauseForOuterJoinWalker((Node *) taskQuery, relationShardList); - } - /* * Ands are made implicit during shard pruning, as predicate comparison and * refutation depend on it being so. We need to make them explicit again so * that the query string is generated as (...) AND (...) as opposed to * (...), (...). - * TODO: do we need to run this before adding quals? */ if (taskQuery->jointree->quals != NULL && IsA(taskQuery->jointree->quals, List)) { @@ -2616,6 +2608,12 @@ QueryPushdownTaskCreate(Query *originalQuery, int shardIndex, (List *) taskQuery->jointree->quals); } + if (updateQualsForOuterJoin) + { + UpdateWhereClauseForOuterJoinWalker((Node *) taskQuery, relationShardList); + } + + Task *subqueryTask = CreateBasicTask(jobId, taskId, taskType, NULL); if ((taskType == MODIFY_TASK && !modifyRequiresCoordinatorEvaluation) || diff --git a/src/backend/distributed/shared_library_init.c b/src/backend/distributed/shared_library_init.c index d98945e01..e2d21d074 100644 --- a/src/backend/distributed/shared_library_init.c +++ b/src/backend/distributed/shared_library_init.c @@ -2334,7 +2334,6 @@ RegisterCitusConfigVariables(void) GUC_UNIT_BYTE | GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE, NULL, NULL, NULL); - DefineCustomIntVariable( "citus.recover_2pc_interval", gettext_noop("Sets the time to wait between recovering 2PCs."), diff --git a/src/test/regress/expected/multi_subquery_in_where_reference_clause.out b/src/test/regress/expected/multi_subquery_in_where_reference_clause.out index 3f8b637dd..eabc5e421 100644 --- a/src/test/regress/expected/multi_subquery_in_where_reference_clause.out +++ b/src/test/regress/expected/multi_subquery_in_where_reference_clause.out @@ -306,7 +306,7 @@ ORDER BY 1, 2; 5 | 5 (2 rows) --- reference table LEFT JOIN distributed table in WHERE is ok +-- reference table LEFT JOIN distributed table in WHERE is still not ok SELECT user_id, value_2 FROM users_table WHERE value_1 > 1 AND value_1 < 3 AND value_2 >= 5 diff --git a/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql b/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql index 59c9d263a..326ae5a91 100644 --- a/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql +++ b/src/test/regress/sql/multi_subquery_in_where_reference_clause.sql @@ -260,7 +260,7 @@ SELECT user_id, value_2 FROM users_table WHERE ) ORDER BY 1, 2; --- reference table LEFT JOIN distributed table in WHERE is ok +-- reference table LEFT JOIN distributed table in WHERE is still not ok SELECT user_id, value_2 FROM users_table WHERE value_1 > 1 AND value_1 < 3 AND value_2 >= 5