Skip to content

Fix Shared Snapshot Parts Pin - #112991

Merged
Michicosun merged 9 commits into
masterfrom
fix_shared_snapshot_parts_pin
Aug 4, 2026
Merged

Michicosun merged 9 commits into
masterfrom
fix_shared_snapshot_parts_pin

Conversation

@Michicosun

@Michicosun Michicosun commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

This patch removes metadata cache from BlockIO.

Version info

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

@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c0e7e4f]

Summary: ✅


AI Review

Summary

This PR makes ReadFromMergeTree strip part lists by cloning the snapshot instead of mutating shared state, clears the streaming source's analyzer carriers, and drops BlockIO's strong QueryMetadataCache owner so long-lived STREAM reads can stop pinning obsolete MergeTree parts. The direction looks correct and the previously raised thread concerns appear addressed in the current code, but I do not think the current proof is strong enough to remove the user-facing warning from enable_shared_storage_snapshot_in_query for all MergeTree reads.

PR Metadata
  • ⚠️ Changelog category is fine as Not for changelog, so a Changelog entry is not required here.
  • ⚠️ The provided Changelog entry text is stale and does not describe this PR. Exact replacement: remove the current Changelog entry text entirely.
Findings

⚠️ Majors

  • [src/Core/Settings.cpp:5996] Removing the warning from enable_shared_storage_snapshot_in_query is a broader contract than the new evidence proves. The implementation change is global to ReadFromMergeTree, but the added regression only demonstrates obsolete-part cleanup for ... STREAM. A focused non-stream regression with enable_shared_storage_snapshot_in_query = 1 is still needed before we can say ordinary same-table subqueries no longer hold obsolete parts for the lifetime of the query.
Final Verdict

⚠️ Changes requested: either add a non-stream regression that proves obsolete parts are releasable mid-query with enable_shared_storage_snapshot_in_query = 1, or keep/narrow the warning instead of deleting it for the whole setting.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

Changed lines: Changed C/C++ lines covered: 53/54 (98.15%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 2, 2026
@azat azat self-assigned this Aug 2, 2026

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it also make sense to remove this note -

:::note
Enabling this setting disables the optimization which removes unnecessary data parts from snapshots once the planning stage is complete.
As a result, long-running queries may hold onto obsolete parts for their entire duration, delaying part cleanup and increasing storage pressure.

@Michicosun
Michicosun enabled auto-merge August 2, 2026 15:06
@clickhouse-gh

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 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: 2ab0e6e5-106c-473e-8364-5e727a8b477a
  • MIRAI run: e52ead3a-d123-4d5a-b760-6200a1679fd4
  • PR check IDs:
    • clickbench_1550178_1785794752
    • clickbench_1550185_1785794752
    • clickbench_1550195_1785794752
    • tpch_adapted_1_official_1550207_1785794753
    • tpch_adapted_1_official_1550223_1785794752
    • tpch_adapted_1_official_1550248_1785794753

@Michicosun
Michicosun added this pull request to the merge queue Aug 3, 2026
@Michicosun
Michicosun removed this pull request from the merge queue due to a manual request Aug 3, 2026
@Michicosun
Michicosun enabled auto-merge August 3, 2026 12:04
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread src/Core/Settings.cpp

Without this setting, the outer and inner queries may operate on different data snapshots, leading to incorrect results.

:::note

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.

Removing this note is broader than the evidence in the PR. ReadFromMergeTree now strips parts from every shared snapshot, but the new regression only proves mid-query cleanup for ... STREAM.

We still need a focused non-stream case with enable_shared_storage_snapshot_in_query = 1 (for example, an ordinary same-table subquery that keeps running while obsolete parts are cleaned up) before dropping the warning for the setting entirely. Otherwise the setting can still regress the storage-pressure behavior this note is warning users about and we would not notice.

@Michicosun
Michicosun added this pull request to the merge queue Aug 4, 2026
Merged via the queue into master with commit dd9866e Aug 4, 2026
180 checks passed
@Michicosun
Michicosun deleted the fix_shared_snapshot_parts_pin branch August 4, 2026 01:36
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 4, 2026
PedroTadim pushed a commit to groeneai/ClickHouse that referenced this pull request Nov 6, 2026
… inserts

When a block is inserted into a table with materialized views, the SELECT of
every view is analyzed with the real source table, and only afterwards the
table is replaced by the inserted block in `replaceStorageInQueryTree`. The
analyzer resolved the source table through `getStorageSnapshot`, which for
`MergeTree` collects all active parts and the mutations snapshot. The result
was thrown away, so the cost, proportional to the number of active parts
multiplied by the number of views, was wasted on every inserted block.

The per-query snapshot cache of `enable_shared_storage_snapshot_in_query`
could not mitigate this: the async insert flush never attaches it, and since
ClickHouse#112991 it is no longer kept
alive during pipeline execution, when the views are processed, for
synchronous inserts either.

Now `IdentifierResolver::tryResolveTableIdentifier` uses
`getStorageSnapshotWithoutData` when the context carries a view source with
the same name as the resolved table, exactly the condition under which the
table is later replaced by the block. The snapshot is only used for metadata
and column resolution in this case.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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