Skip to content

Commit 5703e09

Browse files
committed
Analyzer: fix 01019_alter_materialized_view_consistent
1 parent f1c7665 commit 5703e09

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/Processors/Transforms/buildPushingToViewsChain.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,20 @@ Chain buildPushingToViewsChain(
319319
StoragePtr inner_table = materialized_view->getTargetTable();
320320
auto inner_table_id = inner_table->getStorageID();
321321
auto inner_metadata_snapshot = inner_table->getInMemoryMetadataPtr();
322-
query = view_metadata_snapshot->getSelectQuery().inner_query;
322+
323+
const auto & select_query = view_metadata_snapshot->getSelectQuery();
324+
if (select_query.select_table_id != table_id)
325+
{
326+
/// It may happen if materialize view query was changed and it doesn't depend on this source table anymore.
327+
/// See setting `allow_experimental_alter_materialized_view_structure`
328+
LOG_DEBUG(
329+
&Poco::Logger::get("PushingToViews"), "Table '{}' is not a source for view '{}' anymore, current source is '{}'",
330+
select_query.select_table_id.getFullTableName(), view_id.getFullTableName(), table_id);
331+
continue;
332+
}
333+
334+
query = select_query.inner_query;
335+
323336
target_name = inner_table_id.getFullTableName();
324337

325338
Block header;
@@ -493,7 +506,8 @@ static QueryPipeline process(Block block, ViewRuntimeData & view, const ViewsDat
493506
pipeline = interpreter.buildQueryPipeline();
494507
}
495508
else
496-
{ InterpreterSelectQuery interpreter(view.query, local_context, SelectQueryOptions());
509+
{
510+
InterpreterSelectQuery interpreter(view.query, local_context, SelectQueryOptions());
497511
pipeline = interpreter.buildQueryPipeline();
498512
}
499513

src/Storages/StorageMaterializedView.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ void StorageMaterializedView::alter(
283283
const auto & old_select = old_metadata.getSelectQuery();
284284

285285
DatabaseCatalog::instance().updateViewDependency(old_select.select_table_id, table_id, new_select.select_table_id, table_id);
286-
287-
new_metadata.setSelectQuery(new_select);
288286
}
289287
/// end modify query
290288

tests/analyzer_tech_debt.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,3 @@
8686
02815_range_dict_no_direct_join
8787
02845_threads_count_in_distributed_queries
8888
02861_join_on_nullsafe_compare
89-
01019_alter_materialized_view_consistent

0 commit comments

Comments
 (0)