ClickHouse/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_replacing_merge_tree.sql

199 lines
8.0 KiB
MySQL
Raw Normal View History

2019-03-26 14:39:22 +00:00
----- Group of very similar simple tests ------
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS zero_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
CREATE TABLE zero_rows_per_granule (
2019-03-26 14:39:22 +00:00
p Date,
k UInt64,
v1 UInt64,
v2 Int64
2019-03-26 16:41:11 +00:00
) ENGINE ReplacingMergeTree() PARTITION BY toYYYYMM(p) ORDER BY k
SETTINGS index_granularity_bytes=20, write_final_mark = 0,
2019-03-26 16:41:11 +00:00
enable_vertical_merge_algorithm=1,
vertical_merge_algorithm_min_rows_to_activate=0,
vertical_merge_algorithm_min_columns_to_activate=0;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO zero_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 2, 3000, 4000), ('2018-05-17', 3, 5000, 6000), ('2018-05-18', 4, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM zero_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'zero_rows_per_granule' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO zero_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 8, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
OPTIMIZE TABLE zero_rows_per_granule FINAL;
2019-03-26 16:41:11 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM zero_rows_per_granule FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT sum(marks) from system.parts WHERE table = 'zero_rows_per_granule' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS zero_rows_per_granule;
2019-03-26 14:39:22 +00:00
SELECT '-----';
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS two_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
CREATE TABLE two_rows_per_granule (
2019-03-26 14:39:22 +00:00
p Date,
k UInt64,
v1 UInt64,
v2 Int64
2019-03-26 16:41:11 +00:00
) ENGINE ReplacingMergeTree() PARTITION BY toYYYYMM(p) ORDER BY k
SETTINGS index_granularity_bytes=40, write_final_mark = 0,
2019-03-26 16:41:11 +00:00
enable_vertical_merge_algorithm=1,
vertical_merge_algorithm_min_rows_to_activate=0,
vertical_merge_algorithm_min_columns_to_activate=0;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO two_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 2, 3000, 4000), ('2018-05-17', 3, 5000, 6000), ('2018-05-18', 4, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM two_rows_per_granule FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'two_rows_per_granule' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO two_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 8, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
OPTIMIZE TABLE two_rows_per_granule FINAL;
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM two_rows_per_granule FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'two_rows_per_granule' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS two_rows_per_granule;
2019-03-26 14:39:22 +00:00
SELECT '-----';
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS four_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
CREATE TABLE four_rows_per_granule (
2019-03-26 14:39:22 +00:00
p Date,
k UInt64,
v1 UInt64,
v2 Int64
2019-03-26 16:41:11 +00:00
) ENGINE ReplacingMergeTree() PARTITION BY toYYYYMM(p) ORDER BY k
SETTINGS index_granularity_bytes = 110, write_final_mark = 0,
2019-03-26 16:41:11 +00:00
enable_vertical_merge_algorithm=1,
vertical_merge_algorithm_min_rows_to_activate=0,
vertical_merge_algorithm_min_columns_to_activate=0;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO four_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 2, 3000, 4000), ('2018-05-17', 3, 5000, 6000), ('2018-05-18', 4, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM four_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule' and database=currentDatabase() and active=1;
DETACH TABLE four_rows_per_granule;
ATTACH TABLE four_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO four_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 8, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO four_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 8, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO four_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 8, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO four_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 8, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-03-27 13:56:03 +00:00
SELECT sleep(0.5) Format Null;
2019-06-07 15:41:24 +00:00
OPTIMIZE TABLE four_rows_per_granule FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DETACH TABLE four_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
ATTACH TABLE four_rows_per_granule;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM four_rows_per_granule FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS four_rows_per_granule;
2019-03-26 14:39:22 +00:00
----- More interesting tests ------
SELECT '-----';
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS huge_granularity_small_blocks;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
CREATE TABLE huge_granularity_small_blocks (
2019-03-26 14:39:22 +00:00
p Date,
k UInt64,
v1 UInt64,
v2 Int64
2019-03-26 16:41:11 +00:00
) ENGINE ReplacingMergeTree() PARTITION BY toYYYYMM(p) ORDER BY k
SETTINGS index_granularity_bytes=1000000, write_final_mark = 0,
2019-03-26 16:41:11 +00:00
enable_vertical_merge_algorithm=1,
vertical_merge_algorithm_min_rows_to_activate=0,
vertical_merge_algorithm_min_columns_to_activate=0;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO huge_granularity_small_blocks (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 2, 3000, 4000), ('2018-05-17', 3, 5000, 6000), ('2018-05-18', 4, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM huge_granularity_small_blocks;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'huge_granularity_small_blocks' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO huge_granularity_small_blocks (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 8, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DETACH TABLE huge_granularity_small_blocks;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
ATTACH TABLE huge_granularity_small_blocks;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
OPTIMIZE TABLE huge_granularity_small_blocks FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM huge_granularity_small_blocks FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'huge_granularity_small_blocks' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS huge_granularity_small_blocks;
2019-03-26 14:39:22 +00:00
----- Some alter tests ----
SELECT '-----';
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
CREATE TABLE adaptive_granularity_alter (
2019-03-26 14:39:22 +00:00
p Date,
k UInt64,
v1 UInt64,
v2 Int64
2019-03-26 16:41:11 +00:00
) ENGINE ReplacingMergeTree() PARTITION BY toYYYYMM(p) ORDER BY k
SETTINGS index_granularity_bytes=110, write_final_mark = 0,
2019-03-26 16:41:11 +00:00
enable_vertical_merge_algorithm=1,
vertical_merge_algorithm_min_rows_to_activate=0,
vertical_merge_algorithm_min_columns_to_activate=0;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO adaptive_granularity_alter (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 2, 3000, 4000), ('2018-05-17', 3, 5000, 6000), ('2018-05-18', 4, 7000, 8000);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
ALTER TABLE adaptive_granularity_alter MODIFY COLUMN v1 Int16;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DETACH TABLE adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
ATTACH TABLE adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO adaptive_granularity_alter (p, k, v1, v2) VALUES ('2018-05-15', 5, 1000, 2000), ('2018-05-16', 6, 3000, 4000), ('2018-05-17', 7, 5000, 6000), ('2018-05-19', 42, 42, 42);
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
OPTIMIZE TABLE adaptive_granularity_alter FINAL;
2019-06-07 15:41:24 +00:00
SELECT COUNT(*) FROM adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
ALTER TABLE adaptive_granularity_alter MODIFY COLUMN v2 String;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DETACH TABLE adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
ATTACH TABLE adaptive_granularity_alter;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
INSERT INTO adaptive_granularity_alter (p, k, v1, v2) VALUES ('2018-05-15', 100, 1000, 'aaaa'), ('2018-05-16', 101, 3000, 'bbbb'), ('2018-05-17', 102, 5000, 'cccc'), ('2018-05-19', 103, 7000, 'dddd');
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
OPTIMIZE TABLE adaptive_granularity_alter FINAL;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT k, v2 FROM adaptive_granularity_alter WHERE k >= 100 OR k = 42;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter' and database=currentDatabase() and active=1;
2019-03-26 14:39:22 +00:00
2019-06-07 15:41:24 +00:00
DROP TABLE IF EXISTS adaptive_granularity_alter;