Skip to content

SingleDistinctToGroupBy being applied too broadly #4082

@andygrove

Description

@andygrove

Describe the bug
The intent of SingleDistinctToGroupBy is to rewrite queries that have multiple references to the same distinct expression, such as SELECT F1(DISTINCT s),F2(DISTINCT s) to avoid evaluating the distinct multiple times.

However, it is currently applied even if there is only a single distinct value, adding unnecessary complexity to simple queries,

To Reproduce
Only apply the rule when it is needed.

Expected behavior

Additional context
benchmark q16 is a good example of where it is applied but not needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingoptimizerOptimizer rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions