Skip to content

Commit a228ebe

Browse files
authored
Use monthly partiton (#227)
Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent b0938d9 commit a228ebe

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

migrations/clickhouse/versions/001_init_otel_spans_table.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
class InitOtelSpansTable(Migration):
1717
"""Create the complete otel_spans table with all columns and indexes.
1818
Supports both single-node (MergeTree) and cluster (ReplicatedMergeTree) setups.
19+
20+
Uses monthly partitioning (toYYYYMM) instead of daily because:
21+
- Most queries scan time ranges (not specific days)
22+
- Fewer partition files (12/year vs 365/year) = less overhead
23+
- Better performance for team-level aggregations
24+
- Still fast for specific day queries due to ORDER BY (OrgId, TeamId, Timestamp)
1925
"""
2026

2127
version = "001"
@@ -88,7 +94,7 @@ def upgrade(self, client: clickhouse_connect.driver.Client, database: str) -> No
8894
INDEX idx_experiment_id_minmax ExperimentId TYPE minmax GRANULARITY 4,
8995
INDEX idx_run_id_minmax RunId TYPE minmax GRANULARITY 4
9096
) ENGINE = {engine}
91-
PARTITION BY toDate(Timestamp)
97+
PARTITION BY toYYYYMM(Timestamp)
9298
ORDER BY (OrgId, TeamId, Timestamp)
9399
SETTINGS index_granularity = 8192
94100
"""

0 commit comments

Comments
 (0)