Fix PREWHERE with WHERE in case of always true PREWHERE

This commit is contained in:
Azat Khuzhin 2021-10-22 00:12:30 +03:00
parent b0f05f82b9
commit 16cd70aee9
3 changed files with 15 additions and 4 deletions

View File

@ -1044,10 +1044,15 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r
/// Filter in WHERE instead /// Filter in WHERE instead
else else
{ {
auto type = getSampleBlock().getByName(prewhere_info->prewhere_column_name).type; if (prewhere_info->remove_prewhere_column)
ColumnWithTypeAndName col(result.getFilterHolder()->convertToFullColumnIfConst(), std::make_shared<DataTypeUInt8>(), ""); result.columns.erase(result.columns.begin() + prewhere_column_pos);
result.columns[prewhere_column_pos] = castColumn(col, type); else
result.clearFilter(); // Acting as a flag to not filter in PREWHERE {
auto type = getSampleBlock().getByName(prewhere_info->prewhere_column_name).type;
ColumnWithTypeAndName col(result.getFilterHolder()->convertToFullColumnIfConst(), std::make_shared<DataTypeUInt8>(), "");
result.columns[prewhere_column_pos] = castColumn(col, type);
result.clearFilter(); // Acting as a flag to not filter in PREWHERE
}
} }
} }

View File

@ -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;