Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(metrics): add hourly per-service projection to metrics4_series (#110666)

Frank Hamand8daaaa0210f6
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index 51cd4031fe43..10fd828bd9d4 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -2192,8 +2192,9 @@ SQL
partition_by = "toStartOfWeek(original_expiry_timestamp)"
ttl = "original_expiry_timestamp"
settings = {
- index_granularity = "1024"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2274,6 +2275,20 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "services_by_hour" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_replacing_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_series"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
index 307daa93dd6b..4d873da1c086 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
@@ -2692,8 +2692,9 @@ SQL
partition_by = "toStartOfWeek(original_expiry_timestamp)"
ttl = "original_expiry_timestamp"
settings = {
- index_granularity = "1024"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2774,6 +2775,20 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "services_by_hour" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_replacing_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_series"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 9eb51038b05d..0d318a3145a7 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -7837,8 +7837,9 @@ SQL
partition_by = "toStartOfWeek(original_expiry_timestamp)"
ttl = "original_expiry_timestamp"
settings = {
- index_granularity = "1024"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -7919,6 +7920,20 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "services_by_hour" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_replacing_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_series"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
index 398090cba962..4379c25b6a00 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
@@ -2278,8 +2278,9 @@ SQL
partition_by = "toStartOfWeek(original_expiry_timestamp)"
ttl = "original_expiry_timestamp"
settings = {
- index_granularity = "1024"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2360,6 +2361,20 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "services_by_hour" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_replacing_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_series"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
index f87730baa2af..57890e5f41da 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
@@ -2278,8 +2278,9 @@ SQL
partition_by = "toStartOfWeek(original_expiry_timestamp)"
ttl = "original_expiry_timestamp"
settings = {
- index_granularity = "1024"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2360,6 +2361,20 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "services_by_hour" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_replacing_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_series"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/roles/logs/metrics/metrics4.hcl b/posthog/clickhouse/hcl/roles/logs/metrics/metrics4.hcl
index 9ba808ddf39b..d495e5815b63 100644
--- a/posthog/clickhouse/hcl/roles/logs/metrics/metrics4.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/metrics/metrics4.hcl
@@ -228,8 +228,9 @@ database "posthog" {
partition_by = "toStartOfWeek(original_expiry_timestamp)"
ttl = "original_expiry_timestamp"
settings = {
- index_granularity = "1024"
- ttl_only_drop_parts = "1"
+ index_granularity = "1024"
+ ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
}
column "team_id" {
type = "Int32"
@@ -310,6 +311,20 @@ database "posthog" {
type = "minmax"
granularity = 1
}
+ projection "services_by_hour" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_replacing_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_series"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index 89f9203c6e74..18ee358c43fa 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -579,8 +579,17 @@ CREATE TABLE posthog.metrics4_series (
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour (SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 1024, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics_distributed (
team_id Int32,
metric_name LowCardinality(String),
diff --git a/posthog/clickhouse/hcl/sql/local-multi/logs.sql b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
index d088fa9ff6ef..ea26880d4a15 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
@@ -671,8 +671,17 @@ CREATE TABLE posthog.metrics4_series (
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour (SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 1024, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics_distributed (
team_id Int32,
metric_name LowCardinality(String),
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index 405d360a6476..88796a321e3a 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -1642,8 +1642,17 @@ CREATE TABLE posthog.metrics4_series (
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour (SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 1024, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics_distributed (
team_id Int32,
metric_name LowCardinality(String),
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
index 65f9f2346b52..574a00c73739 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
@@ -603,8 +603,17 @@ CREATE TABLE posthog.metrics4_series (
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour (SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 1024, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics_distributed (
team_id Int32,
metric_name LowCardinality(String),
diff --git a/posthog/clickhouse/hcl/sql/prod-us/logs.sql b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
index 0262018f453b..8dd308d1b61e 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
@@ -603,8 +603,17 @@ CREATE TABLE posthog.metrics4_series (
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS index_granularity = 1024, ttl_only_drop_parts = 1;
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour (SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp) ORDER BY (team_id, metric_name, series_fingerprint, time_bucket) PARTITION BY toStartOfWeek(original_expiry_timestamp) TTL original_expiry_timestamp SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 1024, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics_distributed (
team_id Int32,
metric_name LowCardinality(String),
diff --git a/posthog/clickhouse/metrics/metrics4.py b/posthog/clickhouse/metrics/metrics4.py
index d0378fdea760..0b2df4dfd46d 100644
--- a/posthog/clickhouse/metrics/metrics4.py
+++ b/posthog/clickhouse/metrics/metrics4.py
@@ -263,7 +263,18 @@ CREATE TABLE IF NOT EXISTS {_db()}.{METRICS4_SERIES_TABLE_NAME}
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour
+ (
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+ GROUP BY team_id, time_bucket, service_name
+ )
)
ENGINE = {ReplacingMergeTree(METRICS4_SERIES_TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED, ver="timestamp")}
PARTITION BY toStartOfWeek(original_expiry_timestamp)
@@ -271,7 +282,8 @@ ORDER BY (team_id, metric_name, series_fingerprint, time_bucket)
TTL original_expiry_timestamp
SETTINGS
index_granularity = 1024,
- ttl_only_drop_parts = 1
+ ttl_only_drop_parts = 1,
+ deduplicate_merge_projection_mode = 'rebuild'
"""
diff --git a/posthog/clickhouse/migrations/0345_metrics4_series_services_projection.py b/posthog/clickhouse/migrations/0345_metrics4_series_services_projection.py
new file mode 100644
index 000000000000..b5b13e109d96
--- /dev/null
+++ b/posthog/clickhouse/migrations/0345_metrics4_series_services_projection.py
@@ -0,0 +1,40 @@
+"""Adds an hourly per-service rollup projection to metrics4_series.
+
+The projection is not materialized. New parts and merges build it, and the queries it serves read only recent hours.
+"""
+
+from django.conf import settings
+
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+
+DB = settings.CLICKHOUSE_LOGS_CLUSTER_DATABASE
+
+operations = [
+ # A settings-only ALTER changes only the replica that runs it, so this runs on every host.
+ # ADD PROJECTION on a ReplacingMergeTree fails until this setting is in place.
+ run_sql_with_exceptions(
+ f"ALTER TABLE {DB}.metrics4_series MODIFY SETTING deduplicate_merge_projection_mode = 'rebuild'",
+ node_roles=[NodeRole.LOGS],
+ sharded=False,
+ is_alter_on_replicated_table=False,
+ ),
+ run_sql_with_exceptions(
+ f"""
+ALTER TABLE {DB}.metrics4_series ADD PROJECTION IF NOT EXISTS services_by_hour
+(
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+ GROUP BY team_id, time_bucket, service_name
+)
+""",
+ node_roles=[NodeRole.LOGS],
+ sharded=False,
+ is_alter_on_replicated_table=True,
+ ),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index e1abedf8c8f0..8cd7880294f7 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0344_metrics4_attributes_time_bucket_minmax
+0345_metrics4_series_services_projection
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index 7c56e937b6a7..4cb09c78caef 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -5448,7 +5448,18 @@
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour
+ (
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+ GROUP BY team_id, time_bucket, service_name
+ )
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp)
PARTITION BY toStartOfWeek(original_expiry_timestamp)
@@ -5456,7 +5467,8 @@
TTL original_expiry_timestamp
SETTINGS
index_granularity = 1024,
- ttl_only_drop_parts = 1
+ ttl_only_drop_parts = 1,
+ deduplicate_merge_projection_mode = 'rebuild'
'''
# ---
@@ -12878,7 +12890,18 @@
INDEX idx_attr_keys mapKeys(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_attr_values mapValues(attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_minmax timestamp TYPE minmax GRANULARITY 1,
- INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1
+ INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
+ PROJECTION services_by_hour
+ (
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ uniqExact(metric_name),
+ uniq(series_fingerprint),
+ max(timestamp)
+ GROUP BY team_id, time_bucket, service_name
+ )
)
ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.metrics4_series', '{replica}-{shard}', timestamp)
PARTITION BY toStartOfWeek(original_expiry_timestamp)
@@ -12886,7 +12909,8 @@
TTL original_expiry_timestamp
SETTINGS
index_granularity = 1024,
- ttl_only_drop_parts = 1
+ ttl_only_drop_parts = 1,
+ deduplicate_merge_projection_mode = 'rebuild'
'''
# ---