Repository navigation
fix(unparser): empty projection fallback and preserve global aggregates #27333
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. Does SELECT 1 preserve the meaning of a zero-column projection outside count(*), such as EXISTS or a UNION with zero columns?
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. The Because the parent was planned against a zero-column input, nothing above the empty To check the cases you mentioned, I ran zero-column queries in DataFusion and PostgreSQL 17, and ran the default-dialect unparser output for the same plans, which is the same query with
The one visible difference is when the empty projection is the root of the plan, e.g. a user explicitly asks for zero columns. Then the SQL returns one constant column instead of zero. That's the same trade-off This PR also fixes a union case. Before it, an empty
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. Following up: a review found that the global aggregate case did change cardinality; that's fixed in 95a69c2. |
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.
Non-blocking: Could we also unparse this optimized plan using BigQueryDialect to cover the complete nested query reported in #27332?
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.
Added in 95a69c2:
optimized_count_over_filter_empty_projectionnow also unparses the optimized plan withBigQueryDialect, which givesSELECT count(1) AS `count_40_42_41` FROM (SELECT 1 FROM `t` WHERE (`t`.`id` > 10)). The alias is BigQuery's usual escaping ofcount(*).