mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Merge pull request #9612 from CurtizJ/fix-range-reader
Fix MergeTreeRangeReader
This commit is contained in:
commit
dc9725a757
@ -317,6 +317,9 @@ void MergeTreeRangeReader::ReadResult::optimize(bool can_read_incomplete_granule
|
||||
}
|
||||
num_rows_to_skip_in_last_granule += rows_per_granule_original.back() - rows_per_granule.back();
|
||||
|
||||
filter_original = filter;
|
||||
filter_holder_original = std::move(filter_holder);
|
||||
|
||||
/// Check if const 1 after shrink
|
||||
if (countBytesInResultFilter(filter->getData()) + total_zero_rows_in_tails == total_rows_per_granule)
|
||||
{
|
||||
@ -333,12 +336,10 @@ void MergeTreeRangeReader::ReadResult::optimize(bool can_read_incomplete_granule
|
||||
collapseZeroTails(filter->getData(), new_data);
|
||||
total_rows_per_granule = new_filter->size();
|
||||
num_rows = total_rows_per_granule;
|
||||
filter_original = filter;
|
||||
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())
|
||||
@ -631,7 +632,7 @@ MergeTreeRangeReader::ReadResult MergeTreeRangeReader::read(size_t max_rows, Mar
|
||||
if (read_result.need_filter)
|
||||
{
|
||||
auto old_columns = block_before_prewhere.getColumns();
|
||||
filterColumns(old_columns, read_result.getFilter()->getData());
|
||||
filterColumns(old_columns, read_result.getFilterOriginal()->getData());
|
||||
block_before_prewhere.setColumns(std::move(old_columns));
|
||||
}
|
||||
|
||||
@ -875,7 +876,7 @@ void MergeTreeRangeReader::executePrewhereActionsAndFilterColumns(ReadResult & r
|
||||
if (result.getFilter())
|
||||
{
|
||||
/// filter might be shrinked while columns not
|
||||
auto result_filter = result.getFilterOriginal() ? result.getFilterOriginal() : result.getFilter();
|
||||
auto result_filter = result.getFilterOriginal();
|
||||
filterColumns(result.columns, result_filter->getData());
|
||||
result.need_filter = true;
|
||||
|
||||
|
@ -144,7 +144,7 @@ public:
|
||||
/// The number of bytes read from disk.
|
||||
size_t numBytesRead() const { return num_bytes_read; }
|
||||
/// Filter you need to apply to newly-read columns in order to add them to block.
|
||||
const ColumnUInt8 * getFilterOriginal() const { return filter_original; }
|
||||
const ColumnUInt8 * getFilterOriginal() const { return filter_original ? filter_original : filter; }
|
||||
const ColumnUInt8 * getFilter() const { return filter; }
|
||||
ColumnPtr & getFilterHolder() { return filter_holder; }
|
||||
|
||||
|
@ -0,0 +1,3 @@
|
||||
foo
|
||||
foo
|
||||
foo
|
@ -0,0 +1,17 @@
|
||||
drop table if exists t;
|
||||
|
||||
create table t (id UInt32, a Int) engine = MergeTree order by id;
|
||||
|
||||
insert into t values (1, 0) (2, 1) (3, 0) (4, 0) (5, 0);
|
||||
alter table t add column s String default 'foo';
|
||||
select s from t prewhere a = 1;
|
||||
|
||||
drop table t;
|
||||
|
||||
create table t (id UInt32, a Int) engine = MergeTree order by id;
|
||||
|
||||
insert into t values (1, 1) (2, 1) (3, 0) (4, 0) (5, 0);
|
||||
alter table t add column s String default 'foo';
|
||||
select s from t prewhere a = 1;
|
||||
|
||||
drop table t;
|
Loading…
Reference in New Issue
Block a user