Skip to content

Optimize quadratic DISTINCT aggregate capacity preflight #27687

Closed

Description

@XuPeng-SH

Problem

The allocation-capacity preflight for saved DISTINCT aggregate arguments detects duplicates within each hashmap work unit by scanning every earlier row. With B rows per work unit, this is O(B²), even when all values are unique.

This affects exact DISTINCT aggregate implementations that retain arguments for merge/spill. It is independent of any specific SQL shape, although high-cardinality mixed aggregation makes it visible.

Evidence

A focused benchmark ingesting 65,536 unique INT64 values into one COUNT(DISTINCT) group takes about 200–203 ms on the current implementation. CPU profiling attributes time to the preflight back-scan in addition to the resident skiplist probes.

Expected behavior

Deduplicate candidates within the bounded 256-row work unit in expected O(B) time, with:

  • exact collision verification;
  • no row-frequency allocation;
  • unchanged NULL, const-vector, logical-offset, multi-column, and floating signed-zero semantics;
  • unchanged allocation admission and publication atomicity.

Related performance investigation: #27672.

Activity

  1. self-assigned this
    on Aug 26, 2026
  2. added
    severity/s0
    on Aug 26, 2026
  3. added a commit that references this issue on Aug 26, 2026
    a5eb8b6
  4. added 3 commits that reference this issue on Sep 17, 2026
    77536ec
    975953c
    50049c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/enhancementseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions