Skip to content

DISTINCT fails without columns in the replace_distinct_aggregate rule #18132

@Tpt

Description

@Tpt

Describe the bug

DISTINCT on an input without columns should not be rewritten to a GROUP BY that requires at least one group but into a LIMIT 1

To Reproduce

On queries like SELECT DISTINCT * FROM empty where empty is a table without columns, the replace_distinct_aggregate optimization fails with Error: Unexpected(Context("Optimizer rule 'replace_distinct_aggregate' failed", Plan("Aggregate requires at least one grouping or aggregate expression. Aggregate without grouping expressions nor aggregate expressions is logically equivalent to, but less efficient than, VALUES producing single row. Please use VALUES instead. because it tries to generate an empty aggregate.

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions