mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Use appendrel planning logic for top-level UNION ALL structures.
Formerly, we could convert a UNION ALL structure inside a subquery-in-FROM into an appendrel, as a side effect of pulling up the subquery into its parent; but top-level UNION ALL always caused use of plan_set_operations(). That didn't matter too much because you got an Append-based plan either way. However, now that the appendrel code can do things with MergeAppend, it's worthwhile to hack up the top-level case so it also uses appendrels. This is a bit of a stopgap; but going much further than this will require a major rewrite of the planner's set-operations support, which I'm not prepared to undertake now. For the moment let's grab the low-hanging fruit.
This commit is contained in:
@ -341,12 +341,21 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
|
||||
inline_set_returning_functions(root);
|
||||
|
||||
/*
|
||||
* Check to see if any subqueries in the rangetable can be merged into
|
||||
* Check to see if any subqueries in the jointree can be merged into
|
||||
* this query.
|
||||
*/
|
||||
parse->jointree = (FromExpr *)
|
||||
pull_up_subqueries(root, (Node *) parse->jointree, NULL, NULL);
|
||||
|
||||
/*
|
||||
* If this is a simple UNION ALL query, flatten it into an appendrel.
|
||||
* We do this now because it requires applying pull_up_subqueries to the
|
||||
* leaf queries of the UNION ALL, which weren't touched above because they
|
||||
* weren't referenced by the jointree (they will be after we do this).
|
||||
*/
|
||||
if (parse->setOperations)
|
||||
flatten_simple_union_all(root);
|
||||
|
||||
/*
|
||||
* Detect whether any rangetable entries are RTE_JOIN kind; if not, we can
|
||||
* avoid the expense of doing flatten_join_alias_vars(). Also check for
|
||||
|
Reference in New Issue
Block a user