-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[bug]: Fix wrong order by removal from plan #13497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fd5ab12
59f056e
50005f3
458cf19
fa9284a
1bc5c06
6fbfeb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1260,3 +1260,49 @@ limit 2; | |
|
|
||
| statement ok | ||
| drop table ordered_table; | ||
|
|
||
| query TT | ||
| EXPLAIN SELECT | ||
| CASE | ||
| WHEN name = 'name1' THEN 0.0 | ||
| WHEN name = 'name2' THEN 0.5 | ||
| END AS a | ||
| FROM ( | ||
| SELECT 'name1' AS name | ||
| UNION ALL | ||
| SELECT 'name2' | ||
| ) | ||
| ORDER BY a DESC; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please also add a test case with query that would produce incorrect results before the fix?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I have added a new test in this commit. Prior to this fix, we would get nondeterministic results. |
||
| ---- | ||
| logical_plan | ||
| 01)Sort: a DESC NULLS FIRST | ||
| 02)--Projection: CASE WHEN name = Utf8("name1") THEN Float64(0) WHEN name = Utf8("name2") THEN Float64(0.5) END AS a | ||
| 03)----Union | ||
| 04)------Projection: Utf8("name1") AS name | ||
| 05)--------EmptyRelation | ||
| 06)------Projection: Utf8("name2") AS name | ||
| 07)--------EmptyRelation | ||
| physical_plan | ||
| 01)SortPreservingMergeExec: [a@0 DESC] | ||
| 02)--ProjectionExec: expr=[CASE WHEN name@0 = name1 THEN 0 WHEN name@0 = name2 THEN 0.5 END as a] | ||
| 03)----UnionExec | ||
| 04)------ProjectionExec: expr=[name1 as name] | ||
| 05)--------PlaceholderRowExec | ||
| 06)------ProjectionExec: expr=[name2 as name] | ||
| 07)--------PlaceholderRowExec | ||
|
|
||
| query R | ||
| SELECT | ||
| CASE | ||
| WHEN name = 'name1' THEN 0.0 | ||
| WHEN name = 'name2' THEN 0.5 | ||
| END AS a | ||
| FROM ( | ||
| SELECT 'name1' AS name | ||
| UNION ALL | ||
| SELECT 'name2' | ||
| ) | ||
| ORDER BY a DESC; | ||
| ---- | ||
| 0.5 | ||
| 0 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love this doc!
so the result is
trueif expression contains only constants?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, when constantness is correct across partitions.