Repository navigation
Conversation
|
cc @Avogar for review. This removes an |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260703-162300 |
|
Workflow [PR], commit [3a22898] Summary: ❌
AI ReviewSummaryThis PR replaces the per-row scan in Missing context / blind spots
Final Verdict✅ No new inline findings. The current patch preserves the shared-data densification contract while removing the expensive per-row scan, and the earlier review concern about overstating the asymptotic improvement has already been addressed in the current code and PR text. |
flattenAndBucketSharedDataPaths densified each collected shared-data path into a column with one entry per row. It did this by iterating over ALL accumulated path columns for every row and inserting a default into each column that had no value in that row. With P distinct paths over N rows that is O(N * P) iterations, each with an individual insertDefault call. JSON columns whose shared data holds many sparse paths (each present in only a few rows) hit this per-row scan during merges and part serialization. Under sanitizer builds a single such merge can take many minutes; because the background merge/mutation executor is not cancelled on shutdown until its in-flight task finishes, a slow serialization here can hold up server shutdown long enough to trip the stress-test hung check. Backfill the missing defaults lazily instead: pad a path column with a single bulk insertManyDefaults right before storing a real value (and pad every column once at the end), and touch only the paths present in each row. This removes the per-row scan over every accumulated path and the per-cell insertDefault calls. This is a constant-factor and scan-removal win, not an asymptotic reduction. insertManyDefaults forwards to ColumnVariant::insertManyDefaults, which resize_fills one NULL row per padded cell, so the dense output still materializes O(N * P) cells in the sparse worst case. The produced columns are identical (shared-data paths are unique and sorted within a row), only faster.
591a1ef to
720996b
Compare
CI finish ledger — 720996bEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Both arm_darwin failures are the macOS Fast-test Python-environment class fixed by #108859 (merged 2026-07-03 18:32Z, "Darwin fast test: prune/classify skips, portability fixes, provision Python deps"): it provisions numpy in the fasttest image and prunes the affected skips. This PR's diff is Session id: cron:our-pr-ci-monitor:20260703-223000 |
…ared-data-paths-quadratic
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 60/60 (100.00%) · Uncovered code |
CI finish ledger — 3a22898Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260704-030000 |
0cb025a
…hared-data-paths-quadratic Speed up flattenAndBucketSharedDataPaths for sparse JSON shared data
Related: #107941
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up serialization and merges of
JSONcolumns whose shared data contains many sparse paths. When flattening shared data into per-path columns,flattenAndBucketSharedDataPathsno longer scans every accumulated path column on every row and no longer inserts a default one cell at a time; the per-row scan over all paths is removed and gaps are backfilled in bulk.Description
flattenAndBucketSharedDataPaths(src/DataTypes/Serializations/SerializationObjectHelpers.cpp) collects eachJSONshared-data path into its own dense column with one entry per row. It did this by iterating over all accumulated path columns for every row and inserting a default into each column that had no value in that row, i.e.O(rows * paths)iterations with an individualinsertDefaultcall per gap.When a
JSONcolumn's shared data holds many sparse paths (each present in only a few rows), this per-row scan over all paths dominates part serialization during merges/mutations. Under sanitizer builds one such merge can run for many minutes.This also shows up as the stress-test hung check.
MergeTreeBackgroundExecutor::wait()(called fromContextSharedPart::shutdown) does not cancel an in-flight merge/mutation, it only waits for the pool thread to finish. If that thread is stuck in this serialization, shutdown blocks past the 90s hung-check window and the run is reported asPossible deadlock on shutdown. This PR removes the per-row scan over all paths and the per-cell default insertions; it does not change the general shutdown-cancellation behaviour, which is a separate item.The fix backfills missing defaults lazily: a path column is padded with a single bulk
insertManyDefaultsright before storing a real value (and every column is padded once at the end), and each row only touches the paths actually present in it. The produced columns are identical (shared-data paths are unique and sorted within a row), only faster.This is a large constant-factor and scan-removal win, not an asymptotic reduction of the whole operation: the number of defaults materialized is unchanged.
ColumnDynamic::insertManyDefaultsforwards toColumnVariant::insertManyDefaults, whichresize_fills one NULL row per padded cell, so the dense output still holdsO(rows * paths)cells in the sparse worst case. What is removed is the per-row scan over every accumulated path and the per-cell virtualinsertDefaultdispatch (replaced by a bulk fill).Measured on
OPTIMIZE TABLE ... FINALof a 60000-row granule withobject_shared_data_serialization_version = 'advanced'(compact part, debug build):Correctness: the existing
0355xJSON shared-data advanced-serialization tests pass unchanged, a byte-for-byte comparison of read-back data between the old and new code on varied JSON is identical, and a new unit testObjectSerialization.FlattenAndBucketSharedDataPathsasserts the densified output for full and partial row ranges (including empty and trailing-gap rows).Version info
26.7.1.625(included in26.7and later)