Skip to content

perf: canonical H2O q6/q7/q9/q10 — 4 bypass operators (median+std, max+min, pearson, sum+count)#204

Merged
singaraiona merged 4 commits into
masterfrom
perf/op-group-pearson-rowform
May 17, 2026
Merged

perf: canonical H2O q6/q7/q9/q10 — 4 bypass operators (median+std, max+min, pearson, sum+count)#204
singaraiona merged 4 commits into
masterfrom
perf/op-group-pearson-rowform

Conversation

@ser-vasilich
Copy link
Copy Markdown
Collaborator

Summary

Four dedicated row-form operators that bypass the shared OP_GROUP radix HT path for canonical H2O groupby shapes. Closes the remaining slow queries from PR #203 (which seeded OP_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.

query shape rayforce (was → now) duckdb
q6 median(v3), std(v3) by id4, id5 265 → 75 ms 188 ms
q7 max(v1), min(v2) by id3 155 → 58 ms 105 ms
q9 pearson(v1, v2)² by id2, id4 196 → 66 ms 78 ms
q10 sum(v3), count(v1) by id1..id6 470 → 165 ms 390 ms

Per-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:

  1. Probe HT, accumulate {cnt, sum, sumsq} per group.
  2. Cumsum cnt → per-group offsets; re-walk entries and scatter v3 into the partition's group-contiguous v_buf (sequential writes within partition slice, no cross-partition scatter).
  3. Phase 3 runs ray_median_dbl_inplace per 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 + 8N bytes. 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 wiring
  • src/ops/query.c (+213) — planner gates (mm_ok/ms_ok/sc_ok)

Related

Test plan

  • make release -j8 clean (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
  • Bench (10M rows, k=100): q6/q7/q9/q10 all stable at new numbers across 3 consecutive runs

🤖 Generated with Claude Code

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%.
@singaraiona singaraiona merged commit ad8be5a into master May 17, 2026
4 checks passed
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.

2 participants