diff --git a/src/Interpreters/InterpreterInsertQuery.cpp b/src/Interpreters/InterpreterInsertQuery.cpp index 237146a6321..6e4efdc5167 100644 --- a/src/Interpreters/InterpreterInsertQuery.cpp +++ b/src/Interpreters/InterpreterInsertQuery.cpp @@ -228,6 +228,11 @@ Chain InterpreterInsertQuery::buildChainImpl( ThreadStatusesHolderPtr thread_status_holder, std::atomic_uint64_t * elapsed_counter_ms) { + ThreadStatus * thread_status = current_thread; + + if (!thread_status_holder) + thread_status = nullptr; + auto context_ptr = getContext(); const ASTInsertQuery * query = nullptr; if (query_ptr) @@ -247,7 +252,7 @@ Chain InterpreterInsertQuery::buildChainImpl( if (table->noPushingToViews() && !no_destination) { auto sink = table->write(query_ptr, metadata_snapshot, context_ptr); - sink->setRuntimeData(current_thread, elapsed_counter_ms); + sink->setRuntimeData(thread_status, elapsed_counter_ms); out.addSource(std::move(sink)); } else @@ -290,7 +295,7 @@ Chain InterpreterInsertQuery::buildChainImpl( table_prefers_large_blocks ? settings.min_insert_block_size_bytes : 0)); } - auto counting = std::make_shared(out.getInputHeader(), current_thread, getContext()->getQuota()); + auto counting = std::make_shared(out.getInputHeader(), thread_status, getContext()->getQuota()); counting->setProcessListElement(context_ptr->getProcessListElement()); out.addSource(std::move(counting)); diff --git a/src/Processors/Transforms/buildPushingToViewsChain.cpp b/src/Processors/Transforms/buildPushingToViewsChain.cpp index 6203c85056a..ea088c45471 100644 --- a/src/Processors/Transforms/buildPushingToViewsChain.cpp +++ b/src/Processors/Transforms/buildPushingToViewsChain.cpp @@ -199,8 +199,13 @@ Chain buildPushingToViewsChain( checkStackSize(); Chain result_chain; + ThreadStatus * thread_status = current_thread; + if (!thread_status_holder) + { thread_status_holder = std::make_shared(); + thread_status = nullptr; + } /// If we don't write directly to the destination /// then expect that we're inserting with precalculated virtual columns @@ -409,13 +414,13 @@ Chain buildPushingToViewsChain( if (auto * live_view = dynamic_cast(storage.get())) { auto sink = std::make_shared(live_view_header, *live_view, storage, context); - sink->setRuntimeData(current_thread, elapsed_counter_ms); + sink->setRuntimeData(thread_status, elapsed_counter_ms); result_chain.addSource(std::move(sink)); } else if (auto * window_view = dynamic_cast(storage.get())) { auto sink = std::make_shared(window_view->getInputHeader(), *window_view, storage, context); - sink->setRuntimeData(current_thread, elapsed_counter_ms); + sink->setRuntimeData(thread_status, elapsed_counter_ms); result_chain.addSource(std::move(sink)); } /// Do not push to destination table if the flag is set @@ -423,7 +428,7 @@ Chain buildPushingToViewsChain( { auto sink = storage->write(query_ptr, metadata_snapshot, context); metadata_snapshot->check(sink->getHeader().getColumnsWithTypeAndName()); - sink->setRuntimeData(current_thread, elapsed_counter_ms); + sink->setRuntimeData(thread_status, elapsed_counter_ms); result_chain.addSource(std::move(sink)); }