Repository navigation
Conversation
…rges of many sorted inputs `MergedData` measured the output block through the virtual `IColumn` interface for every column, per row in `hasEnoughRows` (default queue) and per row and column in `rowsToInsertBeforeFlush` (batch queue), even for plain fixed-size columns whose size is exactly `rows x value size`. `MergingSortedAlgorithm` now asks `MergedData` to classify its columns through `IColumn::getPlanes` while no `ColumnReplicated` column can reach the merge: columns with `Shape::Fixed` planes (`ColumnVector`, `ColumnDecimal`, `ColumnFixedString`) are counted as `base + merged_rows x stride` (the base is `sizeof(n)` for `FixedString`, zero otherwise), so merge blocks are cut at the same rows as before and merged parts stay byte-identical. The classification is redone after `insertChunk`, the only place the destination columns are replaced. When at least 8 inputs are merged, each run inserted from a source is followed by a prefetch of the cache line 64 bytes past the start of that source's next row in each of its fixed-size columns, formed only when it lies inside the chunk column's data. With many interleaved parts the merge reads more streams than the hardware prefetcher follows; with few inputs the prefetch was measured in ClickHouse#131192 to cost more than it gains. The analysis, the prefetch and the original measurements are from ClickHouse#131192. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`OPTIMIZE ... FINAL` of 50 parts of 100000 rows sorted by `(sid, ts)`, with the default and with the batch sorting queue, the same merge of a table without fixed-size columns, and a read in order of the 50 parts. Every timed merge re-attaches the source parts first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…irst block of the byte-limit gtest The Iceberg performance configuration selects every new test that creates a MergeTree table unless it opts out. `optimize_many_small_parts.xml` checks `system.parts` and runs `ATTACH PARTITION ... FROM` and `OPTIMIZE ... FINAL`, which cannot work on the rewritten Iceberg tables, so it opts out with `<test iceberg="0">`, like `coalesce_short_circuit.xml`. The skip list is not used because changing it runs the whole Iceberg configuration. `MergingSortedBatchLimits.MaxBlockSizeBytes` only compared the default and the batch queue, which share the fixed-size byte count, so a miscount common to both passed. It now also checks that the 100-byte limit cuts the first block after 3 rows, which is master's behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the refuted-alternative clause from the enableFixedSizeByteCount doc comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings over 2 rounds).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261114-042900 |
|
Workflow [PR], commit [ddad531] Summary: ✅
AI ReviewSummaryReviewed #131534 at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings or existing review threads require action. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units34 translation units recompiled, 283 s compile time in total, 34 of them have a recent master baseline. Median compile-time ratio to the baselines is ×0.90 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
Related: #131192
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Merges of many small parts are faster for tables with fixed-size columns (numbers, dates, decimals, UUIDs, IP addresses,
FixedString): the merge no longer asks every column for its size after every row, and when it merges at least 8 parts it prefetches the next rows of each part.OPTIMIZE FINALof 50 parts of 200000 rows with 9 columns uses 9% less CPU, and 11-12% less withmerge_use_batch_sorting_queue = 1.Description
Analysis, prefetch and original measurements by snelheidai in #131192, verified and reworked.
To respect
merge_max_block_size_bytes,MergedDataasks every output column for its size through the virtualIColumninterface:byteSize()per merged row with the default sorting queue,byteSizeAt()per row and column with the batch queue. Columns whosegetPlanes()isShape::Fixed(ColumnVector,ColumnDecimal,ColumnFixedString) are now counted from the row count. The count is exact, so blocks are cut at the same rows and merged parts stay byte-identical. When at least 8 inputs are merged, the next cache line of each fixed-size column of the source just consumed is prefetched, only inside its data.The issue's in-place copy is not included: it saved about 5% more CPU with the default queue and nothing with the batch queue, which with this PR is 11-18% cheaper than the default queue for these tables.
Release ThinLTO, Xeon 6975P-C, 4 pinned vCPUs, 20 paired runs, CPU time, PR / master (95% CI):
OPTIMIZE FINAL, 50 parts of 200000 rowsORDER BY, 4 / 16 threadsMemory is unchanged. Merged parts are identical to master for 20 cases (both queues, vertical merges, TTL and lightweight deletes, 4096-byte blocks, 30 fixed-size types, sparse columns), 7 of them also under ASan+UBSan. New perf test
optimize_many_small_parts.xml.My #131486 (
JSON/Dynamicbatching) also changesMergedData::rowsToInsertBeforeFlush; the two are independent, whichever merges second is rebased.Workflow [PR]
Sync PR [sync-upstream/pr/131534]