Repository navigation
Add ColumnsScatter::scatter: batched column split with type-index dispatch and bytes-budget input buffering - #106120
harikrishnan94 wants to merge 13 commits into
Conversation
|
Workflow [PR], commit [8445bd9] Summary: ❌
AI ReviewSummaryThis PR adds the batched PR Metadata
Findings
Tests
Final Verdict
|
2d5170d to
e817438
Compare
|
@harikrishnan94, pls fix the style check and merge conflicts to unblock the CI. |
… containers Address the `Style check` `cpp` failures reported on PR ClickHouse#106120: - Remove unnecessary `} // namespace ...` closing comments in `ColumnsScatter.h/.cpp`, `HashCombine32.h`, `MapToRange.h/.cpp`, and the new hash benchmark/test files. - Remove the unused `ErrorCodes::BAD_ARGUMENTS` declaration in `BufferedShardByHashTransform.cpp`. - Mark the short-lived scratch `std::vector` buffers in `ColumnsScatter.cpp` and `ColumnVariant.cpp` with `STYLE_CHECK_ALLOW_STD_CONTAINERS`. - Restore Allman braces for `vectorIndexImpl` in `ColumnVector.cpp`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106120&sha=e8174388e1cdd81267ffb45d4750e6ffa0157466&name_0=PR&name_1=Style%20check Co-authored-by: Cursor <[email protected]>
3776293 to
e82a26e
Compare
|
@nickitat - pushed fixes for all four blockers from ; ready for another look. |
… containers Address the `Style check` `cpp` failures reported on PR ClickHouse#106120: - Remove unnecessary `} // namespace ...` closing comments in `ColumnsScatter.h/.cpp`, `HashCombine32.h`, `MapToRange.h/.cpp`, and the new hash benchmark/test files. - Remove the unused `ErrorCodes::BAD_ARGUMENTS` declaration in `BufferedShardByHashTransform.cpp`. - Mark the short-lived scratch `std::vector` buffers in `ColumnsScatter.cpp` and `ColumnVariant.cpp` with `STYLE_CHECK_ALLOW_STD_CONTAINERS`. - Restore Allman braces for `vectorIndexImpl` in `ColumnVector.cpp`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106120&sha=e8174388e1cdd81267ffb45d4750e6ffa0157466&name_0=PR&name_1=Style%20check Co-authored-by: Cursor <[email protected]>
|
📊 Cloud Performance Report 🟢 AI verdict: 4 improved query(s). K_source=6 K_base=30 flagged=4/65 clickbench🟢 2 improved Flagged queries (2 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 2 improved Flagged queries (2 of 22)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a new batched scatter primitive (DB::ColumnsScatter::scatter) and wires it into hash-based sharding paths to reduce per-chunk allocation overhead. It also replaces the legacy WeakHash32/getWeakHash32 API with a non-allocating IColumn::computeHashInto kernel and adds a byte-budget input batching setting (shard_by_hash_input_batch_bytes) for sharded aggregation.
Changes:
- Add
DB::ColumnsScatter::scatterwith O(1) type-index dispatch plus row-count precomputation, and integrate it intoBufferedShardByHashTransformandScatterByPartitionTransform. - Replace
WeakHash32withIColumn::computeHashIntoacross column implementations and update hash consumers (JoinUtils, transforms). - Add unit/stateless tests and new microbenchmarks for
computeHashIntoandColumnsScatter::scatter; addmapToRange()helper.
Reviewed changes
Copilot reviewed 74 out of 74 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04317_sharded_aggregation_batched_input.sql | New stateless test comparing batched vs per-chunk sharded aggregation results across key types. |
| tests/queries/0_stateless/04317_sharded_aggregation_batched_input.reference | Expected output for batched sharded aggregation stateless test. |
| tests/queries/0_stateless/04316_fix_scatter_buffer_reuse_window.sql | Regression test for hash-buffer reinit across blocks in window partition scattering. |
| tests/queries/0_stateless/04316_fix_scatter_buffer_reuse_window.reference | Expected output for scatter buffer reuse regression test. |
| tests/queries/0_stateless/04312_grace_hash_vs_hash_join_key_types.sql | New stateless test ensuring grace_hash join matches hash join across key families. |
| tests/queries/0_stateless/04312_grace_hash_vs_hash_join_key_types.reference | Expected output for grace-hash vs hash join stateless test. |
| src/Processors/Transforms/ScatterByPartitionTransform.h | Switch transform state from WeakHash32 to reusable POD hash/pids buffers. |
| src/Processors/Transforms/ScatterByPartitionTransform.cpp | Use computeHashInto + mapToRange + ColumnsScatter::scatter for partition scattering. |
| src/Processors/Transforms/BufferedShardByHashTransform.h | Add byte-budget batching state and reusable buffers for batched scattering. |
| src/Processors/Transforms/BufferedShardByHashTransform.cpp | Implement chunk accumulation + batched flush using ColumnsScatter::scatter; add MAX_PENDING_BLOCKS cap. |
| src/Processors/QueryPlan/BuildQueryPipelineSettings.h | Plumb new shard_by_hash_input_batch_bytes setting into pipeline settings. |
| src/Processors/QueryPlan/BuildQueryPipelineSettings.cpp | Initialize shard_by_hash_input_batch_bytes from query settings. |
| src/Processors/QueryPlan/AggregatingStep.cpp | Pass the new batch-bytes setting into BufferedShardByHashTransform. |
| src/Interpreters/JoinUtils.h | Update hashToSelector helper to accept raw UInt32 hashes buffer. |
| src/Interpreters/JoinUtils.cpp | Compute routing hashes via computeHashInto (no WeakHash32). |
| src/Core/SettingsChangesHistory.cpp | Register compatibility history entry for the new batching setting default. |
| src/Core/Settings.cpp | Add the shard_by_hash_input_batch_bytes setting and documentation. |
| src/Common/WeakHash.h | Remove legacy WeakHash32 interface (superseded by computeHashInto). |
| src/Common/WeakHash.cpp | Remove legacy WeakHash32 implementation. |
| src/Common/MapToRange.h | Add mapToRange() helper declarations for Lemire multiply-and-shift mapping. |
| src/Common/MapToRange.cpp | Add multiversioned implementations of mapToRange() for selector/pids generation. |
| src/Common/HashTable/Hash.h | Introduce WEAK_HASH32_INITIAL_VALUE and combineWeakHash32() combiner. |
| src/Columns/tests/gtest_weak_hash_32.cpp | Remove obsolete WeakHash32 unit tests. |
| src/Columns/tests/gtest_compute_hash_into.cpp | Add comprehensive tests for computeHashInto semantics and invariants. |
| src/Columns/tests/gtest_columns_scatter.cpp | Add extensive equivalence and representation-mixing tests for ColumnsScatter::scatter. |
| src/Columns/IColumnUnique.h | Update unsupported hashing API to throw on computeHashInto instead of getWeakHash32. |
| src/Columns/IColumnDummy.h | Implement computeHashInto for dummy columns using the canonical initializer/combiner. |
| src/Columns/IColumn.h | Replace getWeakHash32() with computeHashInto() API and document invariants. |
| src/Columns/ColumnVector.h | Switch ColumnVector to implement computeHashInto. |
| src/Columns/ColumnVector.cpp | Implement non-allocating per-row hashing for vectors (incl. BFloat16 raw-bit hashing). |
| src/Columns/ColumnVariant.h | Switch ColumnVariant to implement computeHashInto. |
| src/Columns/ColumnVariant.cpp | Implement computeHashInto for variants by hashing alternatives and gathering by discriminator. |
| src/Columns/ColumnTuple.h | Switch ColumnTuple to implement computeHashInto. |
| src/Columns/ColumnTuple.cpp | Implement tuple hashing with scratch buffer on non-initial path for representation-independence. |
| src/Columns/ColumnString.h | Switch ColumnString to implement computeHashInto. |
| src/Columns/ColumnString.cpp | Implement per-row string hashing via updateWeakHash32 and canonical combiner. |
| src/Columns/ColumnSparse.h | Switch ColumnSparse to implement computeHashInto. |
| src/Columns/ColumnSparse.cpp | Implement sparse hashing by hashing value dictionary then gathering per-row. |
| src/Columns/ColumnReplicated.h | Switch ColumnReplicated to implement computeHashInto. |
| src/Columns/ColumnReplicated.cpp | Implement replicated hashing by hashing nested then gathering via index column. |
| src/Columns/ColumnQBit.h | Delegate hashing to tuple via computeHashInto. |
| src/Columns/ColumnObject.h | Switch ColumnObject to implement computeHashInto. |
| src/Columns/ColumnObject.cpp | Implement object hashing by chaining typed/dynamic/shared subcolumns with scratch on non-initial path. |
| src/Columns/ColumnNullable.h | Switch ColumnNullable to implement computeHashInto. |
| src/Columns/ColumnNullable.cpp | Implement nullable hashing with NULL payload independence and canonical combiner. |
| src/Columns/ColumnMap.h | Switch ColumnMap to implement computeHashInto. |
| src/Columns/ColumnMap.cpp | Delegate map hashing to nested array storage via computeHashInto. |
| src/Columns/ColumnLowCardinality.h | Switch ColumnLowCardinality to implement computeHashInto. |
| src/Columns/ColumnLowCardinality.cpp | Implement LC hashing by hashing dictionary then gathering by indexes. |
| src/Columns/ColumnLazy.h | Switch ColumnLazy to reject hashing via computeHashInto. |
| src/Columns/ColumnLazy.cpp | Update exception path to the new hashing API name. |
| src/Columns/ColumnIndex.h | Replace getWeakHash() with computeHashInto() gather helper. |
| src/Columns/ColumnIndex.cpp | Implement index-gather hashing with optional combine semantics. |
| src/Columns/ColumnFunction.h | Switch ColumnFunction to implement computeHashInto. |
| src/Columns/ColumnFunction.cpp | Implement function-column hashing with scratch on non-initial path. |
| src/Columns/ColumnFixedString.h | Switch ColumnFixedString to implement computeHashInto. |
| src/Columns/ColumnFixedString.cpp | Implement fixed-string hashing via updateWeakHash32 and canonical combiner. |
| src/Columns/ColumnDynamic.h | Delegate hashing to the internal variant via computeHashInto. |
| src/Columns/ColumnDecimal.h | Switch ColumnDecimal to implement computeHashInto. |
| src/Columns/ColumnDecimal.cpp | Implement per-row decimal hashing using native storage and canonical combiner. |
| src/Columns/ColumnConst.h | Switch ColumnConst to implement computeHashInto. |
| src/Columns/ColumnConst.cpp | Implement const hashing by hashing one element then broadcasting/combining. |
| src/Columns/ColumnCompressed.h | Update unsupported hashing API to computeHashInto. |
| src/Columns/ColumnBLOB.h | Update unsupported hashing API to computeHashInto. |
| src/Columns/ColumnArray.h | Switch ColumnArray to implement computeHashInto. |
| src/Columns/ColumnArray.cpp | Implement range-aware array hashing using element-hash scratch buffer and canonical combiner. |
| src/Columns/ColumnAggregateFunction.h | Switch ColumnAggregateFunction to implement computeHashInto. |
| src/Columns/ColumnAggregateFunction.cpp | Implement agg-state hashing by serializing state per row and hashing bytes. |
| src/Columns/ColumnsScatter.h | Add new batched scatter API and row-count helper declarations. |
| src/Columns/ColumnsScatter.cpp | Implement batched scatter with dispatch table, fast paths, wrapper normalization, and fallback normalization. |
| src/Columns/benchmarks/CMakeLists.txt | Add benchmark executables for computeHashInto and ColumnsScatter::scatter. |
| src/Columns/benchmarks/benchmark_compute_hash_into.cpp | Add microbenchmarks for hashing and end-to-end hash→selector pipeline. |
| src/Columns/benchmarks/benchmark_columns_scatter.cpp | Add microbenchmarks comparing legacy scatter vs batched scatter. |
| src/Columns/benchmarks/benchmark_column_insert_many_from.cpp | Minor change to float value generation (avoid redundant multiply). |
…tter Address review feedback on PR ClickHouse#106120. `ColumnsScatter::scatter`: the all-`ColumnConst` compact path serialized the nested value unconditionally to byte-compare the sources. For a single source that is wasted work, and for a const wrapping a non-serializable column (e.g. `ColumnConst(ColumnFunction)`) it threw `NOT_IMPLEMENTED` where the legacy `ColumnConst::scatter` merely cloned. Short-circuit the single-source case to per-shard `cloneResized` without serializing, and skip the byte-exact comparison for non-serializable (`Function`) multi-source batches so they fall through to the materializing dispatch instead of throwing. Add gtests covering single- and multi-source `ColumnConst(ColumnFunction)`. `04317_sharded_aggregation_batched_input`: the forced-batch cases only aggregated `count`, so no non-key payload column passed through the scatter. Add a case aggregating a distinct-per-row non-key column (`sum`, `max`, sorted `groupArray`) so a payload mis-scatter that keeps keys aligned but misroutes the payload is caught. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Collapse the three near-duplicate "normalize transparent wrappers" helpers (`materializeTransparentWrappers`, `materializeWrappers`, `deepNormalizeForFallback`) into a single recursive `normalizeRepresentation` applied once per source at the `scatter` boundary. After that pass no `ColumnConst`/`ColumnSparse`/`ColumnReplicated` remains at any nesting level (`ColumnLowCardinality` is preserved as a leaf), so `scatterDispatch`, the typed/composite kernels, and `scatterFallback` all assume wrapper-free input. This removes the `scatterDispatch` wrapper guard, the per-subcolumn re-normalization in `scatterNullable`/`scatterTuple`, and the internal normalization in `scatterFallback`. A cheap `probeMayHaveSubcolumns` gate keeps the hot path (plain `ColumnVector`/ `ColumnString` leaves) free of normalization overhead while always recursing for composites whose nested columns a top-level wrapper probe cannot see. The UInt32 per-shard overflow guard stays first — before the all-const compact path, which also sizes shards from UInt32 counts — and now normalizes inline before delegating to `scatterFallback`. No behavior change; ~72 fewer lines in ColumnsScatter.cpp. Add four gtest cases: an all-const heavy-concentration shard-sizing check, a mixed `ColumnConst(Nullable)`/full `Nullable` batch, a `ColumnConst(LowCardinality)`-first type-preservation check, and a sparse-tuple-element-first variant. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Drop the overpromising / micro-architectural claims (eliminating "cold-page TLB flushes", "wall-clock improvement on high-cardinality GROUP BY") from the `shard_by_hash_input_batch_bytes` description and keep the factual account of the batching behavior and the byte-budget rationale. Addresses a PR review comment. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace the hand-written `probeMayHaveSubcolumns` `TypeIndex` switch with a generic `hasSubcolumns` that asks `IColumn::forEachSubcolumn` whether the column exposes any subcolumns. The switch omitted `TypeIndex::QBit`, whose nested `ColumnTuple` can hide a `Sparse`/`Replicated` element and bypass `normalizeRepresentation`, hitting the same mismatched-nested-representation `assert_cast` in `scatterFallback` as the `Array`/`Map`/`Variant` cases. The generic probe covers `QBit` and every current/future composite with no type list to maintain; leaf columns expose no subcolumns and keep the same fast path. Add `FallbackQBitMixedNestedRepresentation` regression: a `QBit` batch mixing a full nested `FixedString` bit-group element with a `ColumnSparse(FixedString)` one. Addresses review comment ClickHouse#106120 (comment) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…mitives # Conflicts: # src/Processors/Transforms/ScatterByPartitionTransform.cpp
The `REGISTER_SWEEP` macro declared a `static const auto cols_...` initialized from `makeUInt64Sources`, but `BM_Legacy_UInt64` and `BM_Batched_UInt64` each rebuild their own sources internally, so this static was never read. It is dead code that wastes startup work (eager `makeUInt64Sources` allocation per sweep entry) and can trip `-Werror=unused-variable` when benchmarks are enabled. Remove it; the registered benchmark bodies are unchanged. Addresses the Copilot review note on `src/Columns/benchmarks/benchmark_columns_scatter.cpp`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 995/1037 (95.95%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 3 line(s) · Uncovered code |
|
Dear @nickitat, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…rg::alter PR ClickHouse#106102 (merged 2026-06-05 17:43 UTC) refactored Iceberg::alter to declare last_version and compression_method outside an if/else that assigns them in both branches. Clang-tidy cppcoreguidelines-init-variables flags the bare declarations and Build (arm_tidy) is built with -warnings-as-errors, so the build fails for every PR whose CI ran on master after this commit. CIDB shows 30+ unrelated PRs hitting this in the last 2 days (e.g. ClickHouse#89360, ClickHouse#103540, ClickHouse#106120, ClickHouse#106386, ClickHouse#106404, ClickHouse#106522, ClickHouse#105102, ClickHouse#106590). Initialize both variables to safe defaults at declaration. They are unconditionally overwritten in both if and else branches before use, so behavior is unchanged. The new defaults are only relevant if a future code path skips both assignments, in which case last_version=0 and compression_method=CompressionMethod::None are sane no-op values (the same defaults the old structured-binding form would produce through default-construction of the destructured aggregate). Co-Authored-By: Claude Opus 4.8 <[email protected]> (cherry picked from commit d72cac5)
…mitives Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. - retargeted PR record [email protected] to 26.10 (settings-history check rule) Also resolved conflicts in: - `src/Columns/benchmarks/CMakeLists.txt` - `src/Processors/QueryPlan/AggregatingStep.cpp` - `src/Processors/QueryPlan/BuildQueryPipelineSettings.cpp` - `src/Processors/Transforms/BufferedShardByHashTransform.cpp` - `src/Processors/Transforms/BufferedShardByHashTransform.h` Master removed the sharded aggregator, so `BufferedShardByHashTransform` is deleted and `AggregatingStep.cpp` follows master; the `shard_by_hash_input_batch_bytes` setting now has no consumer. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| min_outstreams_per_resize_after_split = from->getSettingsRef()[Setting::min_outstreams_per_resize_after_split]; | ||
| max_streams_for_union_step = from->getSettingsRef()[Setting::max_streams_for_union_step]; | ||
| max_streams_for_union_step_to_max_threads_ratio = static_cast<double>(from->getSettingsRef()[Setting::max_streams_for_union_step_to_max_threads_ratio]); | ||
| shard_by_hash_input_batch_bytes = from->getSettingsRef()[Setting::shard_by_hash_input_batch_bytes]; |
There was a problem hiding this comment.
shard_by_hash_input_batch_bytes is now read here and then dropped on the floor: after BufferedShardByHashTransform was removed on master, nothing consumes BuildQueryPipelineSettings::shard_by_hash_input_batch_bytes anymore, and enable_sharding_aggregator is itself obsolete. That leaves the new setting in Settings.cpp as a documented no-op and turns 04317_sharded_aggregation_batched_input.sql into a tautology, because it only compares the same aggregation path under three ignored values.
Please either reintroduce a live batching consumer on the current branch, or remove the setting, its changelog/docs claims, and the obsolete aggregation test from this PR so the shipped contract matches the code.
Split out the scatter half of #106120 as requested in review
(#106120 (comment)...).
The per-column hash production is in #106538; this PR adds only the batched
scatter interface and its consumer plumbing, stacked on top of that PR.
Changes
DB::ColumnsScatter::scatter— batched, O(1)-dispatch physical split(
src/Columns/ColumnsScatter.h/.cpp). The caller supplies oneIColumnfromeach of B pending chunks at the same column-position, plus shared per-source
UInt32partition-ids and precomputed per-shard row counts. A staticfunction-pointer table keyed on
IColumn::getDataType()selects the typedkernel with a single virtual call and one indexed indirect call — no per-row
virtual dispatch on the hot path.
Fast-path typed kernels for
ColumnVector<T>(full integer / float / UUID /IPv4/6 set),
ColumnDecimal<T>,ColumnFixedString,ColumnString,ColumnNullable, andColumnTuple. All other types fall back to the legacyIColumn::scattervirtual. Mixed-representation batches (ColumnConst/ColumnSparse/ColumnReplicatedmixed with materialized columns, includingwrappers hidden inside composite subcolumns) are normalized once, recursively,
via
normalizeRepresentationbefore dispatch — gated by a genericforEachSubcolumnprobe so every composite is covered — preservingLowCardinality; homogeneousLowCardinalitybatches use the fallback.BufferedShardByHashTransforminput batching — new settingshard_by_hash_input_batch_bytes(default 2 MiB; 0 = legacy per-chunk path).The transform accumulates input chunks until the byte budget is reached, then
flushes via
ColumnsScatter::scatteronce per column-position. Hash productionuses
IColumn::computeHashInto(CRC32C, from #106538) +mapToRange.ScatterByPartitionTransform— wired toColumnsScatter::scatterfor thesame O(1)-dispatch benefit on the parallel-window partitioning path.
Testing
gtest_columns_scatter— 39 cases: equivalence vs legacy for all fast-pathtypes (including
Time64), mixed-representation regressions (ColumnConst-first,materialized-first, two consts with different values, mixed
ColumnConst/ColumnString,and sparse/const elements nested in
Tuple/Nullable/Array/Map/Variant/QBit),LowCardinalitytype-preservation, and per-key count assertions that catch misrouted rows.04317_sharded_aggregation_batched_input— batched vs legacy per-key-identical
GROUP BYresults across key types, with smallmax_block_sizeto exercise the threshold path, multi-chunk batches, non-zero
pids_offset,and the single EOF-flush path.
gtest_compute_hash_into(33/33) and04312_grace_hash_vs_hash_join_key_typesremain green.Performance
benchmark_columns_scatter(added in this PR) microbenchmarks the batchedDB::ColumnsScatter::scatteragainst the legacy per-chunkIColumn::scatterit replaces, over aK columns × P shardssweep with 4 source chunks of 65536UInt64rows each (≈ 4 ×DEFAULT_BLOCK_SIZE).Environment: aarch64 (Apple M5 Max, 6 vCPU, aarch64 Linux VM),
RelWithDebInfo(-O3);cpu_time,--benchmark_repetitions=10, median; the figures below are the mean of 3 separate runs that agreed within ~3% (per-cell CV ≤ ~4%). Absolute times are machine-dependent — the same-machine legacy-vs-batched speedup is the substantive metric.Geomean speedup: 1.30× over all 13 cells and 1.28× over the RFC cells (
K∈{4,8} × P∈{64,128,256}), ranging 1.18×–1.46× and rising with shard countP. (The RFC's 1.43× geomean target was measured on x86; this run is aarch64.)This isolates the scatter primitive — this PR's contribution — against the per-chunk
IColumn::scatterpath it replaces. The end-to-end sharded-aggregation gain combines this with the per-column hash production in the stacked #106538 (IColumn::computeHashInto), which is not in this PR's diff; that is why the earlier cloud report attributed the win tocomputeHashInto.Reproduce:
ninja benchmark_columns_scatter && ./benchmark_columns_scatter --benchmark_repetitions=10 --benchmark_report_aggregates_only=trueChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up sharded aggregation and parallel window partitioning by replacing per-chunk
IColumn::scatterwith a batchedDB::ColumnsScatter::scatterprimitive that uses O(1) type-index dispatch and amortises K×PIColumnallocation cost across many input chunks. A new settingshard_by_hash_input_batch_bytes(default2097152, i.e. 2 MiB) controls bytes-budget input batching inBufferedShardByHashTransform; set it to0to scatter one chunk at a time.Documentation entry for user-facing changes
Related: #105936
Related: #106538
Made with Cursor
Workflow [PR]
Sync PR [sync-upstream/pr/106120]