Skip to content

COUNT(DISTINCT <primitive>) misses a null-free fast path in its update loop #23955

Description

@viirya

Is your feature request related to a problem or challenge?

PrimitiveDistinctCountAccumulator::update_batch inserts values with a per-element Option check (if let Some(value) = value) on every row, even when the input array has no nulls. This is the hot path for COUNT(DISTINCT <int/date/time/decimal>).

The same accumulator's merge_batch already inserts wholesale from the values buffer (self.values.extend(list.values())), so the fast path is available — it's just not applied on the update path.

Describe the solution you'd like

When array.null_count() == 0, insert directly from the values buffer, skipping the per-element validity branch — mirroring merge_batch and the null-free fast paths recently added to percentile_cont/median in #23954. Measured ~66% faster on the null-free count_distinct benchmark.

Activity

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

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