2021-09-21 15:47:48 +00:00
|
|
|
-- Tags: no-parallel
|
2021-09-12 12:35:27 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
DROP TABLE IF EXISTS src;
|
|
|
|
DROP TABLE IF EXISTS dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
CREATE TABLE src (p UInt64, k String, d UInt64) ENGINE = MergeTree PARTITION BY p ORDER BY k;
|
|
|
|
CREATE TABLE dst (p UInt64, k String, d UInt64) ENGINE = MergeTree PARTITION BY p ORDER BY k;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
SELECT 'Initial';
|
2019-06-07 16:02:24 +00:00
|
|
|
INSERT INTO src VALUES (0, '0', 1);
|
|
|
|
INSERT INTO src VALUES (1, '0', 1);
|
|
|
|
INSERT INTO src VALUES (1, '1', 1);
|
|
|
|
INSERT INTO src VALUES (2, '0', 1);
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
INSERT INTO dst VALUES (0, '1', 2);
|
|
|
|
INSERT INTO dst VALUES (1, '1', 2), (1, '2', 2);
|
|
|
|
INSERT INTO dst VALUES (2, '1', 2);
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
SELECT count(), sum(d) FROM src;
|
|
|
|
SELECT count(), sum(d) FROM dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
SELECT 'REPLACE simple';
|
2019-06-07 16:02:24 +00:00
|
|
|
ALTER TABLE dst REPLACE PARTITION 1 FROM src;
|
|
|
|
ALTER TABLE src DROP PARTITION 1;
|
|
|
|
SELECT count(), sum(d) FROM src;
|
|
|
|
SELECT count(), sum(d) FROM dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
SELECT 'REPLACE empty';
|
2019-06-07 16:02:24 +00:00
|
|
|
ALTER TABLE src DROP PARTITION 1;
|
|
|
|
ALTER TABLE dst REPLACE PARTITION 1 FROM src;
|
|
|
|
SELECT count(), sum(d) FROM dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
SELECT 'REPLACE recursive';
|
2019-06-07 16:02:24 +00:00
|
|
|
ALTER TABLE dst DROP PARTITION 1;
|
|
|
|
INSERT INTO dst VALUES (1, '1', 2), (1, '2', 2);
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
CREATE TEMPORARY table test_block_numbers (m UInt64);
|
2019-06-07 16:02:24 +00:00
|
|
|
INSERT INTO test_block_numbers SELECT max(max_block_number) AS m FROM system.parts WHERE database=currentDatabase() AND table='dst' AND active AND name LIKE '1_%';
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
ALTER TABLE dst REPLACE PARTITION 1 FROM dst;
|
|
|
|
SELECT count(), sum(d) FROM dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
INSERT INTO test_block_numbers SELECT max(max_block_number) AS m FROM system.parts WHERE database=currentDatabase() AND table='dst' AND active AND name LIKE '1_%';
|
2018-05-21 13:49:54 +00:00
|
|
|
SELECT (max(m) - min(m) > 1) AS new_block_is_generated FROM test_block_numbers;
|
2018-06-08 19:50:15 +00:00
|
|
|
DROP TEMPORARY TABLE test_block_numbers;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
SELECT 'ATTACH FROM';
|
2019-06-07 16:02:24 +00:00
|
|
|
ALTER TABLE dst DROP PARTITION 1;
|
|
|
|
DROP TABLE src;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
CREATE TABLE src (p UInt64, k String, d UInt64) ENGINE = MergeTree PARTITION BY p ORDER BY k;
|
|
|
|
INSERT INTO src VALUES (1, '0', 1);
|
|
|
|
INSERT INTO src VALUES (1, '1', 1);
|
2018-05-21 13:49:54 +00:00
|
|
|
|
2019-06-07 16:02:24 +00:00
|
|
|
SYSTEM STOP MERGES dst;
|
|
|
|
INSERT INTO dst VALUES (1, '1', 2);
|
|
|
|
ALTER TABLE dst ATTACH PARTITION 1 FROM src;
|
|
|
|
SELECT count(), sum(d) FROM dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
SELECT 'OPTIMIZE';
|
2019-06-07 16:02:24 +00:00
|
|
|
SELECT count(), sum(d), uniqExact(_part) FROM dst;
|
2020-07-15 11:47:51 +00:00
|
|
|
SYSTEM START MERGES dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
SET optimize_throw_if_noop=1;
|
2019-06-07 16:02:24 +00:00
|
|
|
OPTIMIZE TABLE dst;
|
|
|
|
SELECT count(), sum(d), uniqExact(_part) FROM dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
SELECT 'After restart';
|
2019-06-07 16:02:24 +00:00
|
|
|
DETACH TABLE dst;
|
|
|
|
ATTACH TABLE dst;
|
|
|
|
SELECT count(), sum(d) FROM dst;
|
2018-05-21 13:49:54 +00:00
|
|
|
|
|
|
|
SELECT 'DETACH+ATTACH PARTITION';
|
2019-06-07 16:02:24 +00:00
|
|
|
ALTER TABLE dst DETACH PARTITION 0;
|
|
|
|
ALTER TABLE dst DETACH PARTITION 1;
|
|
|
|
ALTER TABLE dst DETACH PARTITION 2;
|
|
|
|
ALTER TABLE dst ATTACH PARTITION 1;
|
|
|
|
SELECT count(), sum(d) FROM dst;
|
|
|
|
|
|
|
|
DROP TABLE IF EXISTS src;
|
|
|
|
DROP TABLE IF EXISTS dst;
|