Skip to content

Pushdown DISTINCT agg fields as (additional) GROUP BY keys #24

Open
@kaikalur

Description

@kaikalur

DISTINCT aggs like COUNT DISTINCT are expensive. But in most cases it is helpful to push down these as group by keys before counting them.

SELECT agg(x), COUNT(DISTINCT y) FROM T GROUP BY z;

can be rewritten as

SELECT agg(x), COUNT(DISTINCT y) FROM (SELECT partial_agg(x) AS x, y, z FROM T GROUP BY y, z) AS T GROUP BY z;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions