From 70ec13f3d36293deb3695e3eacac5557c2056474 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Thu, 29 Apr 2021 19:40:14 +0800 Subject: [PATCH] Fix empty block with row_filter --- src/Storages/MergeTree/MergeTreeRangeReader.cpp | 5 ++++- .../01851_fix_row_policy_empty_result.reference | 0 .../01851_fix_row_policy_empty_result.sql | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/01851_fix_row_policy_empty_result.reference create mode 100644 tests/queries/0_stateless/01851_fix_row_policy_empty_result.sql diff --git a/src/Storages/MergeTree/MergeTreeRangeReader.cpp b/src/Storages/MergeTree/MergeTreeRangeReader.cpp index d373c004d10..0bd3d384cba 100644 --- a/src/Storages/MergeTree/MergeTreeRangeReader.cpp +++ b/src/Storages/MergeTree/MergeTreeRangeReader.cpp @@ -941,7 +941,10 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r auto columns = block.getColumns(); filterColumns(columns, row_level_filter); - block.setColumns(columns); + if (columns.empty()) + block = block.cloneEmpty(); + else + block.setColumns(columns); } prewhere_info->prewhere_actions->execute(block); diff --git a/tests/queries/0_stateless/01851_fix_row_policy_empty_result.reference b/tests/queries/0_stateless/01851_fix_row_policy_empty_result.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/01851_fix_row_policy_empty_result.sql b/tests/queries/0_stateless/01851_fix_row_policy_empty_result.sql new file mode 100644 index 00000000000..f28426bb651 --- /dev/null +++ b/tests/queries/0_stateless/01851_fix_row_policy_empty_result.sql @@ -0,0 +1,12 @@ +drop table if exists tbl; +create table tbl (s String, i int) engine MergeTree order by i; + +insert into tbl values ('123', 123); + +drop row policy if exists filter on tbl; +create row policy filter on tbl using (s = 'non_existing_domain') to all; + +select * from tbl prewhere s = '123' where i = 123; + +drop row policy filter on tbl; +drop table tbl;