Skip to content

Commit f416ee0

Browse files
committed
oximeter: optimize measurements tables.
Partition measurements tables by timestamp, within days. Many queries care about a small time range, and partitioning by day will make those queries significantly cheaper.
1 parent a65cda6 commit f416ee0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE TABLE IF NOT EXISTS oximeter.measurements_cumulativef64_local_new_15 ON CLUSTER oximeter_cluster
2+
(
3+
timeseries_name String,
4+
timeseries_key UInt64,
5+
start_time DateTime64(9, 'UTC'),
6+
timestamp DateTime64(9, 'UTC'),
7+
datum Nullable(Float64)
8+
)
9+
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/measurements_cumulativef64_local', '{replica}')
10+
PARTITION BY (toYYYYMMDD(timestamp))
11+
ORDER BY (timeseries_name, timeseries_key, start_time, timestamp)
12+
TTL toDateTime(timestamp) + INTERVAL 30 DAY;
13+
14+
INSERT INTO oximeter.measurements_cumulativef64_local_new_15
15+
SELECT * FROM oximeter.measurements_cumulativef64_local;
16+
17+
RENAME TABLE
18+
oximeter.measurements_cumulativef64_local_new_15 to oximeter.measurements.cumulativef64_local,
19+
oximeter.measurements_cumulativef64_local to oximeter.measurements.cumulativef64_local_old_15;
20+
21+
-- TODO: Drop the original table in a separate step, after verifying the migration.
22+
-- DROP TABLE oximeter.measurements_cumulativef64_old_15;

oximeter/db/schema/replicated/db-init-1.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ CREATE TABLE IF NOT EXISTS oximeter.measurements_cumulativef64_local ON CLUSTER
4949
datum Nullable(Float64)
5050
)
5151
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/measurements_cumulativef64_local', '{replica}')
52+
PARTITION BY (toYYYYMMDD(timestamp))
5253
ORDER BY (timeseries_name, timeseries_key, start_time, timestamp)
5354
TTL toDateTime(timestamp) + INTERVAL 30 DAY;
5455

0 commit comments

Comments
 (0)