ClickHouse/tests/queries/0_stateless/01465_ttl_recompression.sql

81 lines
3.5 KiB
MySQL
Raw Normal View History

2021-09-12 12:35:27 +00:00
-- Tags: no-parallel
2020-09-01 10:49:53 +00:00
DROP TABLE IF EXISTS recompression_table;
CREATE TABLE recompression_table
(
dt DateTime,
key UInt64,
value String
) ENGINE MergeTree()
ORDER BY tuple()
PARTITION BY key
2020-09-07 07:28:04 +00:00
TTL dt + INTERVAL 1 MONTH RECOMPRESS CODEC(ZSTD(17)), dt + INTERVAL 1 YEAR RECOMPRESS CODEC(LZ4HC(10))
2020-09-07 11:46:32 +00:00
SETTINGS min_rows_for_wide_part = 0, min_bytes_for_wide_part = 0;
2020-09-01 10:49:53 +00:00
2020-09-01 11:23:38 +00:00
SHOW CREATE TABLE recompression_table;
SYSTEM STOP TTL MERGES recompression_table;
2020-09-01 10:49:53 +00:00
INSERT INTO recompression_table SELECT now(), 1, toString(number) from numbers(1000);
INSERT INTO recompression_table SELECT now() - INTERVAL 2 MONTH, 2, toString(number) from numbers(1000, 1000);
INSERT INTO recompression_table SELECT now() - INTERVAL 2 YEAR, 3, toString(number) from numbers(2000, 1000);
SELECT COUNT() FROM recompression_table;
2020-09-12 07:07:08 +00:00
SELECT substring(name, 1, length(name) - 2), default_compression_codec FROM system.parts WHERE table = 'recompression_table' and active = 1 and database = currentDatabase() ORDER BY name;
2020-09-01 10:49:53 +00:00
2020-09-07 07:28:04 +00:00
OPTIMIZE TABLE recompression_table FINAL;
2020-09-12 07:07:08 +00:00
-- merge level and mutation in part name is not important
SELECT substring(name, 1, length(name) - 2), default_compression_codec FROM system.parts WHERE table = 'recompression_table' and active = 1 and database = currentDatabase() ORDER BY name;
2020-09-07 07:28:04 +00:00
ALTER TABLE recompression_table MODIFY TTL dt + INTERVAL 1 DAY RECOMPRESS CODEC(ZSTD(12)) SETTINGS mutations_sync = 2;
2020-09-01 10:49:53 +00:00
2020-09-01 11:23:38 +00:00
SHOW CREATE TABLE recompression_table;
2020-09-12 07:07:08 +00:00
SELECT substring(name, 1, length(name) - 4), default_compression_codec FROM system.parts WHERE table = 'recompression_table' and active = 1 and database = currentDatabase() ORDER BY name;
2020-09-01 10:49:53 +00:00
2020-09-01 11:23:38 +00:00
SYSTEM START TTL MERGES recompression_table;
2020-09-12 07:07:08 +00:00
-- Additional merge can happen here
2020-09-01 10:49:53 +00:00
OPTIMIZE TABLE recompression_table FINAL;
2020-09-12 07:07:08 +00:00
-- merge level and mutation in part name is not important
SELECT substring(name, 1, length(name) - 4), default_compression_codec FROM system.parts WHERE table = 'recompression_table' and active = 1 and database = currentDatabase() ORDER BY name;
2020-09-01 10:49:53 +00:00
2020-09-12 07:07:08 +00:00
SELECT substring(name, 1, length(name) - 4), recompression_ttl_info.expression FROM system.parts WHERE table = 'recompression_table' and active = 1 and database = currentDatabase() ORDER BY name;
2020-09-01 10:49:53 +00:00
DROP TABLE IF EXISTS recompression_table;
2020-09-07 07:28:04 +00:00
CREATE TABLE recompression_table_compact
(
dt DateTime,
key UInt64,
value String
) ENGINE MergeTree()
ORDER BY tuple()
PARTITION BY key
TTL dt + INTERVAL 1 MONTH RECOMPRESS CODEC(ZSTD(17)), dt + INTERVAL 1 YEAR RECOMPRESS CODEC(LZ4HC(10))
SETTINGS min_rows_for_wide_part = 10000;
SYSTEM STOP TTL MERGES recompression_table_compact;
INSERT INTO recompression_table_compact SELECT now(), 1, toString(number) from numbers(1000);
INSERT INTO recompression_table_compact SELECT now() - INTERVAL 2 MONTH, 2, toString(number) from numbers(1000, 1000);
INSERT INTO recompression_table_compact SELECT now() - INTERVAL 2 YEAR, 3, toString(number) from numbers(2000, 1000);
2020-09-12 07:07:08 +00:00
SELECT substring(name, 1, length(name) - 2), default_compression_codec FROM system.parts WHERE table = 'recompression_table_compact' and active = 1 and database = currentDatabase() ORDER BY name;
2020-09-07 07:28:04 +00:00
ALTER TABLE recompression_table_compact MODIFY TTL dt + INTERVAL 1 MONTH RECOMPRESS CODEC(ZSTD(12)) SETTINGS mutations_sync = 2; -- mutation affect all columns, so codec changes
2020-09-12 07:07:08 +00:00
-- merge level and mutation in part name is not important
SELECT substring(name, 1, length(name) - 4), default_compression_codec FROM system.parts WHERE table = 'recompression_table_compact' and active = 1 and database = currentDatabase() ORDER BY name;
2020-09-07 07:28:04 +00:00
DROP TABLE recompression_table_compact;