: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(flags): add person columns to flag_evaluations (#114261)
Phil Haack5943705e66c2
diff --git a/docs/internal/clickhouse-deletion-coverage.md b/docs/internal/clickhouse-deletion-coverage.mdindex e1e6582f53e7..fd0d080b33a8 100644--- a/docs/internal/clickhouse-deletion-coverage.md+++ b/docs/internal/clickhouse-deletion-coverage.md@@ -153,10 +153,11 @@ The copy writes each shard's matching rows to S3 with the named keys dropped andThat works because `materialize()` creates columns as `DEFAULT <expr>`, so an insert can set the column directly.`DeletionTarget.accepts_property_rewrite` marks each table the job sweeps, and the gate refuses while a table without it holds rows a request names.-`person_properties` and `group0..group4_properties` no longer exist on the table: no Insight or Hog function used either as a breakdown or a filter, so the ClickHouse team dropped them directly on both prod clusters, and `posthog/models/flag_evaluations/sql.py` no longer declares them, so any environment built from the migrations matches. Event `properties` and `person_id` are still sent.-Because the table can no longer hold person properties, only the event-`properties` half of a request applies here.-`DeletionTarget.stores_person_properties` is `False` on `FLAG_EVALUATIONS`, so the job drops the `person_properties` half for this table, and a request that names only person properties does not touch it.-That is accurate for rows written since the producer stopped sending `person_properties` (2026-09-05, #95693), and a deliberate blind spot for whatever a row written before then still carries: those values are out of reach until the row's TTL passes.+`group0..group4_properties` no longer exist on the table: no Insight or Hog function used them as a breakdown or a filter, so the ClickHouse team dropped them directly on both prod clusters, and `posthog/models/flag_evaluations/sql.py` no longer declares them. Event `properties` and `person_id` are still sent.+`person_properties` is on the table again, so test-account filters can read person properties off the row the way they do on `events`.+The column defaults to `'{}'`, and no row holds real person properties until the producer sends them.+Until then `DeletionTarget.stores_person_properties` stays `False` on `FLAG_EVALUATIONS`, so the job drops the `person_properties` half for this table, and a request that names only person properties does not touch it.+`stores_person_properties` has to turn on before or with the producer change, or a person-property removal skips real values on this table and still reports success.#### Typed columnsdiff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hclindex 8bd96e76b566..40498e10d4c8 100644--- a/posthog/clickhouse/hcl/golden/dev/data.hcl+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl@@ -1799,10 +1799,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"comment = "column_materializer::$group_0"@@ -5518,10 +5528,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hclindex bb7bddda8520..e35d9de756a7 100644--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl@@ -1894,10 +1894,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"comment = "column_materializer::$group_0"@@ -6028,10 +6038,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hclindex 032df63cb403..43b73ed1a2ce 100644--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_medium.hcl@@ -142,9 +142,18 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }engine "kafka" {collection = "warpstream_ingestion"topic_list = "clickhouse_flag_evaluations"@@ -1042,10 +1051,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "_timestamp" {type = "DateTime"}@@ -1609,7 +1628,10 @@ SELECTdistinct_id,created_at,person_id,+ if(empty(person_properties), '{}', person_properties) AS person_properties,+ person_created_at,now64() AS inserted_at,+ person_mode,_timestamp,_offset,_partition@@ -1640,9 +1662,18 @@ SQLcolumn "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(3)"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "_timestamp" {type = "Nullable(DateTime)"}diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex 4000492ae96c..ce86ea265fd3 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -1974,10 +1974,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"comment = "column_materializer::$group_0"@@ -3184,9 +3194,18 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }engine "kafka" {collection = "warpstream_ingestion"topic_list = "clickhouse_flag_evaluations"@@ -11697,10 +11716,20 @@ SQLcolumn "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"@@ -17569,10 +17598,20 @@ SQLcolumn "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "_timestamp" {type = "DateTime"}@@ -20950,7 +20989,10 @@ SELECTdistinct_id,created_at,person_id,+ if(empty(person_properties), '{}', person_properties) AS person_properties,+ person_created_at,now64() AS inserted_at,+ person_mode,_timestamp,_offset,_partition@@ -20981,9 +21023,18 @@ SQLcolumn "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(3)"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "_timestamp" {type = "Nullable(DateTime)"}diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hclindex 8e2db8bb1e1a..7e0224ab14ef 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl@@ -1756,10 +1756,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"comment = "column_materializer::$group_0"@@ -5693,10 +5703,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hclindex fa0d10af2ba7..dcde195906ea 100644--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl@@ -1871,10 +1871,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"comment = "column_materializer::$group_0"@@ -5506,10 +5516,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"default = "replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^\"|\"$', '')"diff --git a/posthog/clickhouse/hcl/roles/data/shared/flag_evaluations.hcl b/posthog/clickhouse/hcl/roles/data/shared/flag_evaluations.hclindex 812b63242add..a6dec55dc1a3 100644--- a/posthog/clickhouse/hcl/roles/data/shared/flag_evaluations.hcl+++ b/posthog/clickhouse/hcl/roles/data/shared/flag_evaluations.hcl@@ -33,10 +33,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "$group_0" {type = "String"comment = "column_materializer::$group_0"diff --git a/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl b/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hclindex 7ae10ecd7b5d..1fe74217ba11 100644--- a/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl+++ b/posthog/clickhouse/hcl/roles/ingestion_medium/local/tables.hcl@@ -142,9 +142,18 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }engine "kafka" {collection = "warpstream_ingestion"topic_list = "clickhouse_flag_evaluations"@@ -681,10 +690,20 @@ database "posthog" {column "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ default = "'{}'"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(6, 'UTC')"default = "timestamp"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "_timestamp" {type = "DateTime"}@@ -1248,7 +1267,10 @@ SELECTdistinct_id,created_at,person_id,+ if(empty(person_properties), '{}', person_properties) AS person_properties,+ person_created_at,now64() AS inserted_at,+ person_mode,_timestamp,_offset,_partition@@ -1279,9 +1301,18 @@ SQLcolumn "person_id" {type = "UUID"}+ column "person_properties" {+ type = "String"+ }+ column "person_created_at" {+ type = "DateTime64(3)"+ }column "inserted_at" {type = "DateTime64(3)"}+ column "person_mode" {+ type = "Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)"+ }column "_timestamp" {type = "Nullable(DateTime)"}diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sqlindex d7d58f7d518f..913c091fd102 100644--- a/posthog/clickhouse/hcl/sql/dev/data.sql+++ b/posthog/clickhouse/hcl/sql/dev/data.sql@@ -1112,7 +1112,10 @@ CREATE TABLE posthog.sharded_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',$group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',$group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',@@ -2588,7 +2591,10 @@ CREATE TABLE posthog.flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String COMMENT 'column_materializer::$group_0',$group_1 String COMMENT 'column_materializer::$group_1',$group_2 String COMMENT 'column_materializer::$group_2',diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sqlindex 1e84f760afc1..bd496ab5536d 100644--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql@@ -1190,7 +1190,10 @@ CREATE TABLE posthog.sharded_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',$group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',$group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',@@ -3178,7 +3181,10 @@ CREATE TABLE posthog.flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String COMMENT 'column_materializer::$group_0',$group_1 String COMMENT 'column_materializer::$group_1',$group_2 String COMMENT 'column_materializer::$group_2',diff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sqlindex ef627759c937..37ed4880388c 100644--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_medium.sql@@ -42,7 +42,10 @@ CREATE TABLE posthog.kafka_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC')+ person_properties String,+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC'),+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_flush_interval_ms = 7500, kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_flag_evaluations', kafka_max_block_size = 10000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 10000, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_flag_evaluations';CREATE TABLE posthog.kafka_heatmaps (session_id String,@@ -301,7 +304,10 @@ CREATE TABLE posthog.writable_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),_timestamp DateTime,_offset UInt64,_partition UInt64@@ -461,7 +467,7 @@ CREATE MATERIALIZED VIEW posthog.cohort_membership_mv TO posthog.writable_cohortFROM posthog.kafka_cohort_membership;CREATE MATERIALIZED VIEW posthog.distinct_id_usage_mv TO posthog.writable_distinct_id_usage (team_id Int64, distinct_id String, minute DateTime('UTC'), event_count UInt8) AS SELECT team_id, distinct_id, toStartOfMinute(timestamp) AS minute, 1 AS event_countFROM posthog.kafka_distinct_id_usage;-CREATE MATERIALIZED VIEW posthog.flag_evaluations_mv TO posthog.writable_flag_evaluations (uuid UUID, event LowCardinality(String), properties String, timestamp DateTime64(6, 'UTC'), team_id Int64, distinct_id String, created_at DateTime64(6, 'UTC'), person_id UUID, inserted_at DateTime64(3), _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECT+CREATE MATERIALIZED VIEW posthog.flag_evaluations_mv TO posthog.writable_flag_evaluations (uuid UUID, event LowCardinality(String), properties String, timestamp DateTime64(6, 'UTC'), team_id Int64, distinct_id String, created_at DateTime64(6, 'UTC'), person_id UUID, person_properties String, person_created_at DateTime64(3), inserted_at DateTime64(3), person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2), _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECTuuid,event,properties,@@ -470,7 +476,10 @@ CREATE MATERIALIZED VIEW posthog.flag_evaluations_mv TO posthog.writable_flag_evdistinct_id,created_at,person_id,+ if(empty(person_properties), '{}', person_properties) AS person_properties,+ person_created_at,now64() AS inserted_at,+ person_mode,_timestamp,_offset,_partitiondiff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex 1faad78fe53c..be3d272feecb 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -475,7 +475,10 @@ CREATE TABLE posthog.kafka_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC')+ person_properties String,+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC'),+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2)) ENGINE = Kafka(warpstream_ingestion) SETTINGS kafka_flush_interval_ms = 7500, kafka_format = 'JSONEachRow', kafka_group_name = 'clickhouse_flag_evaluations', kafka_max_block_size = 10000, kafka_num_consumers = 1, kafka_poll_max_batch_size = 10000, kafka_poll_timeout_ms = 10000, kafka_skip_broken_messages = 100, kafka_topic_list = 'clickhouse_flag_evaluations';CREATE TABLE posthog.kafka_groups (group_type_index UInt8,@@ -2222,7 +2225,10 @@ CREATE TABLE posthog.sharded_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',$group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',$group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',@@ -3950,7 +3956,10 @@ CREATE TABLE posthog.writable_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),_timestamp DateTime,_offset UInt64,_partition UInt64@@ -4851,7 +4860,7 @@ CREATE MATERIALIZED VIEW posthog.events_recent_json_mv TO posthog.writable_event_timestamp,_offsetFROM posthog.sharded_events;-CREATE MATERIALIZED VIEW posthog.flag_evaluations_mv TO posthog.writable_flag_evaluations (uuid UUID, event LowCardinality(String), properties String, timestamp DateTime64(6, 'UTC'), team_id Int64, distinct_id String, created_at DateTime64(6, 'UTC'), person_id UUID, inserted_at DateTime64(3), _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECT+CREATE MATERIALIZED VIEW posthog.flag_evaluations_mv TO posthog.writable_flag_evaluations (uuid UUID, event LowCardinality(String), properties String, timestamp DateTime64(6, 'UTC'), team_id Int64, distinct_id String, created_at DateTime64(6, 'UTC'), person_id UUID, person_properties String, person_created_at DateTime64(3), inserted_at DateTime64(3), person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2), _timestamp Nullable(DateTime), _offset UInt64, _partition UInt64) AS SELECTuuid,event,properties,@@ -4860,7 +4869,10 @@ CREATE MATERIALIZED VIEW posthog.flag_evaluations_mv TO posthog.writable_flag_evdistinct_id,created_at,person_id,+ if(empty(person_properties), '{}', person_properties) AS person_properties,+ person_created_at,now64() AS inserted_at,+ person_mode,_timestamp,_offset,_partition@@ -6642,7 +6654,10 @@ CREATE TABLE posthog.flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String COMMENT 'column_materializer::$group_0',$group_1 String COMMENT 'column_materializer::$group_1',$group_2 String COMMENT 'column_materializer::$group_2',diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sqlindex 26d74a2c0de5..36fbb0004ac8 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql@@ -1389,7 +1389,10 @@ CREATE TABLE posthog.sharded_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',$group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',$group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',@@ -3035,7 +3038,10 @@ CREATE TABLE posthog.flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String COMMENT 'column_materializer::$group_0',$group_1 String COMMENT 'column_materializer::$group_1',$group_2 String COMMENT 'column_materializer::$group_2',diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sqlindex d2038c249358..ab47778232ab 100644--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql@@ -1231,7 +1231,10 @@ CREATE TABLE posthog.sharded_flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0',$group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1',$group_2 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_2'), '^"|"$', '') COMMENT 'column_materializer::$group_2',@@ -2802,7 +2805,10 @@ CREATE TABLE posthog.flag_evaluations (distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full'=0, 'propertyless'=1, 'force_upgrade'=2),$group_0 String COMMENT 'column_materializer::$group_0',$group_1 String COMMENT 'column_materializer::$group_1',$group_2 String COMMENT 'column_materializer::$group_2',diff --git a/posthog/clickhouse/migrations/0350_flag_evaluations_mv_insert_time.py b/posthog/clickhouse/migrations/0350_flag_evaluations_mv_insert_time.pyindex 73e92cc7dd25..84cdb98998e7 100644--- a/posthog/clickhouse/migrations/0350_flag_evaluations_mv_insert_time.py+++ b/posthog/clickhouse/migrations/0350_flag_evaluations_mv_insert_time.py@@ -1,6 +1,8 @@+from django.conf import settings+from posthog.clickhouse.client.connection import NodeRolefrom posthog.clickhouse.client.migration_tools import run_sql_with_exceptions-from posthog.models.flag_evaluations.sql import FLAG_EVALUATIONS_MV_SELECT_SQL, FLAG_EVALUATIONS_MV_TABLE+from posthog.models.flag_evaluations.sql import FLAG_EVALUATIONS_MV_TABLE, KAFKA_FLAG_EVALUATIONS_TABLE# After this migration, flag_evaluations_mv stamps inserted_at with the time the# view processes each row. posthog/models/flag_evaluations/sql.py carries the@@ -9,9 +11,27 @@ from posthog.models.flag_evaluations.sql import FLAG_EVALUATIONS_MV_SELECT_SQL,# The migration uses MODIFY QUERY rather than drop-and-recreate, because only the# SELECT changes. The MV stays attached to the Kafka table, so consumption does# not stop.+#+# The SELECT is a copy of the one sql.py held for this migration, not an import.+# A node with this migration pending has the Kafka table of that time, so a column+# that a later migration adds to the sql.py SELECT does not exist there yet.operations = [run_sql_with_exceptions(- f"ALTER TABLE {FLAG_EVALUATIONS_MV_TABLE} MODIFY QUERY\n{FLAG_EVALUATIONS_MV_SELECT_SQL()}",+ f"""ALTER TABLE {FLAG_EVALUATIONS_MV_TABLE} MODIFY QUERY+SELECT+ uuid,+ event,+ properties,+ timestamp,+ team_id,+ distinct_id,+ created_at,+ person_id,+ now64() AS inserted_at,+ _timestamp,+ _offset,+ _partition+FROM {settings.CLICKHOUSE_DATABASE}.{KAFKA_FLAG_EVALUATIONS_TABLE}""",node_roles=[NodeRole.INGESTION_MEDIUM],sharded=False,is_alter_on_replicated_table=False,diff --git a/posthog/clickhouse/migrations/0353_flag_evaluations_person_columns.py b/posthog/clickhouse/migrations/0353_flag_evaluations_person_columns.pynew file mode 100644index 000000000000..cb6eaffd20e7--- /dev/null+++ b/posthog/clickhouse/migrations/0353_flag_evaluations_person_columns.py@@ -0,0 +1,72 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions+from posthog.models.flag_evaluations.sql import (+ FLAG_EVALUATIONS_DATA_TABLE,+ FLAG_EVALUATIONS_MV_SQL,+ FLAG_EVALUATIONS_MV_TABLE,+ FLAG_EVALUATIONS_TABLE,+ FLAG_EVALUATIONS_WRITABLE_TABLE,+ KAFKA_FLAG_EVALUATIONS_TABLE,+ KAFKA_FLAG_EVALUATIONS_TABLE_SQL,+)++# Adds person_properties, person_created_at and person_mode to the flag_evaluations family.+# posthog/models/flag_evaluations/sql.py carries the rationale.+#+# A Kafka engine table cannot ALTER its columns, so the migration drops and recreates it with its+# MV. The ALTERs run before that drop, so a failed ALTER leaves the old MV ingesting. Its inserts+# omit the new columns, so each table fills their defaults. A shard replica that has not yet applied+# the sharded ALTER rejects a block from writable_flag_evaluations that carries the new columns, so+# a few inserts can fail and retry until it catches up. The recreate also applies the consumer+# settings that sql.py declares to any environment whose live table predates them.+#+# An environment that kept an older person_properties column without a default skips the ADD COLUMN+# for it. The MODIFY COLUMN gives that column the '{}' default too.+++def _add_person_columns(table: str) -> str:+ return (+ f"ALTER TABLE {table} "+ "ADD COLUMN IF NOT EXISTS person_properties String DEFAULT '{}' AFTER person_id, "+ "ADD COLUMN IF NOT EXISTS person_created_at DateTime64(3) AFTER person_properties, "+ "ADD COLUMN IF NOT EXISTS person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2) AFTER inserted_at, "+ "MODIFY COLUMN person_properties DEFAULT '{}'"+ )+++operations = [+ run_sql_with_exceptions(+ _add_person_columns(FLAG_EVALUATIONS_DATA_TABLE),+ node_roles=[NodeRole.DATA],+ sharded=True,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ _add_person_columns(FLAG_EVALUATIONS_TABLE),+ node_roles=[NodeRole.DATA],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ _add_person_columns(FLAG_EVALUATIONS_WRITABLE_TABLE),+ node_roles=[NodeRole.INGESTION_MEDIUM],+ sharded=False,+ is_alter_on_replicated_table=False,+ ),+ run_sql_with_exceptions(+ f"DROP TABLE IF EXISTS {FLAG_EVALUATIONS_MV_TABLE}",+ node_roles=[NodeRole.INGESTION_MEDIUM],+ ),+ run_sql_with_exceptions(+ f"DROP TABLE IF EXISTS {KAFKA_FLAG_EVALUATIONS_TABLE}",+ node_roles=[NodeRole.INGESTION_MEDIUM],+ ),+ run_sql_with_exceptions(+ KAFKA_FLAG_EVALUATIONS_TABLE_SQL(),+ node_roles=[NodeRole.INGESTION_MEDIUM],+ ),+ run_sql_with_exceptions(+ FLAG_EVALUATIONS_MV_SQL(),+ node_roles=[NodeRole.INGESTION_MEDIUM],+ ),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 01156166b119..26c6e8ed1132 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0352_log_entries_read_cutover+0353_flag_evaluations_person_columnsdiff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex f32e8f6faf3e..c6a44da704d2 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -324,7 +324,10 @@distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC')+ person_properties String,+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC'),+ person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2))ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'clickhouse_flag_evaluations_test', kafka_group_name = 'clickhouse_flag_evaluations', kafka_format = 'JSONEachRow')-- The block and batch sizes are an order of magnitude below the precalculated@@ -2087,7 +2090,10 @@distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC') DEFAULT timestamp+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2), $group_0 String COMMENT 'column_materializer::$group_0', $group_1 String COMMENT 'column_materializer::$group_1'@@ -2123,6 +2129,9 @@distinct_id,created_at,person_id,+ -- The Kafka engine rejects DEFAULT, so an omitted person_properties arrives as ''.+ if(empty(person_properties), '{}', person_properties) AS person_properties,+ person_created_at,-- inserted_at is the time this view processes the row, as in the native-JSON-- events MV. The sync_feature_flag_last_called checkpoint and the deletion-- sweeps need a row that ClickHouse consumes after their cutoff to fall after@@ -2130,6 +2139,7 @@-- forward and the replication happen after this stamp, so those readers still-- need a buffer.now64() AS inserted_at,+ person_mode,_timestamp,_offset,_partition@@ -2738,7 +2748,10 @@distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC')+ person_properties String,+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC'),+ person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2))ENGINE = Kafka(warpstream_ingestion, kafka_topic_list = 'clickhouse_flag_evaluations_test', kafka_group_name = 'clickhouse_flag_evaluations', kafka_format = 'JSONEachRow')-- The block and batch sizes are an order of magnitude below the precalculated@@ -7866,7 +7879,10 @@distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC') DEFAULT timestamp+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2), $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0', $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1'@@ -10460,7 +10476,10 @@distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC') DEFAULT timestamp+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2), _timestamp DateTime@@ -13685,7 +13704,10 @@distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC') DEFAULT timestamp+ person_properties String DEFAULT '{}',+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC') DEFAULT timestamp,+ person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2), $group_0 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_0'), '^"|"$', '') COMMENT 'column_materializer::$group_0', $group_1 String DEFAULT replaceRegexpAll(JSONExtractRaw(properties, '$group_1'), '^"|"$', '') COMMENT 'column_materializer::$group_1'diff --git a/posthog/clickhouse/test/test_schema.py b/posthog/clickhouse/test/test_schema.pyindex 41513c42a875..87e730eecb1b 100644--- a/posthog/clickhouse/test/test_schema.py+++ b/posthog/clickhouse/test/test_schema.py@@ -200,7 +200,7 @@ def test_flag_evaluations_mv_projection_matches_column_template():@pytest.mark.usefixtures("clickhouse_database")-def test_flag_evaluations_mv_ignores_producer_inserted_at() -> None:+def test_flag_evaluations_mv_overrides_producer_values() -> None:select = FLAG_EVALUATIONS_MV_SELECT_SQL().replace(f"FROM {django_settings.CLICKHOUSE_DATABASE}.{KAFKA_FLAG_EVALUATIONS_TABLE}", "FROM mv_input")@@ -216,16 +216,19 @@ def test_flag_evaluations_mv_ignores_producer_inserted_at() -> None:'user' AS distinct_id,timestamp AS created_at,generateUUIDv4() AS person_id,+ arrayJoin(['', '{"email": "[email protected]"}']) AS person_properties,+ timestamp AS person_created_at,timestamp AS inserted_at,+ 'full' AS person_mode,toDateTime('2020-01-01 00:00:00', 'UTC') AS _timestamp,0 AS _offset,0 AS _partition)- SELECT inserted_at > timestamp FROM ("""+ SELECT inserted_at > timestamp, person_properties FROM ("""+ select- + ")"+ + ") ORDER BY person_properties")- assert rows == [(1,)]+ assert rows == [(1, '{"email": "[email protected]"}'), (1, "{}")]def test_flag_evaluations_read_table_declares_every_stored_column():@@ -251,8 +254,18 @@ def _hogql_column_names(table: Table) -> set[str]:return names-# Kafka metadata, deliberately not exposed to customers.-_FLAG_EVALUATIONS_COLUMNS_HIDDEN_FROM_HOGQL = {"_timestamp", "_offset", "_partition"}+# _timestamp, _offset and _partition are Kafka metadata, deliberately not exposed to customers.+# The person columns stay hidden until every stored row carries the values the producer writes.+# Older rows hold '{}', epoch and 'full'. Read as values, those rows let internal users through+# test-account filters and keep lifecycle from counting anyone as new.+_FLAG_EVALUATIONS_COLUMNS_HIDDEN_FROM_HOGQL = {+ "_timestamp",+ "_offset",+ "_partition",+ "person_properties",+ "person_created_at",+ "person_mode",+}def test_flag_evaluations_hogql_table_matches_the_read_table():diff --git a/posthog/models/flag_evaluations/sql.py b/posthog/models/flag_evaluations/sql.pyindex e9596cdef5c2..2081f5a8d395 100644--- a/posthog/models/flag_evaluations/sql.py+++ b/posthog/models/flag_evaluations/sql.py@@ -12,11 +12,16 @@ from posthog.kafka_client.topics import KAFKA_CLICKHOUSE_FLAG_EVALUATIONS# Flag evaluation telemetry ($feature_flag_called events routed out of the events# table). The column set is the events table's, narrowed to what a flag evaluation-# actually carries: no elements_chain, no person_mode, and no person or group-# property blobs, since no Insight or Hog function breaks down or filters on them.-# It keeps the full properties JSON as the source of truth, so queries and-# integrations built on event properties survive the routing switch. The 90-day-# TTL is what makes rows that wide affordable.+# actually carries: no elements_chain and no group property blobs, because group+# filters join the groups table instead. It keeps the full properties JSON as the+# source of truth, so queries and integrations built on event properties survive+# the routing switch. It stores person_properties, person_created_at and+# person_mode the way the events table does, because test-account filters read+# person properties, lifecycle insights read the person's created_at, and a+# persons join at query time does not fit in memory on the largest teams.+# person_mode tells a call processed without a person profile from a person with+# no properties, because both store '{}' in person_properties. The 90-day TTL is+# what makes rows that wide affordable.## Naming convention follows the sharded main-cluster table family (see heatmaps):# * `sharded_flag_evaluations` — sharded replicated MergeTree on DATA nodes.@@ -64,18 +69,22 @@ FLAG_EVALUATIONS_ORDER_BY = "(team_id, flag_key, toDate(timestamp), cityHash64(d## The MV ignores the Kafka table's inserted_at and stamps the time it processes# the row, so a producer cannot set the value that deletion sweeps compare-# against. The Kafka table still declares inserted_at with no DEFAULT, because-# changing a Kafka engine table's columns means recreating the table and its MV.-# Both Distributed tables MUST carry the DEFAULT: an INSERT through a Distributed+# against. The Kafka engine rejects DEFAULT expressions, so the Kafka variant+# renders every column without one.+# Both Distributed tables MUST carry the DEFAULTs: an INSERT through a Distributed# table fills omitted columns from the Distributed table's own schema before-# forwarding to the shard, so without it a direct insert via-# writable_flag_evaluations would store epoch instead of the sharded table's-# DEFAULT.+# forwarding to the shard, so without them a direct insert via+# writable_flag_evaluations would store epoch or '' instead of the sharded table's+# DEFAULTs.+#+# person_properties defaults to '{}' because the JSONDropKeys UDFs fail on an+# empty string. HogQL wraps person_properties in one to mask restricted person+# properties.## No column carries a CODEC, including the JSON blobs the events table wraps in# ZSTD(3); the general rule is in posthog/clickhouse/migrations/AGENTS.md. Nothing# here earns an exception: this ORDER BY only buckets timestamp to a day before-# sorting on a distinct_id hash, so the three DateTime64 columns land on disk in+# sorting on a distinct_id hash, so the four DateTime64 columns land on disk in# effectively random order, which is where the delta family loses. Revisit only# with measurements._FLAG_EVALUATIONS_COLUMNS_TEMPLATE = """@@ -87,12 +96,17 @@ _FLAG_EVALUATIONS_COLUMNS_TEMPLATE = """distinct_id String,created_at DateTime64(6, 'UTC'),person_id UUID,- inserted_at DateTime64(6, 'UTC'){ts_default}+ person_properties String{person_properties_default},+ person_created_at DateTime64(3),+ inserted_at DateTime64(6, 'UTC'){ts_default},+ person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2)""".strip()-FLAG_EVALUATIONS_KAFKA_COLUMNS = _FLAG_EVALUATIONS_COLUMNS_TEMPLATE.format(ts_default="")+FLAG_EVALUATIONS_KAFKA_COLUMNS = _FLAG_EVALUATIONS_COLUMNS_TEMPLATE.format(person_properties_default="", ts_default="")-_FLAG_EVALUATIONS_COLUMNS = _FLAG_EVALUATIONS_COLUMNS_TEMPLATE.format(ts_default=" DEFAULT timestamp")+_FLAG_EVALUATIONS_COLUMNS = _FLAG_EVALUATIONS_COLUMNS_TEMPLATE.format(+ person_properties_default=" DEFAULT '{}'", ts_default=" DEFAULT timestamp"+)# Typed copies of properties the hot path cannot afford to parse per row. A# property earns one only when queries filter or group on it across many rows@@ -272,8 +286,9 @@ SETTINGS""")-# The CREATE below and migrations that ALTER ... MODIFY QUERY both use this-# SELECT, so a fresh install and a migrated node run the same query.+# The CREATE below uses this SELECT. A migration that runs ALTER ... MODIFY QUERY+# copies its SELECT instead of calling this one, because a column added here later+# would make it fail on a node that has the migration pending (see 0350).FLAG_EVALUATIONS_MV_SELECT_SQL = lambda: (f"""SELECTuuid,@@ -284,6 +299,9 @@ FLAG_EVALUATIONS_MV_SELECT_SQL = lambda: (distinct_id,created_at,person_id,+ -- The Kafka engine rejects DEFAULT, so an omitted person_properties arrives as ''.+ if(empty(person_properties), '{{}}', person_properties) AS person_properties,+ person_created_at,-- inserted_at is the time this view processes the row, as in the native-JSON-- events MV. The sync_feature_flag_last_called checkpoint and the deletion-- sweeps need a row that ClickHouse consumes after their cutoff to fall after@@ -291,6 +309,7 @@ FLAG_EVALUATIONS_MV_SELECT_SQL = lambda: (-- forward and the replication happen after this stamp, so those readers still-- need a buffer.now64() AS inserted_at,+ person_mode,_timestamp,_offset,_partition