Skip to content

perf(query): extend count-distinct 2-stage rewrite to multi-key by-dict#225

Open
ser-vasilich wants to merge 1 commit into
masterfrom
perf/count-distinct-multi-key
Open

perf(query): extend count-distinct 2-stage rewrite to multi-key by-dict#225
ser-vasilich wants to merge 1 commit into
masterfrom
perf/count-distinct-multi-key

Conversation

@ser-vasilich
Copy link
Copy Markdown
Collaborator

Summary

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 (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 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant