mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-18 04:12:19 +00:00
Allow not in be used in partition pruning
This commit is contained in:
parent
9a652e6aba
commit
df86f8ed36
@ -543,6 +543,37 @@ BoolMask MergeTreeSetIndex::checkInRange(const std::vector<Range> & key_ranges,
|
|||||||
auto left_lower = std::lower_bound(indices.begin(), indices.end(), left_point, less);
|
auto left_lower = std::lower_bound(indices.begin(), indices.end(), left_point, less);
|
||||||
auto right_lower = std::lower_bound(indices.begin(), indices.end(), right_point, less);
|
auto right_lower = std::lower_bound(indices.begin(), indices.end(), right_point, less);
|
||||||
|
|
||||||
|
/// A special case of 1-element KeyRange. It's useful for partition pruning
|
||||||
|
bool one_element_range = true;
|
||||||
|
for (size_t i = 0; i < tuple_size; ++i)
|
||||||
|
{
|
||||||
|
auto & left = left_point[i];
|
||||||
|
auto & right = right_point[i];
|
||||||
|
if (left.getType() == right.getType())
|
||||||
|
{
|
||||||
|
if (left.getType() == ValueWithInfinity::NORMAL)
|
||||||
|
{
|
||||||
|
if (0 != left.getColumnIfFinite().compareAt(0, 0, right.getColumnIfFinite(), 1))
|
||||||
|
{
|
||||||
|
one_element_range = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
one_element_range = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (one_element_range)
|
||||||
|
{
|
||||||
|
if (left_lower != indices.end() && equals(*left_lower, left_point))
|
||||||
|
return {true, false};
|
||||||
|
else
|
||||||
|
return {false, true};
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
{
|
{
|
||||||
left_lower != right_lower
|
left_lower != right_lower
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
7
|
||||||
|
0 100
|
||||||
|
6 106
|
||||||
|
7 107
|
||||||
|
8 108
|
||||||
|
9 109
|
10
tests/queries/0_stateless/01891_not_in_partition_prune.sql
Normal file
10
tests/queries/0_stateless/01891_not_in_partition_prune.sql
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
drop table if exists test1;
|
||||||
|
|
||||||
|
create table test1 (i int, j int) engine MergeTree partition by i order by tuple() settings index_granularity = 1;
|
||||||
|
|
||||||
|
insert into test1 select number, number + 100 from numbers(10);
|
||||||
|
select count() from test1 where i not in (1,2,3);
|
||||||
|
set max_rows_to_read = 5;
|
||||||
|
select * from test1 where i not in (1,2,3,4,5) order by i;
|
||||||
|
|
||||||
|
drop table test1;
|
Loading…
Reference in New Issue
Block a user