From 60f0ed9296ab15c15b368f2de31b020b4933b139 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Mon, 25 Jun 2018 15:47:10 +0300 Subject: [PATCH] Added processing stage check for StorageMerge. [#CLICKHOUSE-3694] #2156 --- dbms/src/Storages/StorageMerge.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/dbms/src/Storages/StorageMerge.cpp b/dbms/src/Storages/StorageMerge.cpp index a6765290f6c..645aca7ac9f 100644 --- a/dbms/src/Storages/StorageMerge.cpp +++ b/dbms/src/Storages/StorageMerge.cpp @@ -171,11 +171,20 @@ BlockInputStreams StorageMerge::read( const ASTPtr & query = query_info.query; - /// If PREWHERE is used in query, you need to make sure that all tables support this. - if (typeid_cast(*query).prewhere_expression) - for (const auto & elem : selected_tables) + for (const auto & elem : selected_tables) + { + /// Check processing stage again in case new table was added after getQueryProcessingStage call. + auto stage = elem.first->getQueryProcessingStage(context); + if (stage != processed_stage) + throw Exception("Source tables for Merge table are processing data up to different stages", + ErrorCodes::INCOMPATIBLE_SOURCE_TABLES); + + /// If PREWHERE is used in query, you need to make sure that all tables support this. + if (typeid_cast(*query).prewhere_expression) if (!elem.first->supportsPrewhere()) - throw Exception("Storage " + elem.first->getName() + " doesn't support PREWHERE.", ErrorCodes::ILLEGAL_PREWHERE); + throw Exception("Storage " + elem.first->getName() + " doesn't support PREWHERE.", + ErrorCodes::ILLEGAL_PREWHERE); + } Block virtual_columns_block = getBlockWithVirtualColumns(selected_tables);