Skip to content

Add ColumnsScatter::scatter: batched column split with type-index dispatch and bytes-budget input buffering - #106120

Draft
harikrishnan94 wants to merge 13 commits into
ClickHouse:masterfrom
harikrishnan94:icolumn-shuffle-primitives
Draft

harikrishnan94 wants to merge 13 commits into
ClickHouse:masterfrom
harikrishnan94:icolumn-shuffle-primitives

Conversation

@harikrishnan94

@harikrishnan94 harikrishnan94 commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

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 one IColumn from
each of B pending chunks at the same column-position, plus shared per-source
UInt32 partition-ids and precomputed per-shard row counts. A static
function-pointer table keyed on IColumn::getDataType() selects the typed
kernel 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, and ColumnTuple. All other types fall back to the legacy
IColumn::scatter virtual. Mixed-representation batches (ColumnConst /
ColumnSparse / ColumnReplicated mixed with materialized columns, including
wrappers hidden inside composite subcolumns) are normalized once, recursively,
via normalizeRepresentation before dispatch — gated by a generic
forEachSubcolumn probe so every composite is covered — preserving
LowCardinality; homogeneous LowCardinality batches use the fallback.

BufferedShardByHashTransform input batching — new setting
shard_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::scatter once per column-position. Hash production
uses IColumn::computeHashInto (CRC32C, from #106538) + mapToRange.

ScatterByPartitionTransform — wired to ColumnsScatter::scatter for the
same O(1)-dispatch benefit on the parallel-window partitioning path.

Testing

  • gtest_columns_scatter — 39 cases: equivalence vs legacy for all fast-path
    types (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),
    LowCardinality type-preservation, and per-key count assertions that catch misrouted rows.
  • 04317_sharded_aggregation_batched_input — batched vs legacy per-key-
    identical GROUP BY results across key types, with small max_block_size
    to exercise the threshold path, multi-chunk batches, non-zero pids_offset,
    and the single EOF-flush path.
  • Also verified: gtest_compute_hash_into (33/33) and
    04312_grace_hash_vs_hash_join_key_types remain green.

Performance

benchmark_columns_scatter (added in this PR) microbenchmarks the batched DB::ColumnsScatter::scatter against the legacy per-chunk IColumn::scatter it replaces, over a K columns × P shards sweep with 4 source chunks of 65536 UInt64 rows 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.

K P (shards) legacy µs/op batched µs/op speedup
1 32 333 261 1.28×
1 64 324 246 1.32×
1 128 347 258 1.34×
1 256 367 252 1.46×
2 64 609 502 1.21×
2 128 666 516 1.29×
2 256 714 507 1.41×
4 64 1207 1013 1.19×
4 128 1324 1042 1.27×
4 256 1417 1021 1.39×
8 64 2407 2040 1.18×
8 128 2644 2097 1.26×
8 256 2871 2089 1.37×

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 count P. (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::scatter path 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 to computeHashInto.

Reproduce: ninja benchmark_columns_scatter && ./benchmark_columns_scatter --benchmark_repetitions=10 --benchmark_report_aggregates_only=true

Changelog category (leave one):

  • Performance Improvement

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::scatter with a batched DB::ColumnsScatter::scatter primitive that uses O(1) type-index dispatch and amortises K×P IColumn allocation cost across many input chunks. A new setting shard_by_hash_input_batch_bytes (default 2097152, i.e. 2 MiB) controls bytes-budget input batching in BufferedShardByHashTransform; set it to 0 to scatter one chunk at a time.

Documentation entry for user-facing changes

  • Documentation is changed for user-facing changes

Related: #105936
Related: #106538

Made with Cursor


Workflow [PR]
Sync PR [sync-upstream/pr/106120]

@CLAassistant

CLAassistant commented May 29, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@clickhouse-gh

clickhouse-gh Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8445bd9]

Summary: ❌

job_name test_name status info comment
Build (arm_tidy) FAIL
Build ClickHouse FAIL cidb
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_tsan) DROPPED

AI Review

Summary

This PR adds the batched DB::ColumnsScatter::scatter primitive and wires it into ScatterByPartitionTransform, but later merges removed the original sharded-aggregation batching consumer. The remaining scatter work looks plausible, however the PR still ships and documents a dead shard_by_hash_input_batch_bytes setting and a stateless test that no longer exercises a distinct code path, so I would not merge it in its current form.

PR Metadata
  • Changelog category: Performance Improvement is still reasonable for the live ScatterByPartitionTransform speedup.
  • Changelog entry: the current entry is no longer correct on this branch because it claims sharded aggregation batching and a new setting that now has no consumer.
  • Exact replacement: Speed up hash-based row partitioning in ScatterByPartitionTransform by replacing per-chunk IColumn::scatter with batched DB::ColumnsScatter::scatter, improving parallel window partitioning and other pipeline stages that scatter rows by hash.
Findings

⚠️ Majors

  • [src/Processors/QueryPlan/BuildQueryPipelineSettings.cpp:38] shard_by_hash_input_batch_bytes is copied into BuildQueryPipelineSettings, but nothing on the current branch ever reads it after BufferedShardByHashTransform was removed and enable_sharding_aggregator became obsolete. That leaves a documented user-facing setting that silently does nothing, and the PR's aggregation test now passes without exercising any live batching path.
    Suggested fix: either reintroduce a current-branch consumer for this setting, or drop the setting, the obsolete aggregation test, and the corresponding changelog/docs claims from this PR.
Tests
  • ⚠️ tests/queries/0_stateless/04317_sharded_aggregation_batched_input.sql no longer proves the claimed behavior on current master: it only toggles a no-op setting on top of an obsolete enable_sharding_aggregator path.
Final Verdict

⚠️ Request changes. The ColumnsScatter integration itself may be fine, but the PR in its current merged state still exposes a no-op setting and non-proving coverage for behavior that no longer exists on this branch.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label May 29, 2026
@harikrishnan94 harikrishnan94 changed the title Add non-allocating column hash/scatter primitives for batched sharded aggregation Add non-allocating column hash/scatter primitives for batched sharding in query execution May 29, 2026
@nickitat nickitat added the can be tested Allows running workflows for external contributors label May 30, 2026
@nickitat nickitat self-assigned this May 30, 2026
Comment thread src/Columns/ColumnNullable.cpp Resolved
@harikrishnan94
harikrishnan94 force-pushed the icolumn-shuffle-primitives branch from 2d5170d to e817438 Compare May 30, 2026 17:17
Comment thread src/Columns/ColumnArray.cpp Resolved
Comment thread src/Columns/IColumn.h Resolved
@nickitat

nickitat commented Jun 1, 2026

Copy link
Copy Markdown
Member

@harikrishnan94, pls fix the style check and merge conflicts to unblock the CI.

harikrishnan94 added a commit to harikrishnan94/ClickHouse that referenced this pull request Jun 4, 2026
… 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]>
Comment thread src/Columns/ColumnDynamic.h Resolved
Comment thread src/Columns/ColumnsScatter.cpp Resolved
Comment thread src/Columns/ColumnObject.cpp Resolved
Comment thread src/Columns/ColumnTuple.cpp Resolved
Comment thread src/Columns/ColumnsScatter.cpp Resolved
Comment thread src/Columns/ColumnArray.cpp Resolved
Comment thread src/Interpreters/JoinUtils.cpp Resolved
@harikrishnan94
harikrishnan94 force-pushed the icolumn-shuffle-primitives branch from 3776293 to e82a26e Compare June 4, 2026 10:59
@harikrishnan94

Copy link
Copy Markdown
Contributor Author

@nickitat - pushed fixes for all four blockers from ; ready for another look.

harikrishnan94 added a commit to harikrishnan94/ClickHouse that referenced this pull request Jun 4, 2026
… 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]>
Comment thread src/Columns/ColumnsScatter.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

🟢 AI verdict: improvement — 4 query(s) improved out of 38 analysed

4 improved query(s). K_source=6 K_base=30 flagged=4/65

clickbench

🟢 2 improved

Flagged queries (2 of 43)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
🟢 22 improvement 334 254 -23.9% <0.0001
🟢 23 improvement 297 200 -32.7% <0.0001

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)
Query Verdict Baseline med (ms) PR med (ms) Change q-value Hint
🟢 7 improvement 113 72 -36.3% <0.0001
🟢 20 improvement 248 126 -49.2% <0.0001

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
  • StressHouse run: 11d82f37-4a0e-4f22-8585-f56df42781a6
  • MIRAI run: 8e4b816d-9ca7-43c9-87ba-a7baefc049cf
  • PR check IDs:
    • clickbench_283094_1781659777
    • clickbench_283180_1781659809
    • clickbench_283279_1781659878
    • tpch_adapted_1_official_283425_1781660073
    • tpch_adapted_1_official_283524_1781660174
    • tpch_adapted_1_official_283544_1781660175

@harikrishnan94
harikrishnan94 requested review from Copilot and removed request for nihalzp June 14, 2026 05:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::scatter with O(1) type-index dispatch plus row-count precomputation, and integrate it into BufferedShardByHashTransform and ScatterByPartitionTransform.
  • Replace WeakHash32 with IColumn::computeHashInto across column implementations and update hash consumers (JoinUtils, transforms).
  • Add unit/stateless tests and new microbenchmarks for computeHashInto and ColumnsScatter::scatter; add mapToRange() 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).

Comment thread src/Core/Settings.cpp Resolved
harikrishnan94 and others added 3 commits June 14, 2026 12:20
…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]>
Comment thread src/Columns/ColumnsScatter.cpp Resolved
@harikrishnan94
harikrishnan94 requested a review from nickitat June 14, 2026 08:30
harikrishnan94 and others added 4 commits June 14, 2026 14:34
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]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.50% 77.60% +0.10%

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

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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.

@harikrishnan94
harikrishnan94 marked this pull request as draft July 10, 2026 10:11
@nickitat nickitat self-assigned this Jul 31, 2026
@abashkeev abashkeev added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Sep 4, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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)
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…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];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@clickhouse-gh clickhouse-gh Bot added comp-data-types Type system & core datatypes used across query planning/execution. and removed comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. labels Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-data-types Type system & core datatypes used across query planning/execution. pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants