From 56df115668d16ef90af455dff156d9f9114c66f5 Mon Sep 17 00:00:00 2001 From: Colm McHugh Date: Thu, 16 Jan 2025 18:17:20 +0000 Subject: [PATCH] Potential fix for issues #7782, #7783 --- .../distributed/planner/distributed_planner.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/backend/distributed/planner/distributed_planner.c b/src/backend/distributed/planner/distributed_planner.c index 0ec3883da..21af214fd 100644 --- a/src/backend/distributed/planner/distributed_planner.c +++ b/src/backend/distributed/planner/distributed_planner.c @@ -272,6 +272,22 @@ distributed_planner(Query *parse, planContext.plan = standard_planner(planContext.query, NULL, planContext.cursorOptions, planContext.boundParams); + + if (needsDistributedPlanning) + { + List *rtesPostPlan = ExtractRangeTableEntryList(planContext.query); + if (list_length(rtesPostPlan) < list_length(rangeTableList)) + { + bool fDistributedTable = false; + + /* range table entries have been reduced by planner, possibly by constant folding. */ + needsDistributedPlanning = ListContainsDistributedTableRTE( + rtesPostPlan, + & + fDistributedTable); + } + } + if (needsDistributedPlanning) { result = PlanDistributedStmt(&planContext, rteIdCounter);