1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-09 13:09:39 +03:00

Forbid SJE with result relation

The target relation for INSERT/UPDATE/DELETE/MERGE has a different behavior
than other relations in EvalPlanQual() and RETURNING clause.  This is why we
forbid target relation to be either source or target relation in SJE.
It's not clear if we could ever support this.

Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/b9e8f460-f9a6-0e9b-e8ba-60d59f0bc22c%40gmail.com
This commit is contained in:
Alexander Korotkov
2024-01-09 10:01:22 +02:00
parent 30b4955a46
commit 8c441c0827
4 changed files with 84 additions and 48 deletions

View File

@@ -2086,6 +2086,14 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
{
RelOptInfo *inner = root->simple_rel_array[r];
/*
* We don't accept result relation as either source or target relation
* of SJE, because result relation has different behavior in
* EvalPlanQual() and RETURNING clause.
*/
if (root->parse->resultRelation == r)
continue;
k = r;
while ((k = bms_next_member(relids, k)) > 0)
@@ -2101,6 +2109,9 @@ remove_self_joins_one_group(PlannerInfo *root, Relids relids)
PlanRowMark *imark = NULL;
List *uclauses = NIL;
if (root->parse->resultRelation == k)
continue;
/* A sanity check: the relations have the same Oid. */
Assert(root->simple_rte_array[k]->relid ==
root->simple_rte_array[r]->relid);