Skip to content

[Tech Request]: Optimize aggregate functions with distinct keyword #9049

Closed as not planned

Description

@aunjgr

Is there an existing issue for the same feature request?

  • I have checked the existing issues.

Is your feature request related to a problem?

Current implementation of distinct aggregate is using hash-table in hash-table.It's inefficient, in both memory and performance.

On my desktop machine with 32GB memory, TPCH SF=100 q16 causes OOM due to this bad implementation.

Describe the feature you'd like

In plan, we should rewrite AGG nodes which have distinct aggregate function with multiple AGG nodes.

  • max/min/any_value (just omit DISTINCT keyword)
  • count/sum
  • avg
  • distinct aggregate coexists with normal aggregates
  • multiple distinct aggregates

Describe implementation you've considered

No response

Documentation, Adoption, Use Case, Migration Strategy

No response

Additional information

No response

Activity

  1. added this to the Backlog milestone on Apr 18, 2023
  2. self-assigned this
    on Apr 18, 2023
  3. changed the title [-][Feature Request]: [/-] [+][Feature Request]: Optimze aggregate functions with distinct keyword[/+] on Apr 18, 2023
  4. changed the title [-][Feature Request]: Optimze aggregate functions with distinct keyword[/-] [+][Feature Request]: Optimize aggregate functions with distinct keyword[/+] on Apr 18, 2023
  5. added
    source/dev
    on Aug 27, 2023
  6. added
    priority/p0
    kind/tech-request
    and removed on Nov 8, 2023
  7. changed the title [-][Feature Request]: Optimize aggregate functions with distinct keyword[/-] [+][Tech Request]: Optimize aggregate functions with distinct keyword[/+] on Nov 8, 2023
  8. added theissue type on Apr 24, 2025
  9. modified the milestones: Backlog, 2506 on Apr 24, 2025
  10. modified the milestones: MO-2506, MO-2508 on Jul 17, 2025
  11. modified the milestones: MO-2508, MO-202603 on Feb 3, 2026
  12. added
    severity/s0
    on Sep 10, 2026
  13. XuPeng-SH commented on Oct 22, 2026

    @XuPeng-SH
    Contributor

    Superseded by #30768, assigned to @matrix-meow, for the remaining mixed/multiple DISTINCT aggregation optimization.

    Inspected main c232b6d2a1b5a94ac624c4954586569841c1e153: standalone AVG(DISTINCT) is now rewritten (#28644), alongside the existing single COUNT/SUM rewrite; mixed COUNT DISTINCT parallelism (#27693) and bounded exact COUNT spill (#28003) have also landed. The old checklist therefore understates completed work.

    The general rewrite still requires one aggregate expression. Mixed and multiple DISTINCT aggregate optimization remains explicit in #30768; adaptive exact-key partition parallelism continues under #27720, and window DISTINCT is separate (#29934).

    Closing this historical umbrella as superseded, not as proof that all original requirements are implemented. The original TPCH SF=100 Q16 / 32GB OOM scenario was not rerun and is not claimed resolved by this status migration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/tech-requestpriority/p0severity/s0source/dev

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions