From f9dbe7784b734d11eb7daf1faa34b227f8c32a58 Mon Sep 17 00:00:00 2001 From: Teja Mupparti Date: Fri, 26 May 2023 11:03:45 -0700 Subject: [PATCH] This commit adds a safety-net to the issue seen in #6785. The fix for the underlying issue will be in the PR#6943 --- .../planner/multi_router_planner.c | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/backend/distributed/planner/multi_router_planner.c b/src/backend/distributed/planner/multi_router_planner.c index 0c6ec9dca..47769f5bb 100644 --- a/src/backend/distributed/planner/multi_router_planner.c +++ b/src/backend/distributed/planner/multi_router_planner.c @@ -1906,17 +1906,36 @@ RouterJob(Query *originalQuery, PlannerRestrictionContext *plannerRestrictionCon { RangeTblEntry *updateOrDeleteOrMergeRTE = ExtractResultRelationRTE(originalQuery); - /* - * If all of the shards are pruned, we replace the relation RTE into - * subquery RTE that returns no results. However, this is not useful - * for UPDATE and DELETE queries. Therefore, if we detect a UPDATE or - * DELETE RTE with subquery type, we just set task list to empty and return - * the job. - */ if (updateOrDeleteOrMergeRTE->rtekind == RTE_SUBQUERY) { - job->taskList = NIL; - return job; + /* + * Not generating tasks for MERGE target relation might + * result in incorrect behavior as source rows with NOT + * MATCHED clause might qualify for insertion. + */ + if (IsMergeQuery(originalQuery)) + { + ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("Merge command is currently " + "unsupported with filters that " + "prunes down to zero shards"), + errhint("Avoid `WHERE false` clause or " + "any equivalent filters that " + "could prune down to zero shards"))); + } + else + { + /* + * If all of the shards are pruned, we replace the + * relation RTE into subquery RTE that returns no + * results. However, this is not useful for UPDATE + * and DELETE queries. Therefore, if we detect a + * UPDATE or DELETE RTE with subquery type, we just + * set task list to empty and return the job. + */ + job->taskList = NIL; + return job; + } } }