-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Is your feature request related to a problem or challenge?
The current the plan for a nested UNION is still nested resulting in unecessary GROUPing
❯ explain SELECT 1 UNION (SELECT 1 UNION SELECT 1);
+---------------+-----------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+-----------------------------------------------------------------------------------------+
| logical_plan | Aggregate: groupBy=[[Int64(1)]], aggr=[[]] |
| | Union |
| | Projection: Int64(1) |
| | EmptyRelation |
| | Aggregate: groupBy=[[Int64(1)]], aggr=[[]] |
| | Union |
| | Projection: Int64(1) |
| | EmptyRelation |
| | Projection: Int64(1) |
| | EmptyRelation |
Describe the solution you'd like
As suggested by @jackwener: #7695 (comment), ideally the plan should look like the following (the unions should be unnested and run through a single group by):
❯ explain SELECT 1 UNION (SELECT 1 UNION SELECT 1);
+---------------+-----------------------------------------------------------------------------------------+
| plan_type | plan |
+---------------+-----------------------------------------------------------------------------------------+
| logical_plan | Aggregate: groupBy=[[Int64(1)]], aggr=[[]] |
| | Union |
| | Projection: Int64(1) |
| | EmptyRelation |
| | Projection: Int64(1) |
| | EmptyRelation |
| | Projection: Int64(1) |
| | EmptyRelation |
Describe alternatives you've considered
No response
Additional context
@maruschin added a nice optimization (as well as very nice tests) to unnest UNION ALL in #7695
❯ explain SELECT 1 UNION ALL (SELECT 1 UNION ALL SELECT 1);
+---------------+----------------------------------------+
| plan_type | plan |
+---------------+----------------------------------------+
| logical_plan | Union |
| | Projection: Int64(1) AS Int64(1) |
| | EmptyRelation |
| | Projection: Int64(1) AS Int64(1) |
| | EmptyRelation |
| | Projection: Int64(1) AS Int64(1) |
| | EmptyRelation |Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request