ClickHouse/tests/queries/0_stateless/00626_replace_partition_from_table.sql

85 lines
2.5 KiB
MySQL
Raw Normal View History

2019-06-07 16:02:24 +00:00
DROP TABLE IF EXISTS src;
DROP TABLE IF EXISTS dst;
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;
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);
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);
2019-06-07 16:02:24 +00:00
SELECT count(), sum(d) FROM src;
SELECT count(), sum(d) FROM dst;
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;
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;
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);
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_%';
2019-06-07 16:02:24 +00:00
ALTER TABLE dst REPLACE PARTITION 1 FROM dst;
SELECT count(), sum(d) FROM dst;
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_%';
SELECT (max(m) - min(m) > 1) AS new_block_is_generated FROM test_block_numbers;
DROP TEMPORARY TABLE test_block_numbers;
SELECT 'ATTACH FROM';
2019-06-07 16:02:24 +00:00
ALTER TABLE dst DROP PARTITION 1;
DROP TABLE src;
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);
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;
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;
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;
SELECT 'After restart';
2019-06-07 16:02:24 +00:00
DETACH TABLE dst;
ATTACH TABLE dst;
SELECT count(), sum(d) FROM dst;
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;