Skip to content

Commit 1a540ef

Browse files
committed
oximeter: optimize measurements tables.
Apply a few ddl-only optimizations to the oximeter measurements tables: * Encode timestamps columns using delta encoding. Rows are sorted by (timeseries_name, timeseries_key, timestamp), so timestamps compress very well as deltas. * 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 1a540ef

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
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') CODEC(Delta, ZSTD),
6+
timestamp DateTime64(9, 'UTC') CODEC(Delta, ZSTD),
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ CREATE TABLE IF NOT EXISTS oximeter.measurements_cumulativef64_local ON CLUSTER
4444
(
4545
timeseries_name String,
4646
timeseries_key UInt64,
47-
start_time DateTime64(9, 'UTC'),
48-
timestamp DateTime64(9, 'UTC'),
47+
start_time DateTime64(9, 'UTC') CODEC(Delta, ZSTD),
48+
timestamp DateTime64(9, 'UTC') CODEC(Delta, ZSTD),
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)