From 15a14d6da2cb0922eff26c6a4710a4a10ac243c0 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 28 Jun 2021 23:08:18 +0300 Subject: [PATCH] Fix "No available columns" for Merge() storage --- src/Interpreters/TreeRewriter.cpp | 2 +- .../0_stateless/01931_storage_merge_no_columns.reference | 0 tests/queries/0_stateless/01931_storage_merge_no_columns.sql | 4 ++++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/01931_storage_merge_no_columns.reference create mode 100644 tests/queries/0_stateless/01931_storage_merge_no_columns.sql diff --git a/src/Interpreters/TreeRewriter.cpp b/src/Interpreters/TreeRewriter.cpp index 76093a14d45..fabd2cc5ef6 100644 --- a/src/Interpreters/TreeRewriter.cpp +++ b/src/Interpreters/TreeRewriter.cpp @@ -742,7 +742,7 @@ void TreeRewriterResult::collectUsedColumns(const ASTPtr & query, bool is_select if (!columns.empty()) required.insert(std::min_element(columns.begin(), columns.end())->name); - else + else if (!source_columns.empty()) /// If we have no information about columns sizes, choose a column of minimum size of its data type. required.insert(ExpressionActions::getSmallestColumn(source_columns)); } diff --git a/tests/queries/0_stateless/01931_storage_merge_no_columns.reference b/tests/queries/0_stateless/01931_storage_merge_no_columns.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01931_storage_merge_no_columns.sql b/tests/queries/0_stateless/01931_storage_merge_no_columns.sql new file mode 100644 index 00000000000..787316e299c --- /dev/null +++ b/tests/queries/0_stateless/01931_storage_merge_no_columns.sql @@ -0,0 +1,4 @@ +drop table if exists data; +create table data (key Int) engine=MergeTree() order by key; +select 1 from merge(currentDatabase(), '^data$') prewhere _table in (NULL); +drop table data;