: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
fix(ingestion): materialize the shadow drift sample sides (#117035)
José Sequeira8375540c7443
diff --git a/posthog/dags/personhog_shadow_drift.py b/posthog/dags/personhog_shadow_drift.pyindex 5f41f9943476..27a06c919122 100644--- a/posthog/dags/personhog_shadow_drift.py+++ b/posthog/dags/personhog_shadow_drift.py@@ -155,13 +155,21 @@ WHERE p.uuid IS NULL OR l.uuid IS NULL OR {_PERSON_ROW_DIFFERS}LIMIT %(limit)s"""+# These sides join a child table to persons before the full outer join.+# MATERIALIZED stops the planner from serving the sample LIMIT through+# index-ordered merge joins: inlined, it merges the child table with persons+# on team_id alone and checks person_id as a join filter, so every row is+# compared against every person of its team. The count queries reference+# each side twice and are materialized either way. The person sides stay+# inline because their full outer join reads both (team_id, uuid) indexes+# in order with no intermediate join._DISTINCT_ID_SIDES = """-WITH legacy AS (+WITH legacy AS MATERIALIZED (SELECT d.team_id, d.distinct_id, p.uuid AS person_uuid, d.versionFROM posthog_persondistinctid dJOIN posthog_person p ON p.id = d.person_id AND p.team_id = d.team_idWHERE NOT d.is_deleted AND NOT p.is_deleted-), personhog AS (+), personhog AS MATERIALIZED (SELECT d.team_id, d.distinct_id, p.uuid AS person_uuid, d.versionFROM personhog_persondistinctid_tmp dJOIN personhog_person_tmp p ON p.team_id = d.team_id AND p.id = d.person_id@@ -196,13 +204,14 @@ WHERE p.person_uuid IS NULL OR l.person_uuid IS NULL OR l.person_uuid <> p.persoLIMIT %(limit)s"""+# MATERIALIZED for the same reason as _DISTINCT_ID_SIDES._HASH_KEY_SIDES = """-WITH legacy AS (+WITH legacy AS MATERIALIZED (SELECT h.team_id, p.uuid AS person_uuid, h.feature_flag_key, h.hash_keyFROM posthog_featureflaghashkeyoverride hJOIN posthog_person p ON p.id = h.person_id AND p.team_id = h.team_idWHERE NOT p.is_deleted-), personhog AS (+), personhog AS MATERIALIZED (SELECT h.team_id, p.uuid AS person_uuid, h.feature_flag_key, h.hash_keyFROM personhog_featureflaghashkeyoverride_tmp hJOIN personhog_person_tmp p ON p.team_id = h.team_id AND p.id = h.person_id