2021-09-12 12:35:27 +00:00
|
|
|
-- Tags: replica
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE IF EXISTS parallel_replicas;
|
|
|
|
DROP TABLE IF EXISTS parallel_replicas_backup;
|
2015-07-13 13:25:56 +00:00
|
|
|
|
2022-06-23 08:37:52 +00:00
|
|
|
set allow_deprecated_syntax_for_merge_tree=1;
|
2019-04-16 14:13:13 +00:00
|
|
|
CREATE TABLE parallel_replicas (d Date DEFAULT today(), x UInt32, u UInt64, s String) ENGINE = MergeTree(d, cityHash64(u, s), (x, d, cityHash64(u, s)), 8192);
|
|
|
|
INSERT INTO parallel_replicas (x, u, s) VALUES (1, 2, 'A'),(3, 4, 'B'),(5, 6, 'C'),(7, 8, 'D'),(9,10,'E');
|
|
|
|
INSERT INTO parallel_replicas (x, u, s) VALUES (11, 12, 'F'),(13, 14, 'G'),(15, 16, 'H'),(17, 18, 'I'),(19,20,'J');
|
|
|
|
INSERT INTO parallel_replicas (x, u, s) VALUES (21, 22, 'K'),(23, 24, 'L'),(25, 26, 'M'),(27, 28, 'N'),(29,30,'O');
|
|
|
|
INSERT INTO parallel_replicas (x, u, s) VALUES (31, 32, 'P'),(33, 34, 'Q'),(35, 36, 'R'),(37, 38, 'S'),(39,40,'T');
|
|
|
|
INSERT INTO parallel_replicas (x, u, s) VALUES (41, 42, 'U'),(43, 44, 'V'),(45, 46, 'W'),(47, 48, 'X'),(49,50,'Y');
|
|
|
|
INSERT INTO parallel_replicas (x, u, s) VALUES (51, 52, 'Z');
|
2015-07-13 13:25:56 +00:00
|
|
|
|
2015-07-16 13:01:49 +00:00
|
|
|
/*
|
2024-09-06 15:27:46 +00:00
|
|
|
* Check that:
|
|
|
|
* - the table is not empty on each replica;
|
|
|
|
* - combining the data of all replicas coincides with the contents of the parallel_replicas table.
|
|
|
|
*/
|
2015-07-16 13:01:49 +00:00
|
|
|
|
2024-09-06 15:27:46 +00:00
|
|
|
/* Two replicas */
|
|
|
|
|
|
|
|
SET enable_parallel_replicas=1, parallel_replicas_mode='sampling_key', max_parallel_replicas=3, parallel_replicas_for_non_replicated_merge_tree = 1;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
CREATE TABLE parallel_replicas_backup(d Date DEFAULT today(), x UInt32, u UInt64, s String) ENGINE = Memory;
|
2015-07-13 13:25:56 +00:00
|
|
|
|
|
|
|
SET parallel_replicas_count = 2;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
|
|
|
SET parallel_replica_offset = 0;
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO parallel_replicas_backup(d, x, u, s) SELECT d, x, u, s FROM parallel_replicas;
|
|
|
|
SELECT count() > 0 FROM parallel_replicas;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
|
|
|
SET parallel_replica_offset = 1;
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO parallel_replicas_backup(d, x, u, s) SELECT d, x, u, s FROM parallel_replicas;
|
|
|
|
SELECT count() > 0 FROM parallel_replicas;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
|
|
|
SET parallel_replicas_count = 0;
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT x, u, s FROM parallel_replicas_backup ORDER BY x, u, s ASC;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE parallel_replicas_backup;
|
|
|
|
CREATE TABLE parallel_replicas_backup(d Date DEFAULT today(), x UInt32, u UInt64, s String) ENGINE = Memory;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
2024-09-06 15:27:46 +00:00
|
|
|
/* Three replicas */
|
2015-07-16 13:01:49 +00:00
|
|
|
|
|
|
|
SET parallel_replicas_count = 3;
|
|
|
|
|
|
|
|
SET parallel_replica_offset = 0;
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO parallel_replicas_backup(d, x, u, s) SELECT d, x, u, s FROM parallel_replicas;
|
|
|
|
SELECT count() > 0 FROM parallel_replicas;
|
2015-07-13 13:25:56 +00:00
|
|
|
|
|
|
|
SET parallel_replica_offset = 1;
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO parallel_replicas_backup(d, x, u, s) SELECT d, x, u, s FROM parallel_replicas;
|
|
|
|
SELECT count() > 0 FROM parallel_replicas;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
|
|
|
SET parallel_replica_offset = 2;
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO parallel_replicas_backup(d, x, u, s) SELECT d, x, u, s FROM parallel_replicas;
|
|
|
|
SELECT count() > 0 FROM parallel_replicas;
|
2015-07-16 13:01:49 +00:00
|
|
|
|
|
|
|
SET parallel_replicas_count = 0;
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT x, u, s FROM parallel_replicas_backup ORDER BY x, u, s ASC;
|
2016-03-27 14:36:59 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE parallel_replicas;
|
|
|
|
DROP TABLE parallel_replicas_backup;
|