fix reading of unneded column in case of multistage prewhere

This commit is contained in:
Anton Popov 2023-07-27 16:13:29 +00:00
parent d48b1cadb0
commit dfc06d2714
3 changed files with 31 additions and 2 deletions

View File

@ -340,8 +340,10 @@ MergeTreeReadTaskColumns getReadTaskColumns(
if (!columns_from_previous_steps.contains(name))
step_column_names.push_back(name);
injectRequiredColumns(
data_part_info_for_reader, storage_snapshot, with_subcolumns, step_column_names);
if (!step_column_names.empty())
injectRequiredColumns(
data_part_info_for_reader, storage_snapshot,
with_subcolumns, step_column_names);
/// More columns could have been added, filter them as well by the list of columns from previous steps.
Names columns_to_read_in_step;

View File

@ -0,0 +1,2 @@
10496500
4

View File

@ -0,0 +1,25 @@
-- Tags: no-parallel, no-random-settings, no-random-merge-tree-settings
drop table if exists t_multi_prewhere;
drop row policy if exists policy_02834 on t_multi_prewhere;
create table t_multi_prewhere (a UInt64, b UInt64, c UInt8)
engine = MergeTree order by tuple()
settings min_bytes_for_wide_part = 0;
create row policy policy_02834 on t_multi_prewhere using a > 2000 as permissive to all;
insert into t_multi_prewhere select number, number, number from numbers(10000);
system drop mark cache;
select sum(b) from t_multi_prewhere prewhere a < 5000;
system flush logs;
select ProfileEvents['FileOpen'] from system.query_log
where
type = 'QueryFinish'
and current_database = currentDatabase()
and query ilike '%select sum(b) from t_multi_prewhere prewhere a < 5000%';
drop table if exists t_multi_prewhere;
drop row policy if exists policy_02834 on t_multi_prewhere;