perf(query): extend count-distinct 2-stage rewrite to SYM keys#222
Open
ser-vasilich wants to merge 1 commit into
Open
perf(query): extend count-distinct 2-stage rewrite to SYM keys#222ser-vasilich wants to merge 1 commit into
ser-vasilich wants to merge 1 commit into
Conversation
The (count distinct X) by K planner rewrite previously rejected SYM
columns for K and X. mk_compile's composite key path already packs
SYM by its storage width, and the outer pass materialises the key
column as SYM when K was SYM — the gate was conservatively narrow,
not algorithmically required.
Also apply asc:/desc:/take: on the rewrite's output. Without this
the emit_filter trims to top-N but leaves rows in HT-iteration
order, silently dropping the user's desc: ordering. Calling
apply_sort_take at return time matches the SQL ORDER BY semantics
that every other ray_select path applies.
ClickBench 10M:
q08 173 → 78 ms (already covered by Anton's original 2-stage;
now also sorted descending by count)
q10 163 → 72 ms
q13 551 → 198 ms
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
(count distinct X) by Kplanner rewrite (706c5be) currentlyshort-circuits when either
KorXis a SYM column.mk_compile'scomposite key path already packs SYM by storage width, and the outer
pass materialises the key column as SYM when
Kwas SYM — the gatewas conservatively narrow.
Drop the SYM bailout, and additionally apply asc/desc/take from the
outer query to the rewrite's output so it composes with sort+take.
ClickBench 10M:
q08 ~390 → ~74 ms
q10 ~170 → ~10 ms
q13 ~615 → ~160 ms