Repository navigation
Fix EXCHANGE TABLES dropping MV source dependencies (#105021) - #105029
Merged
Merged
Conversation
Adds `04240_exchange_tables_drops_mv_source_dependencies`. After `EXCHANGE TABLES a, b` where a materialized view reads from `a`, inserts into both `a` and `b` silently stop feeding the `MV` target table. Regression introduced by #98779 (correct on `v26.4.2.10`, broken on master). The reference pins the current buggy behavior: both post-exchange `SELECT count() FROM dst` assertions stay at 1. When the bug is fixed, the reference must be updated. Related: #105021 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`EXCHANGE TABLES a, b` (and the synthetic exchange used by `CREATE OR REPLACE TABLE` / `REPLACE TABLE`) cross-swapped the source-side `view_dependencies` edges along with the data. The `MV`'s stored `select_table_id` is not rewritten by the rename, so cross-swapping orphaned the `MV`: * `INSERT INTO a` after exchange found no dependents — the edge had been moved to `b`. * `INSERT INTO b` was rejected by `InsertDependenciesBuilder::observePath` because the `MV`'s recorded source name `a` no longer matched the parent `b`. Both inserts silently dropped rows. Restore the pre-#98779 semantics for `EXCHANGE`: keep source-view edges keyed by the original name. The `MV` continues to read from whatever now lives at the name it was created against. Plain `RENAME TABLE` keeps the post-#98779 re-keying behavior used by `01155_rename_move_materialized_view`. This also subsumes the special case from #104907 — the synthetic `CREATE OR REPLACE` exchange routes through the same `exchange_tables=true` branch. Tests: * `04240_exchange_tables_drops_mv_source_dependencies` — regression test for #105021. Now passes; `MV` continues to feed `dst` after `EXCHANGE TABLES`. Reference updated to the fixed behavior. * `04235_create_or_replace_source_table_view_dependencies` — cherry from #104907 (originally authored by @serprex). Passes with the unified fix. * `04241_rename_table_mv_source_dependencies` — pins a pre-existing latent bug in plain same-database `RENAME TABLE` (silent data loss, alive-but-orphaned `MV`). Not a #98779 regression; not fixed by this PR. Root cause shared with #76303; out of scope. The chosen behavior here ("option C": edges follow the name) is a regression repair — it matches v26.4. A future redesign to "option A" (identity-bound, atomic `MV.as_select` rewrite, like PostgreSQL) is tracked separately. Closes #105021 Co-Authored-By: Philip Dubé <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [e509b53] Summary: ✅ AI ReviewSummaryThis PR fixes incorrect handling of source-side Final Verdict
|
This was referenced May 15, 2026
The cross-swap of source-view dependency edges on `EXCHANGE TABLES` introduced by #98779 (commit `6133fbc6416`) is undone by the fix for #105021. The post-`EXCHANGE` sections of this test now produce the option-C output (edges follow the name) that matches the reference from before `6133fbc6416`. The `RENAME TABLE` sections keep #98779's behavior intact. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 15, 2026
CheSema
enabled auto-merge
May 15, 2026 16:15
Contributor
LLVM Coverage Report
Changed lines: 100.00% (10/10) · Uncovered code |
serprex
approved these changes
May 16, 2026
pfcoperez
added a commit
to PeerDB-io/peerdb
that referenced
this pull request
May 25, 2026
Previous PR #4303 reduced the scope of some e2e tests that were affected by ClickHouse/ClickHouse#105021 regression in ClickHouse. This regression has since then been fixed through ClickHouse/ClickHouse#105029 Hence, this follow-up PR reverts the workaround in the e2e tests, restoring their original coverage.
pfcoperez
added a commit
to PeerDB-io/peerdb
that referenced
this pull request
May 25, 2026
Previous PR #4303 reduced the scope of some e2e tests that were affected by ClickHouse/ClickHouse#105021 regression in ClickHouse. This regression has since then been fixed through ClickHouse/ClickHouse#105029 Hence, this follow-up PR reverts the workaround in the e2e tests, restoring their original coverage. Closes: https://linear.app/clickhouse/issue/DBI-738
alexey-milovidov
pushed a commit
to amosbird/ClickHouse
that referenced
this pull request
Oct 8, 2026
When the definition of a system log changes, `SystemLog::prepareTable` renames the table to `<name>_N` and creates a new one under the old name. Since ClickHouse#98779 a plain `RENAME TABLE` moves the source-side view-dependency edges to the new name, but a materialized view's query still reads the log by name (`select_table_id` is name-only and `InsertDependenciesBuilder` rejects any other source), so the new table had no dependent views and the view silently stopped receiving rows until the next restart rebuilt the graph by name. Add an internal `InterpreterRenameQuery::setKeepSourceViewDependencies` that leaves those edges on the old name, as `EXCHANGE TABLES` already does (ClickHouse#105029), and set it only for the system log rotation. User `RENAME TABLE` keeps re-keying the edges. Closes ClickHouse#124177 Co-Authored-By: Claude Opus 5.5 <[email protected]>
pfcoperez
added a commit
to PeerDB-io/peerdb
that referenced
this pull request
Nov 5, 2026
Previous PR #4303 reduced the scope of some e2e tests that were affected by ClickHouse/ClickHouse#105021 regression in ClickHouse. This regression has since then been fixed through ClickHouse/ClickHouse#105029 Hence, this follow-up PR reverts the workaround in the e2e tests, restoring their original coverage.
pfcoperez
added a commit
to PeerDB-io/peerdb
that referenced
this pull request
Nov 5, 2026
Previous PR #4303 reduced the scope of some e2e tests that were affected by ClickHouse/ClickHouse#105021 regression in ClickHouse. This regression has since then been fixed through ClickHouse/ClickHouse#105029 Hence, this follow-up PR reverts the workaround in the e2e tests, restoring their original coverage. Closes: https://linear.app/clickhouse/issue/DBI-738
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix silent data loss after
EXCHANGE TABLESorCREATE OR REPLACE TABLEof a materialized view's source table. TheMV's source-view dependency edge is now kept on the original name so it continues to fire on inserts. Regression introduced by #98779; restores the pre-regression behavior.Description
Closes #105021.
EXCHANGE TABLES a, b(and the synthetic exchange used byCREATE OR REPLACE TABLE/REPLACE TABLE) cross-swapped the source-sideview_dependenciesedges along with the data. TheMV's storedselect_table_idis not rewritten by the rename, so cross-swapping orphaned theMV:INSERT INTO aafter exchange found no dependents — the edge had been moved tob.INSERT INTO bwas rejected byInsertDependenciesBuilder::observePathbecause theMV's recorded source nameano longer matched the parentb.Both inserts silently dropped rows. Confirmed regression:
v26.4.2.10correct, master broken (since #98779).The fix keeps source-view edges keyed by the original name on
EXCHANGE. PlainRENAME TABLEkeeps the post-#98779 re-keying behavior used by01155_rename_move_materialized_view. This also subsumes the special case from #104907 — the syntheticCREATE OR REPLACEexchange routes through the sameexchange_tables=truebranch.Tests
04240_exchange_tables_drops_mv_source_dependencies— regression test for EXCHANGE TABLES with a materialized-view -- regression from #98779 #105021.04235_create_or_replace_source_table_view_dependencies— the test introduced in FixCREATE OR REPLACE TABLElosing source-side view dependencies #104907; passes with the unified fix.04241_rename_table_mv_source_dependencies— pins a pre-existing latent bug in plain same-databaseRENAME TABLE(silent data loss, alive-but-orphanedMV). Not a Fix assertion failure in view dependencies on DROP+CREATE MV #98779 regression. Out of scope for this PR; root cause shared with Views and materialized view definitions don't change when underlying tables are renamed #76303 and tracked there.Design note
This restores ClickHouse's pre-#98779 behavior, where the source-view edge follows the name on
EXCHANGE("option C": MV reads from whatever now lives at the name it was created against). This is a regression repair, not the long-term answer. A proper redesign — identity-boundMVwith atomicas_selectrewrite, like PostgreSQL handles the same problem — would fix this case, the plain-RENAMEcase (04241), and #76303 in one shot. That redesign belongs in a separate, larger change.Documentation entry for user-facing changes
Version info
26.5.1.747