diff --git a/migrations/clickhouse/versions/001_init_otel_spans_table.py b/migrations/clickhouse/versions/001_init_otel_spans_table.py index 7dedbf8..b23827b 100644 --- a/migrations/clickhouse/versions/001_init_otel_spans_table.py +++ b/migrations/clickhouse/versions/001_init_otel_spans_table.py @@ -16,6 +16,12 @@ class InitOtelSpansTable(Migration): """Create the complete otel_spans table with all columns and indexes. Supports both single-node (MergeTree) and cluster (ReplicatedMergeTree) setups. + + Uses monthly partitioning (toYYYYMM) instead of daily because: + - Most queries scan time ranges (not specific days) + - Fewer partition files (12/year vs 365/year) = less overhead + - Better performance for team-level aggregations + - Still fast for specific day queries due to ORDER BY (OrgId, TeamId, Timestamp) """ version = "001" @@ -88,7 +94,7 @@ def upgrade(self, client: clickhouse_connect.driver.Client, database: str) -> No INDEX idx_experiment_id_minmax ExperimentId TYPE minmax GRANULARITY 4, INDEX idx_run_id_minmax RunId TYPE minmax GRANULARITY 4 ) ENGINE = {engine} - PARTITION BY toDate(Timestamp) + PARTITION BY toYYYYMM(Timestamp) ORDER BY (OrgId, TeamId, Timestamp) SETTINGS index_granularity = 8192 """