Skip to content

perf: discard short inline DISTINCT prefixes without allocating - #27990

Draft
QinXi-ai wants to merge 3 commits into
apache:mainfrom
QinXi-ai:perf/27299-discard-inline-prefix
Draft

QinXi-ai wants to merge 3 commits into
apache:mainfrom
QinXi-ai:perf/27299-discard-inline-prefix

Conversation

@QinXi-ai

@QinXi-ai QinXi-ai commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Stacked on #27299. The follow-up commit addresses the partial-emission review suggestion.

Rationale for this change

When the grouped integer COUNT(DISTINCT) accumulator emits a prefix, it returns the counts and discards the corresponding inline first values. For a short prefix, take_needed allocates a vector for values that are immediately dropped.

What changes are included in this PR?

Drain the inline prefix in place when it contains at most half of the groups. For a larger prefix, keep the smaller tail with split_off so the old allocation can be released.

What is the testing strategy for this PR?

partial_evaluation_keeps_first_values_aligned exercises a partial emission followed by updates to the remaining groups. The 10 aggregate::count_distinct unit tests passed. A local allocation counter around evaluate(EmitTo::First(256)) on 65,536 singleton Int64 groups measured 4 allocation calls and 4,264 bytes on the parent commit, and 3 calls and 2,216 bytes on this commit. Emitting 60,000 groups took 4 allocations on both versions and retained the same capacity. Both runs checked the emitted and remaining counts.

Are there any user-facing changes?

No SQL or output changes.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant