: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
chore(persons): correct docs describing the uuid index (#91187)
Eli Reismana78606eac546
diff --git a/.agents/skills/adding-personhog-rpc/references/database-indexes.md b/.agents/skills/adding-personhog-rpc/references/database-indexes.mdindex e08f5a2a1ce8..33f354603a04 100644--- a/.agents/skills/adding-personhog-rpc/references/database-indexes.md+++ b/.agents/skills/adding-personhog-rpc/references/database-indexes.md@@ -10,20 +10,27 @@ All indexes below are sourced from `rust/persons_migrations/` SQL files — thePartitioned by `team_id` (64 hash partitions).Primary key is composite `(team_id, id)`.-| Index name | Type | Columns | Notes |-| ----------------------------- | ------ | ----------------- | --------------------------------------------------------- |-| `posthog_person_new_pkey` | PK | `(team_id, id)` | Partition-pruned lookup |-| `posthog_person_new_uuid_idx` | UNIQUE | `(team_id, uuid)` | Partition-pruned uuid lookup |-| `posthog_person_p{i}_id_idx` | INDEX | `(id)` | Per-partition index on id (64 indexes, one per partition) |+| Index name | Type | Columns | Notes |+| ---------------------------------- | ------ | ----------------- | ------------------------------------------------------------------------------------------------------------------- |+| `posthog_person_new_pkey` | PK | `(team_id, id)` | Partition-pruned lookup |+| `posthog_person_team_id_uuid_uniq` | UNIQUE | `(team_id, uuid)` | Partition-pruned uuid lookup. **Named `posthog_person_new_uuid_idx` in migration-built databases** — see note below |+| `posthog_person_p{i}_id_idx` | INDEX | `(id)` | Per-partition index on id (64 indexes, one per partition) |++> **The uuid index has two names.** `rust/persons_migrations/20251113000001` creates it as+> `posthog_person_new_uuid_idx` (the table was `posthog_person_new` then, and `ALTER TABLE ... RENAME`+> does not rename indexes). prod-US and prod-EU carry the same index as+> `posthog_person_team_id_uuid_uniq`, built out-of-band in 2026-08 and enforcing from then on.+> Both are UNIQUE on `(team_id, uuid)`, so query plans are identical — but **do not reference either+> name in a migration or a query hint**, because neither exists in every environment.Constraints: `check_properties_size` — `pg_column_size(properties) <= 655360` (on old unpartitioned table; `personhog_person_tmp` has equivalent).**Typical query patterns:**- `WHERE team_id = $1 AND id = $2` → PK scan-- `WHERE team_id = $1 AND uuid = $2` → `posthog_person_new_uuid_idx` (partition-pruned)+- `WHERE team_id = $1 AND uuid = $2` → unique `(team_id, uuid)` index (partition-pruned)- `WHERE team_id = $1 AND id = ANY($2)` → PK scan-- `WHERE team_id = $1 AND uuid = ANY($2)` → `posthog_person_new_uuid_idx` scan+- `WHERE team_id = $1 AND uuid = ANY($2)` → unique `(team_id, uuid)` index scan## posthog_persondistinctiddiff --git a/nodejs/src/common/persons/repositories/postgres-person-repository-stranded-claim.serial.test.ts b/nodejs/src/common/persons/repositories/postgres-person-repository-stranded-claim.serial.test.tsindex ca3effc6a3b3..c8eb490b92f4 100644--- a/nodejs/src/common/persons/repositories/postgres-person-repository-stranded-claim.serial.test.ts+++ b/nodejs/src/common/persons/repositories/postgres-person-repository-stranded-claim.serial.test.ts@@ -15,11 +15,12 @@ import { TEST_TIMESTAMP, fetchDistinctIdValues, getFirstTeam } from './test-helpjest.mock('~/common/utils/logger')-// Production does NOT have the unique (team_id, uuid) index the tracked schema declares-// (posthog_person_new_uuid_idx is non-unique in both prod regions), which is what lets-// duplicate persons exist there at all. The tests below recreate that reality; with the-// tracked schema's unique index in place, the duplicate scenarios cannot even be seeded-// and every claim test would pass vacuously.+// The tracked schema's UNIQUE (team_id, uuid) index blocks the duplicate rows these tests+// seed, so the index is recreated non-unique for the fixture. Production enforces uniqueness,+// which is why the claim path matters: a stranded person (one no distinct ID resolves to) still+// holds its uuid, and a returning user derives that same uuid, so the insert hits a constraint+// violation the claim path has to resolve. Without the fixture every claim test would pass+// vacuously.async function makeUuidIndexNonUnique(postgres: PostgresRouter): Promise<void> {const { rows } = await postgres.query(PostgresUse.PERSONS_WRITE,diff --git a/posthog/management/commands/test/test_persons_dedup.py b/posthog/management/commands/test/test_persons_dedup.pyindex c6b6bcc2cf5e..0659f35f0abe 100644--- a/posthog/management/commands/test/test_persons_dedup.py+++ b/posthog/management/commands/test/test_persons_dedup.py@@ -22,11 +22,11 @@ pytestmark = pytest.mark.django_dbTEAM = 987654-# The test database is built from rust/persons_migrations, which declares-# posthog_person_new_uuid_idx as UNIQUE. Production does not have it -- that divergence-# is the entire reason this command exists, and it means the test database physically-# rejects the duplicate rows we need to seed. Recreate the index non-unique so the-# fixture holds what production holds, and restore it afterwards.+# The test database declares a UNIQUE (team_id, uuid) index, so it physically rejects the+# duplicate rows these tests need to seed. Drop to a non-unique index for the fixture and+# restore it afterwards. The duplicates this command repairs accumulated while production+# carried a non-unique index. Production enforces uniqueness, so the command operates on+# historical rows rather than newly created ones.DROP_UNIQUE_UUID_INDEX = "DROP INDEX IF EXISTS posthog_person_new_uuid_idx"CREATE_NON_UNIQUE_UUID_INDEX = "CREATE INDEX posthog_person_new_uuid_idx ON posthog_person (team_id, uuid)"RESTORE_UNIQUE_UUID_INDEX = "CREATE UNIQUE INDEX posthog_person_new_uuid_idx ON posthog_person (team_id, uuid)"