perf(query): narrow + materialize before group for WHERE + multi-key#228
Merged
Conversation
The pre-filter narrowing path in ray_select_fn previously fired only
when the by-dict contained a *computed* val (e.g. q42's
(xbar EventTime ...)). For bare-ref multi-key shapes with a
selective WHERE — e.g. ClickBench q30 / q31:
(select {c: (count ClientIP)
s: (sum IsRefresh)
a: (avg ResolutionWidth)
from: hits where: (!= SearchPhrase "")
by: {SearchEngineID: SearchEngineID ClientIP: ClientIP}
desc: c take: 10})
the planner left the work to the fused mk_par_v2 path. That path
reads each by-key + agg input column from the *original* wide table
at the sparse positions left by the WHERE bitmap. On hits — 100+
columns — and ~14% selectivity, the gather wastes a cache line per
touched column per passing row. Narrowing the input down to just
the referenced columns and filtering once gives the downstream group
a dense column-store and skips the gather.
Extend the gate to fire when:
- the desc/asc COUNT take N shape matches,
- by-vals are all bare column refs (no computed val),
- the by-dict has ≥ 2 keys, and
- at least one aggregate has an input column distinct from the
by-keys (sum/min/max/avg, not pure count).
Count-only shapes (q14: count of SearchPhrase by
{SearchEngineID, SearchPhrase}; q40: count URLHash by
{URLHash, EventDate}) reuse the by-key column for the count input
— narrowing costs the projection without saving the gather, so the
gate keeps them on the original fused path.
ClickBench 10M:
q30 ~152 → ~50 ms
q31 ~353 → ~55 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
The pre-filter narrowing path in
ray_select_fnpreviously fired onlywhen the by-dict contained a computed val (e.g. q42's
(xbar EventTime ...)). For bare-ref multi-key shapes with aselective WHERE — e.g. ClickBench q30 / q31 — the planner left the
work to the fused
mk_par_v2path. That path reads each by-key + agginput column from the original wide table at the sparse positions
left by the WHERE bitmap. On the 100-column
hitstable with ~14%selectivity, the gather wastes a cache line per touched column per
passing row.
Narrowing the input down to just the referenced columns and filtering
once gives the downstream group a dense column-store and skips the
gather.
Extend the gate to fire when:
desc:/asc: COUNT take Nshape matches,by-keys (sum / min / max / avg, not pure count).
The count-only-on-a-by-key shapes (q14:
count SearchPhraseby{SearchEngineID, SearchPhrase}; q40:count URLHashby{URLHash, EventDate}) reuse the by-key column for the count input— narrowing costs the projection without saving the gather, so the
gate keeps them on the original fused path.
ClickBench 10M (on top of the gate from #227):
Full 43-query sum (with #227 already in):
-394 ms / -11.3%.Tests: 3232/3234 pass (unchanged).