Repository navigation
Conversation
…during analysis When a block is pushed to a materialized view, the analyzer resolves the source table from the catalog (for engine checks) and takes the types from the block, but called `getStorageSnapshot` on the real table. `replaceStorageInQueryTree` then replaces the table with the block before anything reads it, so the snapshot's parts were never used. Building them is not free: it walks all parts of the table, and for a `MergeTree` table with a transaction it copies all Active and Outdated parts and checks the visibility of each, once per view per inserted block. Take `getStorageSnapshotWithoutData` for the view source instead: analysis reads only the metadata, and every place that reads the table (the query itself, scalar subqueries, `IN`) swaps in the block first. The test checks that materialized views keep reading the block (plain, `IN`, scalar subquery, CTE, join), and ordinary views and the `view` table function keep reading the table, with and without a transaction. Related: 97ad587
|
Workflow [PR], commit [5b2ce37] Summary: ✅
AI ReviewSummaryThis PR uses Findings
Tests
Final VerdictStatus: |
| auto storage_snapshot = storage->getStorageSnapshot(metadata_snapshot, context); | ||
| /// The view source is read instead of the table, so the table's parts are not needed. | ||
| auto storage_snapshot = is_view_source | ||
| ? storage->getStorageSnapshotWithoutData(metadata_snapshot, context) |
There was a problem hiding this comment.
The new stateless test verifies result semantics, but it neither measures snapshot cost nor exercises a long-lived transaction retaining Outdated parts. It would also pass with the original getStorageSnapshot call restored. The description explains the suspected hotspot, but provides no reproducible workload or before/after measurements establishing the benefit of this change.
Please add a focused performance test or publish a reproducible before/after comparison of insert CPU or latency with several materialized views and retained parts. Include the part/block counts and enable_shared_storage_snapshot_in_query setting, since snapshot sharing affects how often the old path actually builds a snapshot.
|
📊 Cloud Performance Report ✅ AI verdict: Baseline selected using StressHouse version hint 26.11.1.42530; measured build ancestry could not be verified. Measured differences are not attributed to this PR. ⚙️ Master level shift inside the baseline window (~2026-10-18 06:14:51): baseline for 1 query restricted to the checks matching the selected baseline era. no significant changes detected. K_source=6 K_base=25 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
|
@groeneai Check the CI failure |
|
The only failing job on 77b78af is
Current runs use |
When a block is pushed to a materialized view, the analyzer resolves the view's source table from the catalog, so engine checks (
FINAL,SAMPLE,_shard_num) see the real table, and takes the column types from the inserted block. It also calledgetStorageSnapshoton the real table.replaceStorageInQueryTreethen replaces that table with the block before anything reads it, so the parts in that snapshot were never used.Building them is not free. It walks all parts of the table once per view per inserted block. For a
MergeTreetable used inside a transaction it is worse: it copies all Active and Outdated parts and checks the visibility of each. While a long transaction keeps Outdated parts from being removed, that cost grows with every insert. In a load test with three materialized views and a transaction held open for 30 minutes, it became the largest growing part ofINSERTCPU.This takes
getStorageSnapshotWithoutDatafor the view source instead. The metadata is the same; only the parts list is left out. Analysis reads only the metadata, and every place that reads the table (the view query, scalar subqueries,IN) swaps in the block first. The old analyzer already usesgetStorageSnapshotWithoutDatawhen it only analyzes.The new test checks that materialized views keep reading the inserted block (plain,
IN, scalar subquery, CTE, join), and that an ordinary view and theviewtable function inside a materialized view keep reading the table, with and withoutimplicit_transaction.Related: #123514
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Inserting into a table with materialized views no longer builds an unused list of the source table's parts for every view and block. This was expensive for
MergeTreetables inside a transaction while old parts are kept.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126589]