neilconway commented on PR #23871: URL: https://github.com/apache/datafusion/pull/23871#issuecomment-5073629243
@alamb > I am really struggling to figure out why the solutions seem so complicated and I don't understand why emitting an output row is a function of all the groups being constant. 1. When _all_ grouping keys are constants, the optimizer (`EliminateGroupByConstant`) removes the grouping entirely, replacing a grouped agg with an ungrouped agg 2. This changes the semantics of the query. `count()` is not a special-case per se; `count()` produces a single row with `0`, most other aggs will produce a single row with `NULL`. This is different than a grouped agg over an empty input, which should produce zero rows. To me, the simplest fix here is just to decline to optimize away the grouping if _all_ of the grouping expressions are constants. This is a corner case anyway; the perf cost is not catastrophic, and I'd be surprised to see a real-world workload where this pattern occurs. And yes, I realize that we did something similar in a prior PR 🙃 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
