From 52974170503b2d2109f3f04509ad2dceb1d668b0 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sat, 14 Nov 2020 01:56:25 +0300 Subject: [PATCH] Fix Merge(Distributed()) with JOIN --- src/Storages/StorageMerge.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Storages/StorageMerge.cpp b/src/Storages/StorageMerge.cpp index 3e6f99878a6..d569007637d 100644 --- a/src/Storages/StorageMerge.cpp +++ b/src/Storages/StorageMerge.cpp @@ -134,6 +134,18 @@ bool StorageMerge::mayBenefitFromIndexForIn(const ASTPtr & left_in_operand, cons QueryProcessingStage::Enum StorageMerge::getQueryProcessingStage(const Context & context, QueryProcessingStage::Enum to_stage, SelectQueryInfo & query_info) const { + ASTPtr modified_query = query_info.query->clone(); + auto & modified_select = modified_query->as(); + /// In case of JOIN the first stage (which includes JOIN) + /// should be done on the initiator always. + /// + /// Since in case of JOIN query on shards will receive query w/o JOIN (and their columns). + /// (see modifySelect()/removeJoin()) + /// + /// And for this we need to return FetchColumns. + if (removeJoin(modified_select)) + return QueryProcessingStage::FetchColumns; + auto stage_in_source_tables = QueryProcessingStage::FetchColumns; DatabaseTablesIteratorPtr iterator = getDatabaseIterator(context);