From 858f07c7962fa69d8b699ff86c09bb3d9cdddd01 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 17 Jan 2021 12:38:44 +0300 Subject: [PATCH] Update comment for query AST cloning during inesrt into multiple local shards Refs: https://github.com/ClickHouse/ClickHouse/pull/18264#discussion_r558839456 --- src/Storages/Distributed/DistributedBlockOutputStream.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Storages/Distributed/DistributedBlockOutputStream.cpp b/src/Storages/Distributed/DistributedBlockOutputStream.cpp index 70e3ef0f17a..f5a2e48da14 100644 --- a/src/Storages/Distributed/DistributedBlockOutputStream.cpp +++ b/src/Storages/Distributed/DistributedBlockOutputStream.cpp @@ -352,7 +352,12 @@ DistributedBlockOutputStream::runWritingJob(DistributedBlockOutputStream::JobRep /// Forward user settings job.local_context = std::make_unique(context); - /// InterpreterInsertQuery is modifying the AST, but the same AST is also used to insert to remote shards. + /// Copying of the query AST is required to avoid race, + /// in case of INSERT into multiple local shards. + /// + /// Since INSERT into local node uses AST, + /// and InterpreterInsertQuery::execute() is modifying it, + /// to resolve tables (in InterpreterInsertQuery::getTable()) auto copy_query_ast = query_ast->clone(); InterpreterInsertQuery interp(copy_query_ast, *job.local_context);