Repository navigation
perf(executor): hash equi-join, KMV merge by sorted union, group-table entry cache - #1569
Merged
Merged
Conversation
…ry up once per batch A relational join evaluated its predicate on every (left, right) pair. A predicate that is a conjunction of SQL equalities between a left and a right column of one key type (text, integer, timestamp, date, bool) now finds each left row's matches through a hash index of the right rows; the matches and their order are the nested loop's. Example: SELECT node, avg(value) FROM cpu ... GROUP BY node, planned as sum view JOIN count view on node, joined 100k x 100k pairs per evaluation (~144 s at x10); it is now linear. GroupTable kept its dictionary-entry cache per call, and a summary build folds its input in 1024-row slices, so every slice looked its dictionary entries up again (one text hash per row). The cache now lives in the column's parts and is reused while the dictionary is the same array. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kmv::merge inserts each hash of the other sketch through update_with_hash, which scans the retained hashes for a duplicate: O(k^2) per merge. A query merging 60 windows of KMV states for 5000 groups (count(DISTINCT value) ... GROUP BY service over 10 minutes at x10) spent ~110 s there. The merge now sorts both retained sets once and keeps the k smallest distinct hashes, the same set the library's merge keeps (test). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
SELECT node, avg(value) FROM cpu … GROUP BY nodeis planned as a sum view JOINed with a count view onnode. The relational join was a nested loop over 100k × 100k pairs: about 144 s per evaluation. A KMV merge scanned the retained hashes for a duplicate on every inserted hash,O(k²)per merge.count(DISTINCT value) … GROUP BY serviceover 10 minutes (60 windows × 5,000 services) took about 112 s. The group table re-hashed the dictionary texts in every 1024-row slice of a batch.Review guide
eval/2026-12-planner39a25ee (eval build 3). Two commits; the backend draft PR pins this branch.crates/executor/src/operators/joins/mod.rs:relational_join(newequibranch),equi_join_keys,EquiIndex,emit_matches. These need careful review: null handling, which key types are accepted, output order.crates/executor/src/summary_kernels/kmv.rsunion_of, andcrates/executor/src/operators/group_table.rsColumnParts::entry_parts.emit_matches.Behavior: before → after
The query
OU_avg_node_1h: SELECT node, avg(value) AS v FROM cpu WHERE ts > $now - INTERVAL '1 hour' GROUP BY noderuns at x10 (100k nodes). The data plane executes it asJoin(Inner, node = node)overFinalizeExactAccumulator(sum view by node)andFinalizeExactAccumulator(count view by node).Same for
H_traces_per_service_10m(KMV merge of 60 windows × 5,000 services): 112 s → 20-23 s.Interfaces
None. All changes are private functions; no type, field, flag or format changes.
Algorithm changes
Hash equi-join (
joins::relational_join)|L|·|R|pairs; 100k × 100k took ~144 s.equi_join_keysaccepts a predicate that isCompare{Column a, Eq, Column b, Sql}, or a non-emptyBoolAndof such comparisons, where each comparison has one column on each side and both columns have the same type among Utf8/Int64/Timestamp/Date/Bool.EquiIndexhashes each right row's key tuple (Value::keybytes, each length-prefixed) to its right rows in ascending order. A left row's matches are the rows listed under its key. A NULL in any key column matches nothing. Any other predicate, andCross, keeps the nested loop.=is equality ofValue::key, and NULL = anything is not true. So a pair matches under the index exactly when the predicate is true. Matches are emitted through the sameemit_matchesin ascending right-row order, so outer, semi and anti rows come out in the nested loop's order. Floats are excluded (-0.0 = 0.0, NaN). Testequi_join_matches_the_nested_loop_row_for_rowcompares all six join kinds row for row against the forced nested loop, with duplicate keys and NULLs on both sides and a reversed equality.O(|L|·|R|)→O(|L| + |R| + output)time;O(|R|)extra memory for the index.KMV merge (
kmv::union_of)Kmv::mergepushes each hash throughupdate_with_hash, which scans the retained hashes linearly for a duplicate:O(k²).ksmallest, and push them largest first into a new heap.ksmallest distinct hashes of the union, so the estimate is identical. Testmerge_keeps_the_library_merges_hasheschecks this below, at and abovekagainst the library's merge.O(k²)→O(k log k)per merge.Dictionary-entry cache (
GroupTable::column_parts)row_chunks). The entry → part cache was per call, so each slice hashed its entries' texts again: about one text hash per row.ColumnParts::entry_parts) keeps the dictionary values array (anArc, so its address identifies it) and one part per entry, and is reused while batches share that dictionary.Decisions and open questions
None.
Verification
cargo test -p asap-executor --lib --test executor(release)GLEN=130)equi_join_matches_the_nested_loop_row_for_row: the hash path returns the nested loop's rows in its order for every join kind, with duplicates and NULLs.merge_keeps_the_library_merges_hashes: the sorted-union KMV merge keeps the library merge's hashes and estimate.Follow-ups
SE_anomalous(sum(CASE WHEN ts > now()-10m …)/count(*)over 1 h) is planned as a query-time raw scan: 360M rows at x10 with 1 h of history (54 s with 10 minutes of history). Planner capability gap: split it into a 10-minute count and a 1 h count.OB_fast_5m/OF_q2(~30 s): the boundservice IN $Xfilter is applied afterSummaryMergeof all groups. Pushing it below the merge would merge only the bound groups.🤖 Generated with Claude Code