mertak-synnada opened a new pull request, #11781: URL: https://github.com/apache/datafusion/pull/11781
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> Closes #. ## Rationale for this change Inefficient planning is produced when a redundant DISTINCT & GROUP BY clause is used together. Eg. ``` EXPLAIN SELECT c3 FROM aggregate_test_100 GROUP BY c3 LIMIT 5; logical_plan Limit: skip=0, fetch=5 --Aggregate: groupBy=[[aggregate_test_100.c3]], aggr=[[]] ----Aggregate: groupBy=[[aggregate_test_100.c3]], aggr=[[]] ------TableScan: aggregate_test_100 projection=[c3] physical_plan GlobalLimitExec: skip=0, fetch=5 --AggregateExec: mode=Final, gby=[c3@0 as c3], aggr=[], lim=[5] ----CoalescePartitionsExec ------AggregateExec: mode=Partial, gby=[c3@0 as c3], aggr=[], lim=[5] --------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 ----------AggregateExec: mode=Final, gby=[c3@0 as c3], aggr=[], lim=[5] ------------CoalescePartitionsExec --------------AggregateExec: mode=Partial, gby=[c3@0 as c3], aggr=[], lim=[5] ----------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1 ------------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c3], has_header=true ``` Consecutive empty aggregates with same group by are unnecessary. ## What changes are included in this PR? It's fixed that if a distinct is the same as a following group by statement, it should not be turned into an Aggregate plan. ## Are these changes tested? Yes ## Are there any user-facing changes? No -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org