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 a service freshness projection to metrics4_samples (#117076)

Daniel Viscac6a315aaa6cc
diff --git a/posthog/clickhouse/hcl/golden/dev/logs.hcl b/posthog/clickhouse/hcl/golden/dev/logs.hcl
index 98cddbef236e..97ed016beaf6 100644
--- a/posthog/clickhouse/hcl/golden/dev/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/logs.hcl
@@ -1913,8 +1913,9 @@ SQL
partition_by = "original_expiry_date"
ttl = "original_expiry_date"
settings = {
- index_granularity = "128"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "128"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2024,6 +2025,14 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "service_freshness_by_hour" {
+ query = <<SQL
+SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_samples"
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 f762adedfd2b..829fc695f39a 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/logs.hcl
@@ -2414,8 +2414,9 @@ SQL
partition_by = "original_expiry_date"
ttl = "original_expiry_date"
settings = {
- index_granularity = "128"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "128"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2525,6 +2526,14 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "service_freshness_by_hour" {
+ query = <<SQL
+SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_samples"
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 35f1737d59a6..84d730663419 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -7584,8 +7584,9 @@ SQL
partition_by = "original_expiry_date"
ttl = "original_expiry_date"
settings = {
- index_granularity = "128"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "128"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -7695,6 +7696,14 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "service_freshness_by_hour" {
+ query = <<SQL
+SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_samples"
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 7af8e3e912d7..17650a75127f 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/logs.hcl
@@ -2000,8 +2000,9 @@ SQL
partition_by = "original_expiry_date"
ttl = "original_expiry_date"
settings = {
- index_granularity = "128"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "128"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2111,6 +2112,14 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "service_freshness_by_hour" {
+ query = <<SQL
+SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_samples"
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 388facf475f3..4a90e5345f67 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/logs.hcl
@@ -2000,8 +2000,9 @@ SQL
partition_by = "original_expiry_date"
ttl = "original_expiry_date"
settings = {
- index_granularity = "128"
- ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
+ index_granularity = "128"
+ ttl_only_drop_parts = "1"
}
column "team_id" {
type = "Int32"
@@ -2111,6 +2112,14 @@ SQL
type = "minmax"
granularity = 1
}
+ projection "service_freshness_by_hour" {
+ query = <<SQL
+SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_samples"
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 e5c33f0e4ea3..c5b1175ccf52 100644
--- a/posthog/clickhouse/hcl/roles/logs/metrics/metrics4.hcl
+++ b/posthog/clickhouse/hcl/roles/logs/metrics/metrics4.hcl
@@ -113,8 +113,9 @@ database "posthog" {
partition_by = "original_expiry_date"
ttl = "original_expiry_date"
settings = {
- index_granularity = "128"
- ttl_only_drop_parts = "1"
+ index_granularity = "128"
+ ttl_only_drop_parts = "1"
+ deduplicate_merge_projection_mode = "rebuild"
}
column "team_id" {
type = "Int32"
@@ -224,6 +225,18 @@ database "posthog" {
type = "minmax"
granularity = 1
}
+ projection "service_freshness_by_hour" {
+ query = <<SQL
+SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name
+SQL
+
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/noshard/posthog.metrics4_samples"
replica_name = "{replica}-{shard}"
diff --git a/posthog/clickhouse/hcl/sql/dev/logs.sql b/posthog/clickhouse/hcl/sql/dev/logs.sql
index 4ccafbec9b02..d790e324e9e7 100644
--- a/posthog/clickhouse/hcl/sql/dev/logs.sql
+++ b/posthog/clickhouse/hcl/sql/dev/logs.sql
@@ -507,8 +507,11 @@ CREATE TABLE posthog.metrics4_samples (
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS index_granularity = 128, ttl_only_drop_parts = 1;
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour (SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 128, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics4_series (
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 29855e3d1b77..cca83e33972a 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/logs.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/logs.sql
@@ -599,8 +599,11 @@ CREATE TABLE posthog.metrics4_samples (
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS index_granularity = 128, ttl_only_drop_parts = 1;
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour (SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 128, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics4_series (
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 d629557d57da..a189b580f8d7 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -1562,8 +1562,11 @@ CREATE TABLE posthog.metrics4_samples (
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS index_granularity = 128, ttl_only_drop_parts = 1;
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour (SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 128, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics4_series (
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 901a02ec09ae..e099be2d4fef 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/logs.sql
@@ -531,8 +531,11 @@ CREATE TABLE posthog.metrics4_samples (
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS index_granularity = 128, ttl_only_drop_parts = 1;
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour (SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 128, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics4_series (
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 41774e55abc8..189bd2aa2465 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/logs.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/logs.sql
@@ -531,8 +531,11 @@ CREATE TABLE posthog.metrics4_samples (
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
-) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS index_granularity = 128, ttl_only_drop_parts = 1;
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour (SELECT team_id, time_bucket, service_name, max(arrayMax(timestamp_arr))
+GROUP BY
+ team_id, time_bucket, service_name)
+) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/noshard/posthog.metrics4_samples', '{replica}-{shard}') ORDER BY (team_id, metric_name, time_bucket, series_fingerprint) PARTITION BY original_expiry_date TTL original_expiry_date SETTINGS deduplicate_merge_projection_mode = 'rebuild', index_granularity = 128, ttl_only_drop_parts = 1;
CREATE TABLE posthog.metrics4_series (
team_id Int32,
metric_name LowCardinality(String),
diff --git a/posthog/clickhouse/metrics/metrics4.py b/posthog/clickhouse/metrics/metrics4.py
index 139c7c4ce7ed..2e2616a1f90e 100644
--- a/posthog/clickhouse/metrics/metrics4.py
+++ b/posthog/clickhouse/metrics/metrics4.py
@@ -203,6 +203,8 @@ def METRICS4_SAMPLES_TABLE_SQL() -> str:
# The granule can contain multiple metric names and time buckets.
# The time_bucket minmax index lets an hour filter skip the complete granule.
# The metrics2 table uses idx_timestamp_minmax for the same purpose.
+ # The service_freshness_by_hour projection keeps the newest point of each service and hour, also from series
+ # without labels. A read of it does not read the timestamp arrays.
return f"""
CREATE TABLE IF NOT EXISTS {_db()}.{METRICS4_SAMPLES_TABLE_NAME}
(
@@ -228,7 +230,16 @@ CREATE TABLE IF NOT EXISTS {_db()}.{METRICS4_SAMPLES_TABLE_NAME}
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour
+ (
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ max(arrayMax(timestamp_arr))
+ GROUP BY team_id, time_bucket, service_name
+ )
)
ENGINE = {AggregatingMergeTree(METRICS4_SAMPLES_TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED)}
PARTITION BY original_expiry_date
@@ -236,7 +247,8 @@ ORDER BY (team_id, metric_name, time_bucket, series_fingerprint)
TTL original_expiry_date
SETTINGS
index_granularity = 128,
- ttl_only_drop_parts = 1
+ ttl_only_drop_parts = 1,
+ deduplicate_merge_projection_mode = 'rebuild'
"""
diff --git a/posthog/clickhouse/migrations/0360_metrics4_samples_service_freshness_projection.py b/posthog/clickhouse/migrations/0360_metrics4_samples_service_freshness_projection.py
new file mode 100644
index 000000000000..74c7e21b97d0
--- /dev/null
+++ b/posthog/clickhouse/migrations/0360_metrics4_samples_service_freshness_projection.py
@@ -0,0 +1,40 @@
+"""Adds an hourly per-service freshness projection to metrics4_samples.
+
+The projection is not materialized. New parts and merges build it, and the overview query that reads it reads only
+recent hours. Parts with and without the projection do not merge together, so the parts that exist at deploy time
+merge only with each other until TTL drops them.
+"""
+
+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 an AggregatingMergeTree fails until this setting is in place.
+ run_sql_with_exceptions(
+ f"ALTER TABLE {DB}.metrics4_samples 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_samples ADD PROJECTION IF NOT EXISTS service_freshness_by_hour
+(
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ max(arrayMax(timestamp_arr))
+ 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 aa9442ad5cb9..b20bb7b9828a 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0359_logs_ingest_to_apm
+0360_metrics4_samples_service_freshness_projection
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index 881d5b5e61a1..1d41fdc24c45 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -5185,7 +5185,16 @@
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour
+ (
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ max(arrayMax(timestamp_arr))
+ GROUP BY team_id, time_bucket, service_name
+ )
)
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.metrics4_samples', '{replica}-{shard}')
PARTITION BY original_expiry_date
@@ -5193,7 +5202,8 @@
TTL original_expiry_date
SETTINGS
index_granularity = 128,
- ttl_only_drop_parts = 1
+ ttl_only_drop_parts = 1,
+ deduplicate_merge_projection_mode = 'rebuild'
'''
# ---
@@ -12887,7 +12897,16 @@
INDEX idx_time_bucket_minmax time_bucket TYPE minmax GRANULARITY 1,
INDEX idx_trace_id_bf trace_id_arr TYPE bloom_filter(0.01) GRANULARITY 1,
INDEX idx_timestamp_min_minmax timestamp_min TYPE minmax GRANULARITY 1,
- INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1
+ INDEX idx_timestamp_max_minmax timestamp_max TYPE minmax GRANULARITY 1,
+ PROJECTION service_freshness_by_hour
+ (
+ SELECT
+ team_id,
+ time_bucket,
+ service_name,
+ max(arrayMax(timestamp_arr))
+ GROUP BY team_id, time_bucket, service_name
+ )
)
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.metrics4_samples', '{replica}-{shard}')
PARTITION BY original_expiry_date
@@ -12895,7 +12914,8 @@
TTL original_expiry_date
SETTINGS
index_granularity = 128,
- ttl_only_drop_parts = 1
+ ttl_only_drop_parts = 1,
+ deduplicate_merge_projection_mode = 'rebuild'
'''
# ---