Uh oh!
There was an error while loading. Please reload this page.
Move nested union optimization from plan builder to logical optimizer - #7695
Conversation
Uh oh!
There was an error while loading. Please reload this page.
alamb
left a comment
There was a problem hiding this comment.
Thank you @maruschin -- this is looking quite close. The basic idea and testing looks very solid. I think several of the CI failures on this PR are due to #7701, so merging / rebasing with master will help.
I also double checked this branch gets the same plan as main
❯ explain select*from (select1UNION ALL (select2UNION ALLselect3));
+---------------+----------------------------------------+
| plan_type | plan |
+---------------+----------------------------------------+
| logical_plan | Union |
| | Projection: Int64(1) AS Int64(1) |
| | EmptyRelation |
| | Projection: Int64(2) AS Int64(1) |
| | EmptyRelation |
| | Projection: Int64(3) AS Int64(1) |
| | EmptyRelation |
| physical_plan | UnionExec |
| | ProjectionExec: expr=[1as Int64(1)] |
| | EmptyExec: produce_one_row=true |
| | ProjectionExec: expr=[2as Int64(1)] |
| | EmptyExec: produce_one_row=true |
| | ProjectionExec: expr=[3as Int64(1)] |
| | EmptyExec: produce_one_row=true |
| | |
+---------------+----------------------------------------+2 rows inset. Query took 0.008 seconds.I found a few sqllogictests seem to fail, specifically
cargo test --test sqllogictests -- timestamp
Running "timestamps.slt"
External error: query result mismatch:
[SQL] SELECT date_trunc('hour', TIMESTAMPTZ '2000-01-01T00:00:00+00:45') as ts_irregular_offset
UNION ALL
SELECT date_trunc('hour', TIMESTAMPTZ '2000-01-01T00:00:00+00:30') as ts_irregular_offset
UNION ALL
SELECT date_trunc('hour', TIMESTAMPTZ '2000-01-01T00:00:00+00:15') as ts_irregular_offset
UNION ALL
SELECT date_trunc('hour', TIMESTAMPTZ '2000-01-01T00:00:00-00:15') as ts_irregular_offset
UNION ALL
SELECT date_trunc('hour', TIMESTAMPTZ '2000-01-01T00:00:00-00:30') as ts_irregular_offset
UNION ALL
SELECT date_trunc('hour', TIMESTAMPTZ '2000-01-01T00:00:00-00:45') as ts_irregular_offset
[Diff] (-expected|+actual)
- 1999-12-31T23:00:00Z
- 1999-12-31T23:00:00Z
- 1999-12-31T23:00:00Z
- 2000-01-01T00:00:00Z
- 2000-01-01T00:00:00Z
- 2000-01-01T00:00:00Z
+ 1999-12-31T23:00:00
+ 1999-12-31T23:00:00
+ 1999-12-31T23:00:00
+ 2000-01-01T00:00:00
+ 2000-01-01T00:00:00
+ 2000-01-01T00:00:00
at test_files/timestamps.slt:1471Which looks to me like the timestamp logic got lost somehow 🤔
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| plan: &LogicalPlan, | ||
| _config: &dyn OptimizerConfig, | ||
| ) -> Result<Option<LogicalPlan>> { | ||
| // TODO: Add optimization for nested distinct unions. |
There was a problem hiding this comment.
at one point (maybe as a TODO) we probably should also remove unions that have only a single child since they are basically a no-op/pass-through. Not sure if this should be an separate optimizer rule or if this should be done in this rule.
There was a problem hiding this comment.
I believe the EliminateOneUnion rule, also added in this PR, handles the one union case
alamb
left a comment
There was a problem hiding this comment.
Thank you very much @maruschin -- this is a really nice piece of work. It is well tested and the code is very clean.
Thank you @crepererum and @jackwener for the reviews
| plan: &LogicalPlan, | ||
| _config: &dyn OptimizerConfig, | ||
| ) -> Result<Option<LogicalPlan>> { | ||
| // TODO: Add optimization for nested distinct unions. |
There was a problem hiding this comment.
I believe the EliminateOneUnion rule, also added in this PR, handles the one union case
Uh oh!
There was an error while loading. Please reload this page.
alamb
commented
Oct 10, 2023
I took the liberty of merging this branch up from main and fixing clippy as I had it all checked out already I also wrote some end to end tests in #7787 |
alamb
commented
Oct 10, 2023
Thanks again @maruschin |
…apache#7695) * Add naive implementation of eliminate_nested_union * Remove union optimization from LogicalPlanBuilder::union * Fix propagate_union_children_different_schema test * Add implementation of eliminate_one_union * Simplified eliminate_nested_union test * Fix * clippy --------- Co-authored-by: Evgeny Maruschenko <evgeny.maruschenko@x5.ru> Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Which issue does this PR close?
Closes#7481.
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?