ClickHouse/tests/queries/0_stateless/01870_modulo_partition_key.sql

55 lines
2.3 KiB
MySQL
Raw Normal View History

2021-05-15 18:32:20 +00:00
SELECT 'simple partition key:';
2021-05-19 17:36:32 +00:00
DROP TABLE IF EXISTS table1 SYNC;
2021-05-15 18:32:20 +00:00
CREATE TABLE table1 (id Int64, v UInt64)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{database}/test_table12', '1', v)
2021-05-15 18:32:20 +00:00
PARTITION BY id % 200 ORDER BY id;
INSERT INTO table1 SELECT number-205, number FROM numbers(10);
INSERT INTO table1 SELECT number-205, number FROM numbers(400, 10);
2021-05-24 23:39:56 +00:00
SELECT toInt64(partition) as p FROM system.parts WHERE table='table1' and database=currentDatabase() ORDER BY p;
2021-05-21 14:56:36 +00:00
select 'where id % 200 = +-2:';
select id from table1 where id % 200 = 2 OR id % 200 = -2 order by id;
select 'where id % 200 > 0:';
2021-05-19 17:36:32 +00:00
select id from table1 where id % 200 > 0 order by id;
2021-05-21 14:56:36 +00:00
select 'where id % 200 < 0:';
2021-05-19 17:36:32 +00:00
select id from table1 where id % 200 < 0 order by id;
2021-05-15 18:32:20 +00:00
2021-05-16 09:20:59 +00:00
SELECT 'tuple as partition key:';
2021-05-15 18:32:20 +00:00
DROP TABLE IF EXISTS table2;
CREATE TABLE table2 (id Int64, v UInt64)
ENGINE = MergeTree()
PARTITION BY (toInt32(id / 2) % 3, id % 200) ORDER BY id;
INSERT INTO table2 SELECT number-205, number FROM numbers(10);
INSERT INTO table2 SELECT number-205, number FROM numbers(400, 10);
2021-05-24 23:39:56 +00:00
SELECT partition as p FROM system.parts WHERE table='table2' and database=currentDatabase() ORDER BY p;
2021-05-15 18:32:20 +00:00
2021-05-16 09:20:59 +00:00
SELECT 'recursive modulo partition key:';
DROP TABLE IF EXISTS table3;
CREATE TABLE table3 (id Int64, v UInt64)
ENGINE = MergeTree()
PARTITION BY (id % 200, (id % 200) % 10, toInt32(round((id % 200) / 2, 0))) ORDER BY id;
INSERT INTO table3 SELECT number-205, number FROM numbers(10);
INSERT INTO table3 SELECT number-205, number FROM numbers(400, 10);
2021-05-24 23:39:56 +00:00
SELECT partition as p FROM system.parts WHERE table='table3' and database=currentDatabase() ORDER BY p;
2021-05-16 09:20:59 +00:00
DETACH TABLE table3;
ATTACH TABLE table3;
2021-05-22 16:19:56 +00:00
SELECT 'After detach:';
2021-05-24 23:39:56 +00:00
SELECT partition as p FROM system.parts WHERE table='table3' and database=currentDatabase() ORDER BY p;
SELECT 'Indexes:';
DROP TABLE IF EXISTS table4;
CREATE TABLE table4 (id Int64, v UInt64, s String,
INDEX a (id * 2, s) TYPE minmax GRANULARITY 3
) ENGINE = MergeTree() PARTITION BY id % 10 ORDER BY v;
INSERT INTO table4 SELECT number, number, toString(number) FROM numbers(1000);
SELECT count() FROM table4 WHERE id % 10 = 7;
2021-05-16 09:20:59 +00:00
2021-05-15 18:32:20 +00:00
SELECT 'comparison:';
2021-05-16 09:20:59 +00:00
SELECT v, v-205 as vv, modulo(vv, 200), moduloLegacy(vv, 200) FROM table1 ORDER BY v;
2021-05-15 18:32:20 +00:00
DROP TABLE table1 SYNC;
DROP TABLE table2 SYNC;
DROP TABLE table3 SYNC;
DROP TABLE table4 SYNC;