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;