Skip to content

Avoid building unused full-column serializations in MergeTree readers - #111020

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
rorylshanks:agent/avoid-unused-full-column-serializations
Sep 13, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
rorylshanks:agent/avoid-unused-full-column-serializations

Conversation

@rorylshanks

@rorylshanks rorylshanks commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Related: #110957

IMergeTreeReader currently constructs and stores a full-column serialization whenever a subcolumn is requested. However, serializations_of_full_columns is only consumed by MergeTreeReaderCompact when reading compact parts that do not have substream marks.

This means wide parts and compact parts with substream marks construct full-column serializations that are never used. This is particularly expensive for JSON, where constructing SerializationJSON also builds the JSON extraction tree.

Restrict initialization to the only reader configuration that consumes it: compact parts without substream marks. This avoids unnecessary CPU and memory allocation for all other subcolumn reads without introducing another cache or changing serialization lifetime.

The change passed the focused 03732_json_duplicated_path_in_dynamic_paths_and_shared_data_compact_part_bug stateless test in both parallel and sequential jobs. It was also validated with Debug and production ThinLTO builds. The PostHog JSON microbenchmark retained the previous optimized performance within run-to-run noise.

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Avoid unnecessary construction of full-column serializations when reading subcolumns from wide parts or compact parts with substream marks.

Documentation entry

  • Documentation is not required because this is an internal performance optimization.

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

Version info

  • Merged into: 26.9.1.1343 (included in 26.9 and later)

@clickhouse-gh clickhouse-gh Bot added the comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. label Sep 4, 2026
@evillique evillique added the can be tested Allows running workflows for external contributors label Sep 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ea31b9b]

Summary: ✅


AI Review

Summary

This PR narrows serializations_of_full_columns initialization to the only reader mode that still consumes it: compact MergeTree parts without substream marks. After tracing the current subcolumn read paths in IMergeTreeReader, MergeTreeReaderCompact, MergeTreeReaderWide, and the text-index fallback reader, I did not find a remaining correctness or completeness issue in the live diff.

Missing context / blind spots
  • ⚠️ I did not reproduce the referenced JSON microbenchmark locally, so the exact size of the claimed performance win was not independently validated in this review. Attaching before/after benchmark numbers would fully close that evidence gap.
Final Verdict

✅ No findings.

LLVM Coverage Report

Measured on commit ea31b9b.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.70% 91.80% +0.10%
Branches 81.40% 81.30% -0.10%

Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 459919c7-60d2-4d32-8186-7fe79a6ef0cf
  • MIRAI run: 5df60f16-ce4c-4528-929c-88ce42b24dd6
  • PR check IDs:
    • clickbench_192961_1789231410
    • clickbench_192974_1789231410
    • clickbench_192980_1789231410
    • tpch_adapted_1_official_192986_1789231410
    • tpch_adapted_1_official_192997_1789231410
    • tpch_adapted_1_official_193033_1789231410

@clickhouse-gh

clickhouse-gh Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ea31b9bcc with master 3476b12ea (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 12, 2026
Merged via the queue into ClickHouse:master with commit 436a98a Sep 13, 2026
175 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
rorylshanks added a commit to rorylshanks/ClickHouse that referenced this pull request Sep 13, 2026
Reuse the same parent serialization, deserialization state, and cached
column for full-column and subcolumn requests without substream marks.
Copy only the current granule when the cached full column spans earlier
granules. Cover both request orders and block boundaries, and add a
mixed full-column/subcolumn performance query.

ClickHouse#110957 (comment)
Related: ClickHouse#111020

ClickHouse#110957
leshikus pushed a commit to leshikus/ClickHouse that referenced this pull request Oct 27, 2026
@clickhouse-gh clickhouse-gh Bot added comp-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... and removed comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. labels Nov 22, 2026
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-part-formats Formats of MergeTree data parts in the public repository, that is how a part is laid out on disk ... pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants