diff --git a/src/Interpreters/InterpreterSelectQueryAnalyzer.cpp b/src/Interpreters/InterpreterSelectQueryAnalyzer.cpp index 4f2f05dc7eb..8db1d27c073 100644 --- a/src/Interpreters/InterpreterSelectQueryAnalyzer.cpp +++ b/src/Interpreters/InterpreterSelectQueryAnalyzer.cpp @@ -135,6 +135,8 @@ QueryTreeNodePtr buildQueryTreeAndRunPasses(const ASTPtr & query, QueryTreePassManager query_tree_pass_manager(context); addQueryTreePasses(query_tree_pass_manager); + /// We should not apply any query tree level optimizations on shards + /// because it can lead to a changed header. if (select_query_options.ignore_ast_optimizations || context->getClientInfo().query_kind == ClientInfo::QueryKind::SECONDARY_QUERY) query_tree_pass_manager.run(query_tree, 1 /*up_to_pass_index*/);