perf(query): extend count-distinct 2-stage rewrite to multi-key by-dict#225
Open
ser-vasilich wants to merge 1 commit into
Open
perf(query): extend count-distinct 2-stage rewrite to multi-key by-dict#225ser-vasilich wants to merge 1 commit into
ser-vasilich wants to merge 1 commit into
Conversation
try_count_distinct_v2_rewrite previously fired only when `by:` was a
single bare symbol; the multi-key `by: {K1: K1 K2: K2 ...}` dict form
fell through to the slow per-group exec_count_distinct path. The
mk_compile composite key path already handles the (K1, K2, ..., X)
packing — the gate was conservatively narrow.
Collect K_syms[] from either bare-sym or RAY_DICT by_expr, verify
each K column's type and that the total composite (sum of K
widths + X width) fits the 16-byte mk_compile budget, then build
the inner GROUP BY (K1...Kn, X) and outer GROUP BY (K1...Kn) → count
the same way as the single-key path.
The identity-projection check is widened to accept any column ref
that matches any K column.
ClickBench 10M q11 (`COUNT(DISTINCT UserID) GROUP BY MobilePhone,
MobilePhoneModel`):
q11 ~162 → ~8 ms
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
try_count_distinct_v2_rewritepreviously fired only whenby:was asingle bare symbol; the multi-key
by: {K1: K1 K2: K2 ...}dict formfell through to the slow per-group
exec_count_distinctpath. Themk_compilecomposite-key path already handles(K1, K2, ..., X)packing — the gate was conservatively narrow.
Collect
K_syms[]from either bare-sym orRAY_DICTby_expr,verify each K column's type and that the total composite (sum of K
widths + X width) fits the 16-byte budget, then build the inner
GROUP BY (K1...Kn, X)and outerGROUP BY (K1...Kn)→ count thesame way as the single-key path.
The identity-projection check is widened to accept any column ref
that matches any K column.
ClickBench 10M q11 (
COUNT(DISTINCT UserID) GROUP BY MobilePhone, MobilePhoneModel):