diff --git a/src/Storages/MergeTree/MergeTreeRangeReader.cpp b/src/Storages/MergeTree/MergeTreeRangeReader.cpp index 2f6bc10e472..c5454f33c79 100644 --- a/src/Storages/MergeTree/MergeTreeRangeReader.cpp +++ b/src/Storages/MergeTree/MergeTreeRangeReader.cpp @@ -1044,10 +1044,15 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r /// Filter in WHERE instead else { - auto type = getSampleBlock().getByName(prewhere_info->prewhere_column_name).type; - ColumnWithTypeAndName col(result.getFilterHolder()->convertToFullColumnIfConst(), std::make_shared(), ""); - result.columns[prewhere_column_pos] = castColumn(col, type); - result.clearFilter(); // Acting as a flag to not filter in PREWHERE + if (prewhere_info->remove_prewhere_column) + result.columns.erase(result.columns.begin() + prewhere_column_pos); + else + { + auto type = getSampleBlock().getByName(prewhere_info->prewhere_column_name).type; + ColumnWithTypeAndName col(result.getFilterHolder()->convertToFullColumnIfConst(), std::make_shared(), ""); + result.columns[prewhere_column_pos] = castColumn(col, type); + result.clearFilter(); // Acting as a flag to not filter in PREWHERE + } } } diff --git a/tests/queries/0_stateless/02021_prewhere_always_true_where.reference b/tests/queries/0_stateless/02021_prewhere_always_true_where.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/02021_prewhere_always_true_where.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/02021_prewhere_always_true_where.sql b/tests/queries/0_stateless/02021_prewhere_always_true_where.sql new file mode 100644 index 00000000000..95dcb6a15c2 --- /dev/null +++ b/tests/queries/0_stateless/02021_prewhere_always_true_where.sql @@ -0,0 +1,5 @@ +drop table if exists data_02021; +create table data_02021 (key Int) engine=MergeTree() order by key; +insert into data_02021 values (1); +select count() from data_02021 prewhere 1 or ignore(key) where ignore(key)=0; +drop table data_02021;