diff --git a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_pk.sql b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_pk.sql index d1aa787bd07..a3163603719 100644 --- a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_pk.sql +++ b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_pk.sql @@ -6,7 +6,6 @@ CREATE TABLE test.pk (d Date DEFAULT '2000-01-01', x DateTime, y UInt64, z UInt6 INSERT INTO test.pk (x, y, z) VALUES (1, 11, 1235), (2, 11, 4395), (3, 22, 3545), (4, 22, 6984), (5, 33, 4596), (61, 11, 4563), (62, 11, 4578), (63, 11, 3572), (64, 22, 5786), (65, 22, 5786), (66, 22, 2791), (67, 22, 2791), (121, 33, 2791), (122, 33, 2791), (123, 33, 1235), (124, 44, 4935), (125, 44, 4578), (126, 55, 5786), (127, 55, 2791), (128, 55, 1235); -SET min_insert_block_size_rows = 0, min_insert_block_size_bytes = 0; SET max_block_size = 1; -- Test inferred limit @@ -30,6 +29,7 @@ SELECT toUInt32(x), y, z FROM test.pk WHERE x BETWEEN toDateTime(60) AND toDateT DROP TABLE test.pk; +SET max_block_size = 8192; SELECT '----00607----'; SET max_rows_to_read = 0; @@ -52,7 +52,6 @@ DROP TABLE test.merge_tree; SELECT '----00804----'; -SET max_rows_to_read = 0; DROP TABLE IF EXISTS test.large_alter_table; DROP TABLE IF EXISTS test.store_of_hash; @@ -60,7 +59,7 @@ CREATE TABLE test.large_alter_table ( somedate Date CODEC(ZSTD, ZSTD, ZSTD(12), LZ4HC(12)), id UInt64 CODEC(LZ4, ZSTD, NONE, LZ4HC), data String CODEC(ZSTD(2), LZ4HC, NONE, LZ4, LZ4) -) ENGINE = MergeTree() PARTITION BY somedate ORDER BY id SETTINGS index_granularity_bytes=19; +) ENGINE = MergeTree() PARTITION BY somedate ORDER BY id SETTINGS index_granularity_bytes=40; INSERT INTO test.large_alter_table SELECT toDate('2019-01-01'), number, toString(number + rand()) FROM system.numbers LIMIT 300000; @@ -82,4 +81,3 @@ SELECT COUNT(DISTINCT hash) FROM test.store_of_hash; DROP TABLE IF EXISTS test.large_alter_table; DROP TABLE IF EXISTS test.store_of_hash; - diff --git a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_replacing_merge_tree.sql b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_replacing_merge_tree.sql index 6cd00641f04..14d3a18a8c5 100644 --- a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_replacing_merge_tree.sql +++ b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity_replacing_merge_tree.sql @@ -90,14 +90,14 @@ INSERT INTO test.four_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 5, 1 INSERT INTO test.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); +SELECT sleep(0.5) Format Null; + OPTIMIZE TABLE test.four_rows_per_granule FINAL; DETACH TABLE test.four_rows_per_granule; ATTACH TABLE test.four_rows_per_granule; -SELECT sleep(1) Format Null; - SELECT COUNT(*) FROM test.four_rows_per_granule FINAL; SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule' and database='test' and active=1; diff --git a/dbms/tests/queries/0_stateless/00926_zookeeper_adaptive_index_granularity_replicated_merge_tree.reference b/dbms/tests/queries/0_stateless/00926_zookeeper_adaptive_index_granularity_replicated_merge_tree.reference new file mode 100644 index 00000000000..642f836c646 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00926_zookeeper_adaptive_index_granularity_replicated_merge_tree.reference @@ -0,0 +1,47 @@ +----HORIZONTAL MERGE TESTS---- +4 +4 +4 +4 +4 +4 +8 +8 +8 +8 +----- +4 +1 +4 +1 +1 +1 +8 +2 +8 +2 +----- +4 +1 +4 +1 +4 +1 +4 +1 +8 +1 +8 +1 +42 42 +100 aaaa +101 bbbb +102 cccc +103 dddd +2 +42 42 +100 aaaa +101 bbbb +102 cccc +103 dddd +2 diff --git a/dbms/tests/queries/0_stateless/00926_zookeeper_adaptive_index_granularity_replicated_merge_tree.sql b/dbms/tests/queries/0_stateless/00926_zookeeper_adaptive_index_granularity_replicated_merge_tree.sql new file mode 100644 index 00000000000..0ac96ce751b --- /dev/null +++ b/dbms/tests/queries/0_stateless/00926_zookeeper_adaptive_index_granularity_replicated_merge_tree.sql @@ -0,0 +1,198 @@ +----- Group of very similar simple tests ------ +select '----HORIZONTAL MERGE TESTS----'; +DROP TABLE IF EXISTS test.zero_rows_per_granule1; +DROP TABLE IF EXISTS test.zero_rows_per_granule2; + +CREATE TABLE test.zero_rows_per_granule1 ( + p Date, + k UInt64, + v1 UInt64, + v2 Int64 +) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/zero_rows_in_granule', '1') PARTITION BY toYYYYMM(p) ORDER BY k SETTINGS index_granularity_bytes = 20; + +CREATE TABLE test.zero_rows_per_granule2 ( + p Date, + k UInt64, + v1 UInt64, + v2 Int64 +) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/zero_rows_in_granule', '2') PARTITION BY toYYYYMM(p) ORDER BY k SETTINGS index_granularity_bytes = 20; + +INSERT INTO test.zero_rows_per_granule1 (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); + +SYSTEM SYNC REPLICA test.zero_rows_per_granule2; + +SELECT COUNT(*) FROM test.zero_rows_per_granule1; + +SELECT distinct(marks) from system.parts WHERE table = 'zero_rows_per_granule1' and database='test' and active=1; + +SELECT COUNT(*) FROM test.zero_rows_per_granule2; + +SELECT distinct(marks) from system.parts WHERE table = 'zero_rows_per_granule2' and database='test' and active=1; + +INSERT INTO test.zero_rows_per_granule2 (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); + +SELECT distinct(marks) from system.parts WHERE table = 'zero_rows_per_granule2' and database='test' and active=1; + +SELECT distinct(marks) from system.parts WHERE table = 'zero_rows_per_granule1' and database='test' and active=1; + +SELECT sleep(0.5) Format Null; + +OPTIMIZE TABLE test.zero_rows_per_granule2 FINAL; + +SYSTEM SYNC REPLICA test.zero_rows_per_granule1; + +SELECT COUNT(*) FROM test.zero_rows_per_granule2; + +SELECT distinct(marks) from system.parts WHERE table = 'zero_rows_per_granule2' and database='test' and active=1; + +SELECT COUNT(*) FROM test.zero_rows_per_granule1; + +SELECT distinct(marks) from system.parts WHERE table = 'zero_rows_per_granule1' and database='test' and active=1; + +DROP TABLE IF EXISTS test.zero_rows_per_granule1; +DROP TABLE IF EXISTS test.zero_rows_per_granule2; + +SELECT '-----'; + +DROP TABLE IF EXISTS test.four_rows_per_granule1; +DROP TABLE IF EXISTS test.four_rows_per_granule2; + +CREATE TABLE test.four_rows_per_granule1 ( + p Date, + k UInt64, + v1 UInt64, + v2 Int64 +) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/four_rows_in_granule', '1') PARTITION BY toYYYYMM(p) ORDER BY k SETTINGS index_granularity_bytes = 110; + +CREATE TABLE test.four_rows_per_granule2 ( + p Date, + k UInt64, + v1 UInt64, + v2 Int64 +) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/four_rows_in_granule', '2') PARTITION BY toYYYYMM(p) ORDER BY k SETTINGS index_granularity_bytes = 110; + +INSERT INTO test.four_rows_per_granule1 (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); + +SELECT COUNT(*) FROM test.four_rows_per_granule1; + +SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule1' and database='test' and active=1; + +SYSTEM SYNC REPLICA test.four_rows_per_granule2; + +SELECT COUNT(*) FROM test.four_rows_per_granule2; + +SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule2' and database='test' and active=1; + +DETACH TABLE test.four_rows_per_granule2; +ATTACH TABLE test.four_rows_per_granule2; + +INSERT INTO test.four_rows_per_granule2 (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); + +SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule2' and database='test' and active=1; + +SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule1' and database='test' and active=1; + +SELECT sleep(0.5) Format Null; + +OPTIMIZE TABLE test.four_rows_per_granule2 FINAL; + +DETACH TABLE test.four_rows_per_granule2; + +ATTACH TABLE test.four_rows_per_granule2; + +SELECT COUNT(*) FROM test.four_rows_per_granule2; + +SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule2' and database='test' and active=1; + +SYSTEM SYNC REPLICA test.four_rows_per_granule1; + +SELECT COUNT(*) FROM test.four_rows_per_granule1; + +SELECT distinct(marks) from system.parts WHERE table = 'four_rows_per_granule1' and database='test' and active=1; + +DROP TABLE IF EXISTS test.four_rows_per_granule1; +DROP TABLE IF EXISTS test.four_rows_per_granule2; + +SELECT '-----'; + +DROP TABLE IF EXISTS test.adaptive_granularity_alter1; +DROP TABLE IF EXISTS test.adaptive_granularity_alter2; + +CREATE TABLE test.adaptive_granularity_alter1 ( + p Date, + k UInt64, + v1 UInt64, + v2 Int64 +) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/adaptive_granularity_alter', '1') PARTITION BY toYYYYMM(p) ORDER BY k SETTINGS index_granularity_bytes = 110; + +CREATE TABLE test.adaptive_granularity_alter2 ( + p Date, + k UInt64, + v1 UInt64, + v2 Int64 +) ENGINE ReplicatedMergeTree('/clickhouse/tables/test/adaptive_granularity_alter', '2') PARTITION BY toYYYYMM(p) ORDER BY k SETTINGS index_granularity_bytes = 110; + +INSERT INTO test.adaptive_granularity_alter1 (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); + +SELECT COUNT(*) FROM test.adaptive_granularity_alter1; + +SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter1' and database='test' and active=1; + +SYSTEM SYNC REPLICA test.adaptive_granularity_alter2; + +SELECT COUNT(*) FROM test.adaptive_granularity_alter2; + +SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter2' and database='test' and active=1; + +ALTER TABLE test.adaptive_granularity_alter2 MODIFY COLUMN v1 Int16; + +DETACH TABLE test.adaptive_granularity_alter2; + +ATTACH TABLE test.adaptive_granularity_alter2; + +SELECT COUNT(*) FROM test.adaptive_granularity_alter2; + +SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter2' and database='test' and active=1; + +SYSTEM SYNC REPLICA test.adaptive_granularity_alter1; + +SELECT COUNT(*) FROM test.adaptive_granularity_alter1; + +SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter1' and database='test' and active=1; + +INSERT INTO test.adaptive_granularity_alter1 (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 5, 3000, 4000), ('2018-05-17', 6, 5000, 6000), ('2018-05-19', 42, 42, 42); + +SELECT COUNT(*) FROM test.adaptive_granularity_alter1; + +SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter1' and database='test' and active=1; + +SYSTEM SYNC REPLICA test.adaptive_granularity_alter2; + +SELECT COUNT(*) FROM test.adaptive_granularity_alter2; + +SELECT distinct(marks) from system.parts WHERE table = 'adaptive_granularity_alter2' and database='test' and active=1; + +ALTER TABLE test.adaptive_granularity_alter1 MODIFY COLUMN v2 String; + +DETACH TABLE test.adaptive_granularity_alter1; + +ATTACH TABLE test.adaptive_granularity_alter1; + +INSERT INTO test.adaptive_granularity_alter1 (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'); + +SELECT sleep(0.5) Format Null; + +OPTIMIZE TABLE test.adaptive_granularity_alter1 FINAL; + +SELECT k, v2 FROM test.adaptive_granularity_alter1 WHERE k >= 100 OR k = 42; + +SELECT sum(marks) from system.parts WHERE table = 'adaptive_granularity_alter1' and database='test' and active=1; + +SYSTEM SYNC REPLICA test.adaptive_granularity_alter2; + +SELECT k, v2 FROM test.adaptive_granularity_alter2 WHERE k >= 100 OR k = 42; + +SELECT sum(marks) from system.parts WHERE table = 'adaptive_granularity_alter2' and database='test' and active=1; + +DROP TABLE IF EXISTS test.adaptive_granularity_alter1; +DROP TABLE IF EXISTS test.adaptive_granularity_alter2;