Skip to content

Stop copying a system table's metadata twice to set its comment - #115490

Merged
thevar1able merged 2 commits into
masterfrom
system-table-comment-no-metadata-copy
Aug 21, 2026
Merged

thevar1able merged 2 commits into
masterfrom
system-table-comment-no-metadata-copy

Conversation

@thevar1able

@thevar1able thevar1able commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Noticed while profiling start-up for #112496.

Attaching a system table fetched the table back from DatabaseCatalog and copied its whole StorageInMemoryMetadata — which carries the full ColumnsDescription — twice, only to fill in the comment. Since there are ~164 system tables, every start-up copied every system table's schema two extra times.

IStorage::setInMemoryMetadataComment replaces only the comment, and it is now applied to the storage before it is attached, so the catalog lookup goes away as well.

Changelog category (leave one):

  • Performance Improvement

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

Attaching the system tables no longer copies each table's metadata, including its full column description, twice just to set the table comment.


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

Version info

  • Merged into: 26.8.1.1833 (included in 26.8 and later)

Attaching a system table fetched the table back from `DatabaseCatalog` and copied
its whole `StorageInMemoryMetadata` - which carries the full `ColumnsDescription` -
twice, just to fill in the comment. `setInMemoryMetadataComment` replaces only the
comment, and it is now set on the storage before it is attached, so there is no
lookup either.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fd06106]

Summary: ✅


AI Review

Summary

This PR moves the system-table comment update onto the freshly constructed storage and adds IStorage::setInMemoryMetadataComment so attachSystemTables no longer round-trips through DatabaseCatalog and no longer performs the second full StorageInMemoryMetadata copy. I did not find an additional correctness issue in the current code paths, but the PR still lacks the focused before/after evidence that a Performance Improvement claim promises.

Tests
  • ⚠️ Because this PR is filed as Performance Improvement, please add a small before/after startup-time or allocation-profile measurement around system-table attachment or server startup. The code clearly removes one whole metadata copy per system table, but there is still no proof that this is a measurable user-facing win rather than a localized cleanup.
Final Verdict

Needs evidence before merge. No new correctness blockers found in the current code, but the performance claim is still unproven.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 86.90% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

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

Full report · Diff report

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

/// Set the comment on the storage before attaching it, so that we neither look the table back up in
/// `DatabaseCatalog` nor copy its whole metadata (including the full `ColumnsDescription`) an extra time.
storage->setInMemoryMetadataComment(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.

Because this PR is filed as Performance Improvement, I think it needs a small before/after measurement in the description. The code shape clearly removes work here, but without a startup-time or allocation-profile delta it's hard to tell whether this is a measurable user-facing win or just a localized cleanup.

@evillique evillique self-assigned this Aug 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fd061066f with master 6481befc2 (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
Binary Master PR Δ
programs/clickhouse-stripped 704.43 MiB 701.27 MiB -3.16 MiB (-0.45%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

3 object files changed (-192.38 KiB total), 0 added.

Object file Master PR Δ
src/Storages/System/CMakeFiles/clickhouse_storages_system.dir/attachSystemTables.cpp.o 1.69 MiB 1.50 MiB -192.38 KiB (-11.13%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

This PR only changes how SYSTEM database tables are attached and get their comment set at server startup (attachSystemTablesImpl / IStorage), avoiding an extra catalog lookup and metadata copy. Nothing in that path is exercised by TPC-H query execution, so neither flagged delta can be attributed to the change. Q17's flagged +59.4% is downgraded to not_sure: the source measurements were highly variable and the query touches none of the modified code. Q7's +16.4% sits inside master's variance band and is likewise off-path, so both deltas read as run-to-run noise rather than a real PR effect.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 7 not_sure 67 78 +16.4% <0.0001 Correctly within master's variance band; this PR only optimizes SYSTEM-table attachment at startup, a path Q7 never executes, so the +16.4% is variance.
⚠️ 17 not_sure 64 102 +59.4% <0.0001 This PR only speeds up SYSTEM-table attachment at server startup; Q17 executes none of that code and its source runs were very noisy, so the +59.4% reads as run-to-run variance.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. 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: c1d22494-e92d-408b-acdd-11a01603af9c
  • MIRAI run: a639be0f-70f8-49b3-99cc-98eae7b797ee
  • PR check IDs:
    • clickbench_367429_1787277792
    • clickbench_367435_1787277791
    • clickbench_367441_1787277792
    • tpch_adapted_1_official_367458_1787277792
    • tpch_adapted_1_official_367471_1787277792
    • tpch_adapted_1_official_367501_1787277792

Comment thread src/Storages/IStorage.h Resolved
@thevar1able
thevar1able added this pull request to the merge queue Aug 20, 2026
@thevar1able
thevar1able removed this pull request from the merge queue due to a manual request Aug 20, 2026
Comment thread src/Storages/IStorage.h Resolved
@thevar1able
thevar1able enabled auto-merge August 20, 2026 17:16
@thevar1able
thevar1able added this pull request to the merge queue Aug 21, 2026
Merged via the queue into master with commit 36af905 Aug 21, 2026
347 of 348 checks passed
@thevar1able
thevar1able deleted the system-table-comment-no-metadata-copy branch August 21, 2026 06:49
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants