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

@ -1043,6 +1043,10 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r
}
/// Filter in WHERE instead
else
{
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<DataTypeUInt8>(), "");
@ -1050,5 +1054,6 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r
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;