perf: canonical H2O q6/q7/q9/q10 — 4 bypass operators (median+std, max+min, pearson, sum+count)#204
Merged
Merged
Conversation
Dedicated single-pass operator for canonical shape (select (pearson_corr x y) from t by [k0] or [k0 k1]) with no other aggs/non-aggs/where. Bypasses shared radix HT path (slowed 3-4× after Anton's master merge) via private morsel-scatter + per-partition open-addressing HT with fixed Pearson state. Mirrors OP_GROUP_TOPK_ROWFORM (q8). q9 (10M rows, 10k groups, 2 keys SYM+I64): 196ms->67ms. Beats DuckDB (77ms) by 13%.
3 tasks
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
Four dedicated row-form operators that bypass the shared
OP_GROUPradix HT path for canonical H2O groupby shapes. Closes the remaining slow queries from PR #203 (which seededOP_MEDIAN,OP_PEARSON_CORR,OP_TOP_N,OP_GROUP_TOPK_ROWFORM) by giving each its own specialized executor — smaller entries, no agg_strlen/rowsel/holistic-fill defensive paths, no direct-array eligibility scans that always fail for these shapes.median(v3), std(v3) by id4, id5max(v1), min(v2) by id3pearson(v1, v2)² by id2, id4sum(v3), count(v1) by id1..id6Per-operator design
OP_GROUP_PEARSON_ROWFORM(q9)1-2 keys, fixed Pearson state
{Σx, Σy, Σx², Σy², Σxy, cnt}(6 doubles + cnt) per group accumulated in Phase 1's scatter+fold. Phase 3 emits keys + r² in one pass.OP_GROUP_MAXMIN_ROWFORM(q7)1 key, fixed-state
{max_x, min_y, cnt}. Closes q7's first stage (max(v1)−min(v2) by id3); the subtraction runs as element-wise arithmetic on the small group result.OP_GROUP_MEDIAN_STDDEV_ROWFORM(q6)2 keys, two-pass per-partition Phase 2:
{cnt, sum, sumsq}per group.v3into the partition's group-contiguousv_buf(sequential writes within partition slice, no cross-partition scatter).ray_median_dbl_inplaceper group on its slice + emits stddev.Replaces the shared path's reprobe+histogram+scatter holistic fill (which sequentially re-hashes 10M rows under
match_idx==NULL).OP_GROUP_SUM_COUNT_ROWFORM(q10)Variadic N keys (3..8), VLA entry stride =
16 + 8Nbytes. For q10's 6-key composite where ~every row creates its own group, HT is pre-sized to 2× partition entry count (load 0.5). Skips: direct-array eligibility scans (always fail for this composite), rowsel branches, nullable defensive checks, holistic scaffolding.Files
src/ops/group.c(+2225) — 4 specialized executors with per-op helper prefixes (`grpc_`/`grpmm_`/`grpms_`/`grpsc_`)src/ops/ops.h(+51),src/ops/exec.c(+12),src/ops/graph.c(+181),src/ops/dump.c(+4),src/ops/internal.h(+4) — opcode/builder/dispatch/dump wiringsrc/ops/query.c(+213) — planner gates (mm_ok/ms_ok/sc_ok)Related
Test plan
make release -j8clean (no warnings, -Werror enabled)make test -j8→ 2417/2418 pass (1 skipped pre-existing)make check LOCAL=1→ pass — 665/665 comparisons matched polars, 0 NYI🤖 Generated with Claude Code