From d4f9de7875fedfe5d148910954ea01f9afe5f0e6 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Tue, 4 Apr 2023 18:46:43 +0300 Subject: [PATCH] Explicitly disallow local rels when inserting into dist table (#6817) --- .../distributed/planner/insert_select_planner.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/backend/distributed/planner/insert_select_planner.c b/src/backend/distributed/planner/insert_select_planner.c index e58970fbd..2eab62fc3 100644 --- a/src/backend/distributed/planner/insert_select_planner.c +++ b/src/backend/distributed/planner/insert_select_planner.c @@ -717,6 +717,19 @@ DistributedInsertSelectSupported(Query *queryTree, RangeTblEntry *insertRte, } else { + /* + * Note that we've already checked the non-existence of Postgres + * tables in the subquery. + */ + if (subqueryRteListProperties->hasCitusLocalTable || + subqueryRteListProperties->hasMaterializedView) + { + return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED, + "distributed INSERT ... SELECT cannot select from " + "a local relation when inserting into a distributed " + "table", NULL, NULL); + } + /* ensure that INSERT's partition column comes from SELECT's partition column */ error = InsertPartitionColumnMatchesSelect(queryTree, insertRte, subqueryRte, &selectPartitionColumnTableId);