From 2fb7f980ef1b9f80c37c3f68d9b939216924b715 Mon Sep 17 00:00:00 2001 From: Jordi Villar Date: Mon, 5 Feb 2024 10:16:07 +0100 Subject: [PATCH] Address PR comments --- .../Transforms/buildPushingToViewsChain.cpp | 26 +++++++++++++------ ...duplication_token_hierarchical_inserts.sql | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Processors/Transforms/buildPushingToViewsChain.cpp b/src/Processors/Transforms/buildPushingToViewsChain.cpp index 44c5234c00e..40f4166283b 100644 --- a/src/Processors/Transforms/buildPushingToViewsChain.cpp +++ b/src/Processors/Transforms/buildPushingToViewsChain.cpp @@ -303,8 +303,8 @@ Chain buildPushingToViewsChain( auto & target_name = runtime_stats->target_name; auto * view_counter_ms = &runtime_stats->elapsed_ms; - auto insert_settings = insert_context->getSettings(); - ContextMutablePtr new_insert_context = insert_context; + const auto & insert_settings = insert_context->getSettingsRef(); + ContextMutablePtr view_insert_context = insert_context; if (!disable_deduplication_for_children && insert_settings.update_insert_deduplication_token_in_dependent_materialized_views && @@ -321,6 +321,16 @@ Chain buildPushingToViewsChain( * * Here we want to avoid deduplication for two different blocks generated from `mv_2_1` and `mv_2_2` that will * be inserted into `ds_2_1`. + * + * We are forced to use view id instead of table id because there are some possible INSERT flows where no tables + * are involved. + * + * Example: + * + * landing -┬--> mv_1_1 --┬-> ds_1_1 + * | | + * └--> mv_1_2 --┘ + * */ auto insert_deduplication_token = insert_settings.insert_deduplication_token.value; @@ -329,8 +339,8 @@ Chain buildPushingToViewsChain( else insert_deduplication_token += "_" + view_id.getFullNameNotQuoted(); - new_insert_context = Context::createCopy(insert_context); - new_insert_context->setSetting("insert_deduplication_token", insert_deduplication_token); + view_insert_context = Context::createCopy(insert_context); + view_insert_context->setSetting("insert_deduplication_token", insert_deduplication_token); } if (auto * materialized_view = dynamic_cast(view.get())) @@ -400,7 +410,7 @@ Chain buildPushingToViewsChain( insert_columns.emplace_back(column.name); } - InterpreterInsertQuery interpreter(nullptr, new_insert_context, false, false, false); + InterpreterInsertQuery interpreter(nullptr, view_insert_context, false, false, false); out = interpreter.buildChain(inner_table, inner_metadata_snapshot, insert_columns, thread_status_holder, view_counter_ms); out.addStorageHolder(view); out.addStorageHolder(inner_table); @@ -410,7 +420,7 @@ Chain buildPushingToViewsChain( runtime_stats->type = QueryViewsLogElement::ViewType::LIVE; query = live_view->getInnerQuery(); // Used only to log in system.query_views_log out = buildPushingToViewsChain( - view, view_metadata_snapshot, new_insert_context, ASTPtr(), + view, view_metadata_snapshot, view_insert_context, ASTPtr(), /* no_destination= */ true, thread_status_holder, running_group, view_counter_ms, async_insert, storage_header); } @@ -419,13 +429,13 @@ Chain buildPushingToViewsChain( runtime_stats->type = QueryViewsLogElement::ViewType::WINDOW; query = window_view->getMergeableQuery(); // Used only to log in system.query_views_log out = buildPushingToViewsChain( - view, view_metadata_snapshot, new_insert_context, ASTPtr(), + view, view_metadata_snapshot, view_insert_context, ASTPtr(), /* no_destination= */ true, thread_status_holder, running_group, view_counter_ms, async_insert); } else out = buildPushingToViewsChain( - view, view_metadata_snapshot, new_insert_context, ASTPtr(), + view, view_metadata_snapshot, view_insert_context, ASTPtr(), /* no_destination= */ false, thread_status_holder, running_group, view_counter_ms, async_insert); diff --git a/tests/queries/0_stateless/02972_insert_deduplication_token_hierarchical_inserts.sql b/tests/queries/0_stateless/02972_insert_deduplication_token_hierarchical_inserts.sql index 31c860cc5d0..c033b500e14 100644 --- a/tests/queries/0_stateless/02972_insert_deduplication_token_hierarchical_inserts.sql +++ b/tests/queries/0_stateless/02972_insert_deduplication_token_hierarchical_inserts.sql @@ -151,4 +151,4 @@ DROP TABLE landing_fix; DROP TABLE ds_1_1_fix; DROP VIEW mv_1_1; -DROP VIEW mv_1_2; \ No newline at end of file +DROP VIEW mv_1_2;