Repository navigation
Conversation
`InterpreterRenameQuery::executeToTables` cross-swaps the harvested `from_dependent_views` and `to_dependent_views` after the physical rename, which is correct for `EXCHANGE TABLES a, b` (both tables persist, edges follow data). `doCreateOrReplaceTable` routes both `CREATE OR REPLACE TABLE` and `REPLACE TABLE` through the same rename interpreter, but the displaced table is dropped immediately afterwards — so the cross-swap pins the source-view edges to the soon-to-be-dropped table and the new occupant of the name ends up with `system.tables.dependencies_table` empty. `InsertDependenciesBuilder` then visits no MVs on the next insert and rows are silently lost. Tag the synthetic rename built by `doCreateOrReplaceTable` with a new `ASTRenameQuery::is_create_or_replace` flag and, when set, restore each harvested dependent-view list onto the table id it came from instead of swapping them. `EXCHANGE TABLES a, b` keeps its existing semantics. Regression introduced in ClickHouse#98779
|
Workflow [PR], commit [ef11941] Summary: ❌
AI ReviewSummaryThis PR fixes a real correctness bug in Final Verdict✅ No blocking issues found in the current diff. |
LLVM Coverage Report
Changed lines: 100.00% (16/16) · Uncovered code |
There was a problem hiding this comment.
Not totally sure but by the symmetry it might have required different rollback according if (rename.is_create_or_replace) is true or not.
|
close in favor of #105029 |
`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-ClickHouse#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-ClickHouse#98779 re-keying behavior used by `01155_rename_move_materialized_view`. This also subsumes the special case from ClickHouse#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 ClickHouse#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 ClickHouse#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 ClickHouse#98779 regression; not fixed by this PR. Root cause shared with ClickHouse#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 ClickHouse#105021 Co-Authored-By: Philip Dubé <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
InterpreterRenameQuery::executeToTablescross-swaps the harvestedfrom_dependent_viewsandto_dependent_viewsafter the physical rename, which is correct forEXCHANGE TABLES a, b(both tables persist, edges follow data).doCreateOrReplaceTableroutes bothCREATE OR REPLACE TABLEandREPLACE TABLEthrough the same rename interpreter, but the displaced table is dropped immediately afterwards — so the cross-swap pins the source-view edges to the soon-to-be-dropped table and the new occupant of the name ends up withsystem.tables.dependencies_tableempty.InsertDependenciesBuilderthen visits no MVs on the next insert and rows are silently lost.Tag the synthetic rename built by
doCreateOrReplaceTablewith a newASTRenameQuery::is_create_or_replaceflag and, when set, restore each harvested dependent-view list onto the table id it came from instead of swapping them.EXCHANGE TABLES a, bkeeps its existing semantics.Regression introduced in #98779
Closes #104906
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
fix REPLACE TABLE dropping MV dependencies