From 7041e2807794b7247cc55f5d17428e76aeffc480 Mon Sep 17 00:00:00 2001 From: CurtizJ Date: Fri, 14 Feb 2020 00:16:40 +0300 Subject: [PATCH] fix segfault in MergeTreeRangeReader --- dbms/src/Storages/MergeTree/MergeTreeRangeReader.cpp | 2 +- .../01079_new_range_reader_segfault.reference | 1 + .../0_stateless/01079_new_range_reader_segfault.sql | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.reference create mode 100644 dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.sql diff --git a/dbms/src/Storages/MergeTree/MergeTreeRangeReader.cpp b/dbms/src/Storages/MergeTree/MergeTreeRangeReader.cpp index 56e5cfdb3d2..cd458669d81 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeRangeReader.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeRangeReader.cpp @@ -333,8 +333,8 @@ void MergeTreeRangeReader::ReadResult::optimize() filter_holder_original = std::move(filter_holder); filter = new_filter.get(); filter_holder = std::move(new_filter); + need_filter = true; } - need_filter = true; } /// Another guess, if it's worth filtering at PREWHERE else if (countBytesInResultFilter(filter->getData()) < 0.6 * filter->size()) diff --git a/dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.reference b/dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.reference new file mode 100644 index 00000000000..257cc5642cb --- /dev/null +++ b/dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.reference @@ -0,0 +1 @@ +foo diff --git a/dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.sql b/dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.sql new file mode 100644 index 00000000000..35de0d0b1df --- /dev/null +++ b/dbms/tests/queries/0_stateless/01079_new_range_reader_segfault.sql @@ -0,0 +1,11 @@ +drop table if exists t; + +create table t (a Int) engine = MergeTree order by a; + +-- some magic to satisfy conditions to run optimizations in MergeTreeRangeReader +insert into t select number < 10 ? 0 : 1 from numbers(50); +alter table t add column s String default 'foo'; + +select s from t prewhere a != 1 where rand() % 2 = 0 limit 1; + +drop table t;