This commit adds a safety-net to the issue seen in #6785. The fix for the underlying issue will be in the PR#6943

(cherry picked from commit f9dbe7784b)
release-11.3-gokhan-1
Teja Mupparti 2023-05-26 11:03:45 -07:00
parent 78f0b0c6dd
commit 2de879dc59
1 changed files with 28 additions and 9 deletions

View File

@ -1885,17 +1885,36 @@ RouterJob(Query *originalQuery, PlannerRestrictionContext *plannerRestrictionCon
{ {
RangeTblEntry *updateOrDeleteOrMergeRTE = ExtractResultRelationRTE(originalQuery); 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) 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;
}
} }
} }