diff options
author | David Rowley | 2024-04-01 23:15:45 +0000 |
---|---|---|
committer | David Rowley | 2024-04-01 23:15:45 +0000 |
commit | d5d2205c8ddc6670fa87474e172fdfab162b7a73 (patch) | |
tree | 6445b3d946f634d0a683650619f0b7cb7694859f /src/backend/optimizer/plan/subselect.c | |
parent | 3622c8084643cc05bc8f28d0b238615c845eae14 (diff) |
Fix assert failure when planning setop subqueries with CTEs
66c0185a3 adjusted the UNION planner to request that union child queries
produce Paths correctly ordered to implement the UNION by way of
MergeAppend followed by Unique. The code there made a bad assumption
that if the root->parent_root->parse had setOperations set that the
query must be the child subquery of a set operation. That's not true
when it comes to planning a non-inlined CTE which is parented by a set
operation. This causes issues as the CTE's targetlist has no
requirement to match up to the SetOperationStmt's groupClauses
Fix this by adding a new parameter to both subquery_planner() and
grouping_planner() to explicitly pass the SetOperationStmt only when
planning set operation child subqueries.
Thank you to Tom Lane for helping to rationalize the decision on the
best function signature for subquery_planner().
Reported-by: Alexander Lakhin
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/backend/optimizer/plan/subselect.c')
-rw-r--r-- | src/backend/optimizer/plan/subselect.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index d5fa281b102..e35ebea8b43 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -218,9 +218,8 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, Assert(root->plan_params == NIL); /* Generate Paths for the subquery */ - subroot = subquery_planner(root->glob, subquery, - root, - false, tuple_fraction); + subroot = subquery_planner(root->glob, subquery, root, false, + tuple_fraction, NULL); /* Isolate the params needed by this specific subplan */ plan_params = root->plan_params; @@ -266,9 +265,8 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, if (subquery) { /* Generate Paths for the ANY subquery; we'll need all rows */ - subroot = subquery_planner(root->glob, subquery, - root, - false, 0.0); + subroot = subquery_planner(root->glob, subquery, root, false, 0.0, + NULL); /* Isolate the params needed by this specific subplan */ plan_params = root->plan_params; @@ -967,9 +965,8 @@ SS_process_ctes(PlannerInfo *root) * Generate Paths for the CTE query. Always plan for full retrieval * --- we don't have enough info to predict otherwise. */ - subroot = subquery_planner(root->glob, subquery, - root, - cte->cterecursive, 0.0); + subroot = subquery_planner(root->glob, subquery, root, + cte->cterecursive, 0.0, NULL); /* * Since the current query level doesn't yet contain any RTEs, it |