2020-10-22 06:18:10 +00:00
|
|
|
drop table if exists xy;
|
|
|
|
|
2020-11-08 09:11:02 +00:00
|
|
|
create table xy(x int, y int) engine MergeTree partition by intHash64(x) % 2 order by y settings index_granularity = 1;
|
2020-10-22 06:18:10 +00:00
|
|
|
|
2020-11-08 09:11:02 +00:00
|
|
|
-- intHash64(0) % 2 = 0
|
|
|
|
-- intHash64(2) % 2 = 1
|
|
|
|
-- intHash64(8) % 2 = 0
|
|
|
|
-- intHash64(9) % 2 = 1
|
|
|
|
insert into xy values (0, 2), (2, 3), (8, 4), (9, 5);
|
2020-10-22 06:18:10 +00:00
|
|
|
|
2020-11-08 09:11:02 +00:00
|
|
|
-- Now we have two partitions: 0 and 1, each of which contains 2 values.
|
|
|
|
-- minmax index for the first partition is 0 <= x <= 8
|
|
|
|
-- minmax index for the second partition is 2 <= x <= 9
|
2020-10-22 06:18:10 +00:00
|
|
|
|
2020-11-08 09:11:02 +00:00
|
|
|
SET max_rows_to_read = 2;
|
2020-10-22 06:18:10 +00:00
|
|
|
|
2020-11-08 09:11:02 +00:00
|
|
|
select * from xy where intHash64(x) % 2 = intHash64(2) % 2;
|
2020-11-06 03:50:58 +00:00
|
|
|
|
2020-11-08 09:11:02 +00:00
|
|
|
-- Equality is another special operator that can be treated as an always monotonic indicator for deterministic functions.
|
|
|
|
-- minmax index is not enough.
|
|
|
|
select * from xy where x = 8;
|
2020-11-08 06:21:58 +00:00
|
|
|
|
2020-10-22 06:18:10 +00:00
|
|
|
drop table if exists xy;
|
2020-11-09 12:31:51 +00:00
|
|
|
|
|
|
|
-- Test if we provide enough columns to generate a partition value
|
|
|
|
drop table if exists xyz;
|
|
|
|
create table xyz(x int, y int, z int) engine MergeTree partition by if(toUInt8(x), y, z) order by x settings index_granularity = 1;
|
|
|
|
insert into xyz values (1, 2, 3);
|
|
|
|
select * from xyz where y = 2;
|
|
|
|
drop table if exists xyz;
|