Repository navigation
Conversation
…ueue sizes a batch `MergedData::rowsToInsertBeforeFlush` inserted every row of a merge with a `JSON` or `Dynamic` column one by one when `merge_max_block_size_bytes` is set, because the sum of the source rows' `byteSizeAt` can underestimate the growth of the merged block. A merge fixes the dynamic structure of the merged column (`chooseDynamicStructureForMerge`), so when every path and variant of the source is in the merged column the rows are copied as they are, and the merged column only adds a default (a 1-byte discriminator and an 8-byte offset) to each dynamic path the source lacks. `extraBytesPerInsertedRow` returns that bound for a (merged, source) column pair, recursing into typed and dynamic paths, variants, `Array` (exact only), `Map`, `Nullable` and `Tuple`, and nullopt when a value could move between the regular storage and the shared data or the shared variant, which keeps the row-by-row insertion for those sources. In the bounded case the bound is exact, so blocks end at the same rows as before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bound from `extraBytesPerInsertedRow` depends only on the structure of the merged column, which a merge fixes in `initialize`, and on the structure of the source chunk, which does not change while the chunk lives. Evaluating it for every batch cost more than batching saved when parts interleave in runs of 2 or 3 rows (merges 1.12x and 1.37x slower than master), and for every row of a run whose source falls back to row-by-row insertion (up to 1.29x). `MergingSortedAlgorithm` now keeps the bound per source in `source_extra_bytes_per_row`, refreshed in `initialize` and `consume` where `source_row_filter_masks` is, only for the batch queue with a byte limit (the default queue and query-time merges never read it), and passes it to `rowsToInsertBeforeFlush`. A destination column can still be wrapped in `ColumnReplicated` during a merge, so once `may_have_replicated_columns` is set the bound is recomputed for every batch. `OPTIMIZE ... DRY RUN PARTS`, release build, ratio to master over 15 paired rounds: runs of 3 / 2 rows 0.81 / 0.92 (were 1.12 / 1.37), shapes that fall back 0.85-1.02 (were up to 1.29), 20-path JSON 0.69. Merged parts are byte-identical to master. The keys of the late-replicated-chunk test interleave so that neither queue passes a chunk through whole: wrapping an empty destination in `ColumnReplicated` gives it 8-byte indexes (`ColumnIndex::insertIndexesRange(0, 0)`), which would make the two queues' blocks differ for a reason unrelated to the bound. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A row of a `Dynamic` column fills one variant (NULL rows none), so taking the maximum of the variants' bounds charged a growing variant's defaults to the rows of every other variant. Reachable with a `JSON` variant whose values lack a path of the merged `JSON` variant (the merge fixes the structure of variants too): the bound was conservative, so the batch queue ended blocks earlier than row-by-row insertion. Return 0 only when no source variant grows, nullopt (row by row) otherwise. The new gtest builds a `Dynamic` column alternating `Int64` and `JSON` values: with a missing path the batch is 1 row (row by row 46, the old maximum gave 38); with all paths the batch equals row by row (44). Remove 05632_merge_batch_sorting_queue_dynamic: it compared batch-on and batch-off merge results, which are equal with or without this change, so it could not fail. The batching is covered by the MergedData gtests and the performance test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds)
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261113-222100 |
|
Workflow [PR], commit [5b2c1b5] Summary: ✅
AI ReviewSummaryThis PR batches Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes19 object files changed (+36.67 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units34 translation units recompiled, 417 s compile time in total, 34 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.14 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - b58e76bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The Session id: cron:our-pr-ci-monitor:20261114-043009 |
…h-dynamic-json Resolve the conflicts with the `[[nodiscard]]` attributes of ClickHouse#126158 in `MergedData.h` and `MergingSortedAlgorithm.h`, and mark the new const getters `extraBytesPerRow` and `maxBlockSizeBytes` `[[nodiscard]]` as well, since master now enables `modernize-use-nodiscard`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…iguration The test measures merges of MergeTree parts with `JSON` and `Dynamic` columns, which the Iceberg rewrite of `perf.py --table-engine` cannot keep (`Column json of type JSON has no Iceberg equivalent`), so the six `Performance Comparison (*, iceberg_*)` jobs it scheduled measured nothing. Opt it out with `<test iceberg="0">` rather than the skip list, which is one of `ICEBERG_PERFORMANCE_PATHS` and would run the whole Iceberg suite instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #127826
Related: #108468
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Merges with
merge_use_batch_sorting_queueenabled now insert runs of rows ofJSONandDynamiccolumns at once instead of one row at a time, still respectingmerge_max_block_size_bytes, whenever the values keep their storage in the merged part (no value moves between dynamic paths or variants and the shared data). A merge of interleaved parts of a table with a 20-pathJSONcolumn takes about 0.7 of the time.Description
#127826 lets the batch sorting queue batch
LowCardinalitycolumns undermerge_max_block_size_bytes; columns with a dynamic structure stayed row by row because the source rows'byteSizeAtcan underestimate how much the merged block grows. Its review asked for a safe upper bound forJSON/Dynamic(#127826 (review)).A merge fixes the dynamic structure of the merged column (
chooseDynamicStructureForMerge). When every path and variant of a source chunk is in the merged column, its rows are copied as they are and the merged column only adds a default, a 1-byte discriminator and an 8-byte offset, to each dynamic path the source lacks.extraBytesPerInsertedRowreturns that bound for a column pair. It returns nullopt, which keeps the row-by-row insertion, when a value could move to or from the shared data or the shared variant, or when aJSONvalue inside aDynamiccolumn lacks a path. The bound is computed once per source chunk inMergingSortedAlgorithm, and per batch only after a destination column was wrapped inColumnReplicated. It is exact, so merged parts are byte-identical to master unless the table also has aLowCardinalitycolumn, whose estimate from #127826 can end blocks at other rows.Validation: gtests (the 9-byte default by equality; batch == row-by-row; 1,000 paths with 8,000 empty objects batch 1,165 rows at 10 MiB; the fallback shapes stay at 1 row; per-chunk refresh; late replicated chunk) and a performance test. Release build,
OPTIMIZE ... DRY RUN, ratio PR / master over 15 rounds: 20-path JSON 0.69, parts with 5 of 20 paths 0.66,Dynamic0.79, arrays of objects 0.68, 1,000 paths 0.86 (same peak memory as the default queue), runs of 3 / 2 rows 0.81 / 0.92, shapes that fall back 0.85-1.02.Workflow [PR]
Sync PR [sync-upstream/pr/131486]