-
Notifications
You must be signed in to change notification settings - Fork 602
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
fix(sql): remove constants in order_by
calls during select merging
#10475
base: main
Are you sure you want to change the base?
Conversation
b8ac7bc
to
872d5c4
Compare
order_by
calls during select merging
872d5c4
to
a185a03
Compare
It looks like DuckDB's planner erases constants in
|
@@ -320,7 +320,9 @@ def merge_select_select(_, **kwargs): | |||
selections=selections, | |||
predicates=unique_predicates, | |||
qualified=unique_qualified, | |||
sort_keys=unique_sort_keys, | |||
sort_keys=tuple( | |||
key for key in unique_sort_keys if not isinstance(key.expr, ops.Literal) |
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.
Can we remove all expressions which are constant across the relation? I am thinking of all pure scalar nodes.
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.
What do you mean? We can't just start deleting anything that's a literal scalar. Expressions like
SELECT 1 as a
FROM t
are 100% valid and useful.
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.
I only mean the order by expressions.
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.
No because it's possible to write things like 1 if x else 0, and use them in sort keys.
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.
expr = 1 if x else 0
right, though we can identify that as well, like its .relations
attribute is not empty
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.
In any case, it doesn't block this PR.
Remove literals in
ORDER BY
when sorting tables. Fixes #10428.