diff --git a/src/Storages/StorageMerge.cpp b/src/Storages/StorageMerge.cpp index 9891340a0d0..c68e9103704 100644 --- a/src/Storages/StorageMerge.cpp +++ b/src/Storages/StorageMerge.cpp @@ -520,6 +520,8 @@ QueryPipelineBuilderPtr ReadFromMerge::createSources( modified_select.setFinal(); } + modified_select.replaceDatabaseAndTable(database_name, table_name); + auto storage_stage = storage->getQueryProcessingStage(modified_context, QueryProcessingStage::Complete, storage_snapshot, modified_query_info); if (processed_stage <= storage_stage) @@ -545,6 +547,12 @@ QueryPipelineBuilderPtr ReadFromMerge::createSources( } else { + { + /// Analyze query to check that types are valid (e.g. in PREWHERE). + InterpreterSelectQuery interpreter + (modified_query_info.query, modified_context, SelectQueryOptions(processed_stage).ignoreProjections()); + } + storage->read( plan, real_column_names, @@ -569,8 +577,6 @@ QueryPipelineBuilderPtr ReadFromMerge::createSources( } else if (processed_stage > storage_stage) { - modified_select.replaceDatabaseAndTable(database_name, table_name); - /// Maximum permissible parallelism is streams_num modified_context->setSetting("max_threads", streams_num); modified_context->setSetting("max_streams_to_max_threads_ratio", 1); diff --git a/tests/queries/0_stateless/01902_table_function_merge_db_repr.sql b/tests/queries/0_stateless/01902_table_function_merge_db_repr.sql index 460ce16ccad..ee6f052d694 100644 --- a/tests/queries/0_stateless/01902_table_function_merge_db_repr.sql +++ b/tests/queries/0_stateless/01902_table_function_merge_db_repr.sql @@ -65,7 +65,7 @@ SELECT _database, _table, n FROM merge(currentDatabase(), '^t') ORDER BY _databa --fuzzed LOGICAL_ERROR CREATE TABLE 01902_db.t4 (n Date) ENGINE=MergeTree ORDER BY n; INSERT INTO 01902_db.t4 SELECT * FROM numbers(10); -SELECT NULL FROM 01902_db.t_merge WHERE n ORDER BY _table DESC; +SELECT NULL FROM 01902_db.t_merge WHERE n ORDER BY _table DESC; -- {serverError ILLEGAL_TYPE_OF_COLUMN_FOR_FILTER} DROP DATABASE 01902_db; DROP DATABASE 01902_db1;