Skip to content
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(core): disable SingleDistinctToGroupBy for distinct aggregation unparsing #985

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

goldmedal
Copy link
Contributor

@goldmedal goldmedal commented Dec 16, 2024

Description

Given a SQL using distinct aggregation

SELECT c_custkey, count(distinct c_name) FROM customer GROUP BY c_custkey

It will be planned to multiple aggregation plans by SingleDistinctToGroupBy like

     Projection: customer.c_custkey, count(DISTINCT customer.c_name)
      Projection: customer.c_custkey, count(alias1) AS count(DISTINCT customer.c_name)
        Aggregate: groupBy=[[customer.c_custkey]], aggr=[[count(alias1)]]
          Aggregate: groupBy=[[customer.c_custkey, customer.c_name AS alias1]], aggr=[[]]
            SubqueryAlias: customer
              Projection: customer.c_custkey, customer.c_name
                SubqueryAlias: customer
                  Projection: customer.c_custkey AS c_custkey, customer.c_name AS c_name
                    TableScan: customer

However, The unparser can't process it well. Disable it to get the simpler plan:

     Projection: customer.c_custkey, count(DISTINCT customer.c_name)
      Aggregate: groupBy=[[customer.c_custkey]], aggr=[[count(DISTINCT customer.c_name)]]
        SubqueryAlias: customer
          Projection: customer.c_custkey, customer.c_name
            SubqueryAlias: customer
              Projection: customer.c_custkey AS c_custkey, customer.c_name AS c_name
                TableScan: customer

@github-actions github-actions bot added core rust Pull requests that update Rust code labels Dec 16, 2024
@goldmedal goldmedal marked this pull request as ready for review December 16, 2024 02:48
Copy link
Contributor

@grieve54706 grieve54706 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grieve54706 grieve54706 merged commit 7fb7dfd into Canner:main Dec 16, 2024
15 checks passed
@goldmedal goldmedal deleted the bugfix/fix-distinct-agg branch December 16, 2024 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core rust Pull requests that update Rust code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants