: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(marketing-analytics): add a session-grain precompute table (#90926)
Javier Bahamondes5a560e2080c6
diff --git a/docs/internal/web-analytics-query-serving.md b/docs/internal/web-analytics-query-serving.mdindex 41e19dc4107c..aada1f80104b 100644--- a/docs/internal/web-analytics-query-serving.md+++ b/docs/internal/web-analytics-query-serving.md@@ -119,6 +119,18 @@ Full details in [PRECOMPUTATION.md](../../products/web_analytics/PRECOMPUTATION.- OOM protection: a team that OOMs during a build gets Redis-pinned for 14 days to 1-day insert windows.- Max range: 90 days; wider requests are permanently live.+## Session-grain precompute schema++`web_sessions_dimensional_preaggregated` preserves individual sessions and person identity for attribution reads.+Its sharded storage table lives on the aux cluster; distributed tables on aux and data nodes point to it.+This schema is a prerequisite for the session writer and reader; creating it does not enable either path.++`session_id_v7` uses `UInt128`, matching the raw Sessions v2 and v3 tables and the numeric representation in `events.$session_id_uuid`.+Writers must preserve that representation and only materialize valid UUIDv7 sessions; a null or invalid ID must not become a shared zero-valued ID.+Sessions v1 and arbitrary string IDs require the live query path unless a separate compatible precompute path is available.+The writer, reader, and HogQL schema must use `session_id_v7` consistently before this precompute path is enabled.+The table uses `TTL toDateTime(expires_at)` with whole-part expiry; the lazy computation executor includes the in-flight reader buffer in `expires_at`.+## Background warming systemsFour writers keep buckets warm; user reads only ever consume.diff --git a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl b/posthog/clickhouse/hcl/golden/dev/auxiliary.hclindex 1d74983b5749..9bb0f21d859e 100644--- a/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/dev/auxiliary.hcl@@ -2642,6 +2642,80 @@ database "posthog" {}}+ table "sharded_web_sessions_dimensional_preaggregated" {+ order_by = ["team_id", "job_id", "person_id", "start_timestamp", "session_id_v7"]+ partition_by = "toYYYYMMDD(expires_at)"+ ttl = "toDateTime(expires_at)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated"+ replica_name = "{replica}"+ version_column = "computed_at"+ }+ }+table "sharded_web_stats_dimensional_preaggregated" {order_by = ["team_id", "job_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_backend", "mat_metadata_loggedIn"]partition_by = "toYYYYMMDD(expires_at)"@@ -3151,6 +3225,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_dimensional_preaggregated" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hclindex 850131e0f0ad..6ce5eed2905d 100644--- a/posthog/clickhouse/hcl/golden/dev/data.hcl+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl@@ -7221,6 +7221,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_dimensional_preaggregated" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hclindex 81a7c5302cfa..09206fdf57c0 100644--- a/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/auxiliary.hcl@@ -2650,6 +2650,80 @@ database "posthog" {}}+ table "sharded_web_sessions_dimensional_preaggregated" {+ order_by = ["team_id", "job_id", "person_id", "start_timestamp", "session_id_v7"]+ partition_by = "toYYYYMMDD(expires_at)"+ ttl = "toDateTime(expires_at)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated"+ replica_name = "{replica}"+ version_column = "computed_at"+ }+ }+table "sharded_web_stats_dimensional_preaggregated" {order_by = ["team_id", "job_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_backend", "mat_metadata_loggedIn"]partition_by = "toYYYYMMDD(expires_at)"@@ -3159,6 +3233,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_dimensional_preaggregated" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hclindex 66e006e13f0c..a7877ad7569a 100644--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl@@ -8680,6 +8680,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_dimensional_preaggregated" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex b20e4fb708d4..1767d1472a61 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -14354,6 +14354,80 @@ SQL}}+ table "sharded_web_sessions_dimensional_preaggregated" {+ order_by = ["team_id", "job_id", "person_id", "start_timestamp", "session_id_v7"]+ partition_by = "toYYYYMMDD(expires_at)"+ ttl = "toDateTime(expires_at)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated"+ replica_name = "{replica}"+ version_column = "computed_at"+ }+ }+table "sharded_web_stats_dimensional_preaggregated" {order_by = ["team_id", "job_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_backend", "mat_metadata_loggedIn"]partition_by = "toYYYYMMDD(expires_at)"@@ -15935,6 +16009,74 @@ SQL}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_dimensional_preaggregated" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hclindex b8376144f63d..ac341067018a 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/auxiliary.hcl@@ -2642,6 +2642,80 @@ database "posthog" {}}+ table "sharded_web_sessions_dimensional_preaggregated" {+ order_by = ["team_id", "job_id", "person_id", "start_timestamp", "session_id_v7"]+ partition_by = "toYYYYMMDD(expires_at)"+ ttl = "toDateTime(expires_at)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated"+ replica_name = "{replica}"+ version_column = "computed_at"+ }+ }+table "sharded_web_stats_dimensional_preaggregated" {order_by = ["team_id", "job_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_backend", "mat_metadata_loggedIn"]partition_by = "toYYYYMMDD(expires_at)"@@ -3151,6 +3225,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_dimensional_preaggregated" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hclindex 853458680d9e..dee868702aaa 100644--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl@@ -7334,6 +7334,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_daily_distributed" {column "period_bucket" {type = "DateTime"diff --git a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hclindex 9bf9bf33778d..a20eca9ad4fa 100644--- a/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/auxiliary.hcl@@ -2680,6 +2680,80 @@ database "posthog" {}}+ table "sharded_web_sessions_dimensional_preaggregated" {+ order_by = ["team_id", "job_id", "person_id", "start_timestamp", "session_id_v7"]+ partition_by = "toYYYYMMDD(expires_at)"+ ttl = "toDateTime(expires_at)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated"+ replica_name = "{replica}"+ version_column = "computed_at"+ }+ }+table "sharded_web_stats_dimensional_preaggregated" {order_by = ["team_id", "job_id", "period_bucket", "host", "device_type", "pathname", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_backend", "mat_metadata_loggedIn"]partition_by = "toYYYYMMDD(expires_at)"@@ -3189,6 +3263,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_dimensional_preaggregated" {column "team_id" {type = "Int64"diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hclindex d2900001eb26..36ffcb2a7d16 100644--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl@@ -7092,6 +7092,74 @@ database "posthog" {}}+ table "web_sessions_dimensional_preaggregated" {+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }+table "web_stats_daily_distributed" {column "period_bucket" {type = "DateTime"diff --git a/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hcl b/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hclindex 91748f9f0820..209ca10c6378 100644--- a/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hcl+++ b/posthog/clickhouse/hcl/roles/auxiliary/shared/tables.hcl@@ -464,6 +464,21 @@ database "posthog" {replica_name = "{replica}"}}+ table "sharded_web_sessions_dimensional_preaggregated" {+ order_by = ["team_id", "job_id", "person_id", "start_timestamp", "session_id_v7"]+ partition_by = "toYYYYMMDD(expires_at)"+ ttl = "toDateTime(expires_at)"+ settings = {+ index_granularity = "8192"+ ttl_only_drop_parts = "1"+ }+ extend = "_web_sessions_dimensional_preaggregated_columns"+ engine "replicated_replacing_merge_tree" {+ zoo_path = "/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated"+ replica_name = "{replica}"+ version_column = "computed_at"+ }+ }table "sharded_web_bounces_dimensional_preaggregated" {order_by = ["team_id", "job_id", "period_bucket", "host", "device_type", "entry_pathname", "end_pathname", "browser", "os", "viewport_width", "viewport_height", "referring_domain", "utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content", "country_code", "city_name", "region_code", "region_name", "has_gclid", "has_gad_source_paid_search", "has_fbclid", "mat_metadata_backend", "mat_metadata_loggedIn"]partition_by = "toYYYYMMDD(expires_at)"diff --git a/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hclindex 31099bcfc37d..0de825bec977 100644--- a/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl+++ b/posthog/clickhouse/hcl/roles/coshared/aux_data/tables.hcl@@ -550,6 +550,68 @@ database "posthog" {type = "Array(String)"}}+ table "_web_sessions_dimensional_preaggregated_columns" {+ abstract = true+ column "team_id" {+ type = "Int64"+ }+ column "job_id" {+ type = "UUID"+ }+ column "period_bucket" {+ type = "DateTime"+ }+ column "session_id_v7" {+ type = "UInt128"+ }+ column "person_id" {+ type = "UUID"+ }+ column "start_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "min_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "max_event_timestamp" {+ type = "DateTime64(6, 'UTC')"+ }+ column "channel_type" {+ type = "String"+ }+ column "utm_source" {+ type = "String"+ }+ column "utm_medium" {+ type = "String"+ }+ column "utm_campaign" {+ type = "String"+ }+ column "utm_term" {+ type = "String"+ }+ column "utm_content" {+ type = "String"+ }+ column "referring_domain" {+ type = "String"+ }+ column "entry_pathname" {+ type = "String"+ }+ column "pageview_count" {+ type = "UInt64"+ }+ column "computed_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now()"+ }+ column "expires_at" {+ type = "DateTime64(6, 'UTC')"+ default = "now() + toIntervalDay(7)"+ }+ }table "_web_bounces_dimensional_preaggregated_columns" {abstract = truecolumn "team_id" {@@ -1179,6 +1241,15 @@ database "posthog" {sharding_key = "sipHash64(id)"}}+ table "web_sessions_dimensional_preaggregated" {+ extend = "_web_sessions_dimensional_preaggregated_columns"+ engine "distributed" {+ cluster_name = "aux"+ remote_database = "posthog"+ remote_table = "sharded_web_sessions_dimensional_preaggregated"+ sharding_key = "cityHash64(person_id)"+ }+ }table "web_bounces_dimensional_preaggregated" {extend = "_web_bounces_dimensional_preaggregated_columns"engine "distributed" {diff --git a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql b/posthog/clickhouse/hcl/sql/dev/auxiliary.sqlindex 8cdd64858ede..7ece2e0e031e 100644--- a/posthog/clickhouse/hcl/sql/dev/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/dev/auxiliary.sql@@ -540,6 +540,27 @@ CREATE TABLE posthog.sharded_web_overview_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_overview_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,@@ -683,6 +704,27 @@ CREATE TABLE posthog.web_goals_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = Distributed('aux', 'posthog', 'sharded_web_goals_preaggregated', sipHash64(job_id));+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sqlindex d52cb47cc124..e6f3679e6709 100644--- a/posthog/clickhouse/hcl/sql/dev/data.sql+++ b/posthog/clickhouse/hcl/sql/dev/data.sql@@ -1607,6 +1607,27 @@ CREATE TABLE posthog.web_pre_aggregated_teams (enabled_by String DEFAULT 'system',version UInt32 DEFAULT toUnixTimestamp(now())) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sqlindex 9e2f9f949292..59240e92e9fb 100644--- a/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/auxiliary.sql@@ -544,6 +544,27 @@ CREATE TABLE posthog.sharded_web_overview_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_overview_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,@@ -687,6 +708,27 @@ CREATE TABLE posthog.web_goals_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = Distributed('aux', 'posthog', 'sharded_web_goals_preaggregated', sipHash64(job_id));+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sqlindex 88676e44fa26..97978d63bd0d 100644--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql@@ -1934,6 +1934,27 @@ CREATE TABLE posthog.web_pre_aggregated_teams (enabled_by String DEFAULT 'system',version UInt32 DEFAULT toUnixTimestamp(now())) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex 2329570bde57..580da75488ba 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -3003,6 +3003,27 @@ CREATE TABLE posthog.sharded_web_overview_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_overview_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,@@ -3463,6 +3484,27 @@ CREATE TABLE posthog.web_pre_aggregated_teams (enabled_by String DEFAULT 'system',version UInt32 DEFAULT toUnixTimestamp(now())) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sqlindex 5f2877ad2cf2..e607852f2f2f 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/auxiliary.sql@@ -540,6 +540,27 @@ CREATE TABLE posthog.sharded_web_overview_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_overview_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,@@ -683,6 +704,27 @@ CREATE TABLE posthog.web_goals_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = Distributed('aux', 'posthog', 'sharded_web_goals_preaggregated', sipHash64(job_id));+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sqlindex 39110f726096..27f87c81ec77 100644--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql@@ -1864,6 +1864,27 @@ CREATE TABLE posthog.web_pre_aggregated_teams (enabled_by String DEFAULT 'system',version UInt32 DEFAULT toUnixTimestamp(now())) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS index_granularity = 8192;+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_daily_distributed (period_bucket DateTime,team_id UInt64,diff --git a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sqlindex f05de4cb5767..1de261b463d9 100644--- a/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/auxiliary.sql@@ -540,6 +540,27 @@ CREATE TABLE posthog.sharded_web_overview_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_overview_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, time_window_start) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;+CREATE TABLE posthog.sharded_web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/{shard}/posthog.web_sessions_dimensional_preaggregated', '{replica}', computed_at) ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7) PARTITION BY toYYYYMMDD(expires_at) TTL toDateTime(expires_at) SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1;CREATE TABLE posthog.sharded_web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,@@ -683,6 +704,27 @@ CREATE TABLE posthog.web_goals_preaggregated (computed_at DateTime64(6, 'UTC') DEFAULT now(),expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)) ENGINE = Distributed('aux', 'posthog', 'sharded_web_goals_preaggregated', sipHash64(job_id));+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_dimensional_preaggregated (team_id Int64,job_id UUID,diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sqlindex 74574517cf27..4e30fb9266ef 100644--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql@@ -1691,6 +1691,27 @@ CREATE TABLE posthog.web_pre_aggregated_teams (enabled_by String DEFAULT 'system',version UInt32 DEFAULT toUnixTimestamp(now())) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/noshard/posthog.web_analytics_team_selection', '{replica}-{shard}', version) ORDER BY (team_id) SETTINGS default_compression_codec = 'lz4', index_granularity = 8192;+CREATE TABLE posthog.web_sessions_dimensional_preaggregated (+ team_id Int64,+ job_id UUID,+ period_bucket DateTime,+ session_id_v7 UInt128,+ person_id UUID,+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),+ channel_type String,+ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,+ pageview_count UInt64,+ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + toIntervalDay(7)+) ENGINE = Distributed('aux', 'posthog', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id));CREATE TABLE posthog.web_stats_daily_distributed (period_bucket DateTime,team_id UInt64,diff --git a/posthog/clickhouse/migrations/0326_web_sessions_preaggregated.py b/posthog/clickhouse/migrations/0326_web_sessions_preaggregated.pynew file mode 100644index 000000000000..82e3ebf685e9--- /dev/null+++ b/posthog/clickhouse/migrations/0326_web_sessions_preaggregated.py@@ -0,0 +1,23 @@+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions+from posthog.clickhouse.preaggregation.web_sessions_sql import (+ DISTRIBUTED_WEB_SESSIONS_TABLE_SQL,+ SHARDED_WEB_SESSIONS_TABLE_SQL,+)++operations = [+ run_sql_with_exceptions(+ SHARDED_WEB_SESSIONS_TABLE_SQL(),+ node_roles=[NodeRole.AUX],+ sharded=True,+ ),+ run_sql_with_exceptions(+ DISTRIBUTED_WEB_SESSIONS_TABLE_SQL(),+ node_roles=[NodeRole.DATA],+ ),+ # Also on AUX, for ad-hoc reads directly from an AUX node.+ run_sql_with_exceptions(+ DISTRIBUTED_WEB_SESSIONS_TABLE_SQL(),+ node_roles=[NodeRole.AUX],+ ),+]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 59fd5e7d4eaa..d658262ea51a 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0325_sessions_v3_flag_key_values+0326_web_sessions_preaggregateddiff --git a/posthog/clickhouse/preaggregation/web_sessions_sql.py b/posthog/clickhouse/preaggregation/web_sessions_sql.pynew file mode 100644index 000000000000..db7e5d4c87ea--- /dev/null+++ b/posthog/clickhouse/preaggregation/web_sessions_sql.py@@ -0,0 +1,103 @@+# Session-grain precompute for web and marketing analytics.+#+# The sibling tables aggregate by dimension, so the person survives only as a `uniq` state. The+# credit side of attribution walks each converting person's touchpoints in order and needs them+# individually, so this table keeps one row per session with `person_id` un-aggregated.+#+# Store `channel_type` already classified to avoid resolving it on every read.++from django.conf import settings++from posthog.clickhouse.table_engines import Distributed, ReplacingMergeTree, ReplicationScheme++TABLE_BASE_NAME = "web_sessions_dimensional_preaggregated"+++def DISTRIBUTED_WEB_SESSIONS_TABLE() -> str:+ return TABLE_BASE_NAME+++def SHARDED_WEB_SESSIONS_TABLE() -> str:+ return f"sharded_{TABLE_BASE_NAME}"+++def SHARDED_WEB_SESSIONS_TABLE_ENGINE() -> ReplacingMergeTree:+ return ReplacingMergeTree(TABLE_BASE_NAME, replication_scheme=ReplicationScheme.SHARDED, ver="computed_at")+++WEB_SESSIONS_TABLE_BASE_SQL = """+CREATE TABLE IF NOT EXISTS {table_name}+(+ team_id Int64,+ job_id UUID,++ period_bucket DateTime,++ -- Match the numeric UUIDv7 representation in raw sessions and events.$session_id_uuid.+ session_id_v7 UInt128,++ person_id UUID,++ -- The event bounds let a read agree with the live path, which bounds by event time rather than+ -- by session start.+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),++ channel_type String,++ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,++ -- Pageviews in the session, so a read can report views next to visitors and sessions.+ pageview_count UInt64,++ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + INTERVAL 7 DAY+) ENGINE = {engine}+"""+++def SHARDED_WEB_SESSIONS_TABLE_SQL() -> str:+ # Person first, unlike the sibling tables: the credit read groups by person and walks each one's+ # sessions in time order, so that is the prefix it needs.+ return (+ WEB_SESSIONS_TABLE_BASE_SQL+ + """+PARTITION BY toYYYYMMDD(expires_at)+ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7)+TTL toDateTime(expires_at)+SETTINGS ttl_only_drop_parts = 1, index_granularity = 8192+"""+ ).format(+ table_name=SHARDED_WEB_SESSIONS_TABLE(),+ engine=SHARDED_WEB_SESSIONS_TABLE_ENGINE(),+ )+++def DISTRIBUTED_WEB_SESSIONS_TABLE_SQL() -> str:+ return WEB_SESSIONS_TABLE_BASE_SQL.format(+ table_name=DISTRIBUTED_WEB_SESSIONS_TABLE(),+ engine=Distributed(+ data_table=SHARDED_WEB_SESSIONS_TABLE(),+ cluster=settings.CLICKHOUSE_AUX_CLUSTER,+ sharding_key="cityHash64(person_id)",+ ),+ )+++def DROP_WEB_SESSIONS_TABLE_SQL() -> str:+ return f"DROP TABLE IF EXISTS {DISTRIBUTED_WEB_SESSIONS_TABLE()}"+++def DROP_SHARDED_WEB_SESSIONS_TABLE_SQL() -> str:+ return f"DROP TABLE IF EXISTS {SHARDED_WEB_SESSIONS_TABLE()} SYNC"+++def TRUNCATE_WEB_SESSIONS_TABLE_SQL() -> str:+ return f"TRUNCATE TABLE IF EXISTS {SHARDED_WEB_SESSIONS_TABLE()}"diff --git a/posthog/clickhouse/schema.py b/posthog/clickhouse/schema.pyindex 3c4e6ea22867..657ed1732dce 100644--- a/posthog/clickhouse/schema.py+++ b/posthog/clickhouse/schema.py@@ -106,6 +106,10 @@ from posthog.clickhouse.preaggregation.web_overview_preaggregated_sql import (DISTRIBUTED_WEB_OVERVIEW_PREAGGREGATED_TABLE_SQL,SHARDED_WEB_OVERVIEW_PREAGGREGATED_TABLE_SQL,)+from posthog.clickhouse.preaggregation.web_sessions_sql import (+ DISTRIBUTED_WEB_SESSIONS_TABLE_SQL,+ SHARDED_WEB_SESSIONS_TABLE_SQL,+)from posthog.clickhouse.preaggregation.web_stats_dimensional_preaggregated_sql import (DISTRIBUTED_WEB_STATS_DIMENSIONAL_PREAGGREGATED_TABLE_SQL,SHARDED_WEB_STATS_DIMENSIONAL_PREAGGREGATED_TABLE_SQL,@@ -442,6 +446,7 @@ CREATE_MERGETREE_TABLE_QUERIES = (SHARDED_WEB_STATS_PREAGGREGATED_TABLE_SQL,SHARDED_WEB_VITALS_PATHS_PREAGGREGATED_TABLE_SQL,SHARDED_WEB_STATS_DIMENSIONAL_PREAGGREGATED_TABLE_SQL,+ SHARDED_WEB_SESSIONS_TABLE_SQL,SHARDED_WEB_BOUNCES_DIMENSIONAL_PREAGGREGATED_TABLE_SQL,DISTINCT_ID_USAGE_DATA_TABLE_SQL,PROPERTY_DEFINITIONS_TABLE_SQL,@@ -540,6 +545,7 @@ CREATE_DISTRIBUTED_TABLE_QUERIES = (DISTRIBUTED_WEB_STATS_PREAGGREGATED_TABLE_SQL,DISTRIBUTED_WEB_VITALS_PATHS_PREAGGREGATED_TABLE_SQL,DISTRIBUTED_WEB_STATS_DIMENSIONAL_PREAGGREGATED_TABLE_SQL,+ DISTRIBUTED_WEB_SESSIONS_TABLE_SQL,DISTRIBUTED_WEB_BOUNCES_DIMENSIONAL_PREAGGREGATED_TABLE_SQL,DOCUMENT_EMBEDDINGS_BUFFER_WRITABLE_TABLE_SQL,*[table.distributed_table_sql for table in EMBEDDING_TABLES],diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 8b382423edf2..ac78a5e72238 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -8790,6 +8790,51 @@'''# ---+# name: test_create_table_query[sharded_web_sessions_dimensional_preaggregated]+ '''++ CREATE TABLE IF NOT EXISTS sharded_web_sessions_dimensional_preaggregated+ (+ team_id Int64,+ job_id UUID,++ period_bucket DateTime,++ -- Match the numeric UUIDv7 representation in raw sessions and events.$session_id_uuid.+ session_id_v7 UInt128,++ person_id UUID,++ -- The event bounds let a read agree with the live path, which bounds by event time rather than+ -- by session start.+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),++ channel_type String,++ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,++ -- Pageviews in the session, so a read can report views next to visitors and sessions.+ pageview_count UInt64,++ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + INTERVAL 7 DAY+ ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_{shard}/posthog.web_sessions_dimensional_preaggregated', '{replica}', computed_at)++ PARTITION BY toYYYYMMDD(expires_at)+ ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7)+ TTL toDateTime(expires_at)+ SETTINGS ttl_only_drop_parts = 1, index_granularity = 8192++ '''+# ---# name: test_create_table_query[sharded_web_stats_dimensional_preaggregated]'''@@ -9447,6 +9492,46 @@'''# ---+# name: test_create_table_query[web_sessions_dimensional_preaggregated]+ '''++ CREATE TABLE IF NOT EXISTS web_sessions_dimensional_preaggregated+ (+ team_id Int64,+ job_id UUID,++ period_bucket DateTime,++ -- Match the numeric UUIDv7 representation in raw sessions and events.$session_id_uuid.+ session_id_v7 UInt128,++ person_id UUID,++ -- The event bounds let a read agree with the live path, which bounds by event time rather than+ -- by session start.+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),++ channel_type String,++ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,++ -- Pageviews in the session, so a read can report views next to visitors and sessions.+ pageview_count UInt64,++ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + INTERVAL 7 DAY+ ) ENGINE = Distributed('aux', 'posthog_test', 'sharded_web_sessions_dimensional_preaggregated', cityHash64(person_id))++ '''+# ---# name: test_create_table_query[web_stats_dimensional_preaggregated]'''@@ -14107,6 +14192,51 @@'''# ---+# name: test_create_table_query_replicated_and_storage[sharded_web_sessions_dimensional_preaggregated]+ '''++ CREATE TABLE IF NOT EXISTS sharded_web_sessions_dimensional_preaggregated+ (+ team_id Int64,+ job_id UUID,++ period_bucket DateTime,++ -- Match the numeric UUIDv7 representation in raw sessions and events.$session_id_uuid.+ session_id_v7 UInt128,++ person_id UUID,++ -- The event bounds let a read agree with the live path, which bounds by event time rather than+ -- by session start.+ start_timestamp DateTime64(6, 'UTC'),+ min_event_timestamp DateTime64(6, 'UTC'),+ max_event_timestamp DateTime64(6, 'UTC'),++ channel_type String,++ utm_source String,+ utm_medium String,+ utm_campaign String,+ utm_term String,+ utm_content String,+ referring_domain String,+ entry_pathname String,++ -- Pageviews in the session, so a read can report views next to visitors and sessions.+ pageview_count UInt64,++ computed_at DateTime64(6, 'UTC') DEFAULT now(),+ expires_at DateTime64(6, 'UTC') DEFAULT now() + INTERVAL 7 DAY+ ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_{shard}/posthog.web_sessions_dimensional_preaggregated', '{replica}', computed_at)++ PARTITION BY toYYYYMMDD(expires_at)+ ORDER BY (team_id, job_id, person_id, start_timestamp, session_id_v7)+ TTL toDateTime(expires_at)+ SETTINGS ttl_only_drop_parts = 1, index_granularity = 8192++ '''+# ---# name: test_create_table_query_replicated_and_storage[sharded_web_stats_dimensional_preaggregated]'''