Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

perf(personhog): add mark_active column for HOT-friendly uniqueness index (#100626)

Nick Best21247fa5f8c1
diff --git a/rust/persons_migrations/20260914000001_add_lifecycle_mark_active.sql b/rust/persons_migrations/20260914000001_add_lifecycle_mark_active.sql
new file mode 100644
index 000000000000..0f57a8ad1bd7
--- /dev/null
+++ b/rust/persons_migrations/20260914000001_add_lifecycle_mark_active.sql
@@ -0,0 +1,18 @@
+-- New mark_active boolean for HOT-friendly status transitions.
+-- Old lifecycle_op_person_mark index kept until all callers migrate.
+ALTER TABLE lifecycle_op_person
+ ADD COLUMN IF NOT EXISTS mark_active BOOLEAN NOT NULL DEFAULT false;
+
+UPDATE lifecycle_op_person
+ SET mark_active = true
+ WHERE status IN ('marked', 'sealed')
+ AND mark_active = false;
+
+-- Shadow table
+ALTER TABLE lifecycle_op_person_tmp
+ ADD COLUMN IF NOT EXISTS mark_active BOOLEAN NOT NULL DEFAULT false;
+
+UPDATE lifecycle_op_person_tmp
+ SET mark_active = true
+ WHERE status IN ('marked', 'sealed')
+ AND mark_active = false;
diff --git a/rust/persons_migrations/20260914000002_add_lifecycle_mark_active_index.sql b/rust/persons_migrations/20260914000002_add_lifecycle_mark_active_index.sql
new file mode 100644
index 000000000000..8d06da2d5e10
--- /dev/null
+++ b/rust/persons_migrations/20260914000002_add_lifecycle_mark_active_index.sql
@@ -0,0 +1,12 @@
+-- no-transaction
+--
+-- Unique partial index on mark_active for HOT-friendly lifecycle fencing.
+-- CONCURRENTLY avoids SHARE lock on the table during the build.
+--
+-- Recovery note: if this CONCURRENTLY build is ever interrupted, it leaves the index
+-- INVALID and a rerun's IF NOT EXISTS will NOT rebuild it. Recover manually:
+-- DROP INDEX CONCURRENTLY lifecycle_op_person_mark_active;
+-- then re-run migrations.
+CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS lifecycle_op_person_mark_active
+ ON lifecycle_op_person (team_id, person_id)
+ WHERE mark_active = true;
diff --git a/rust/persons_migrations/20260914000003_add_lifecycle_mark_active_tmp_index.sql b/rust/persons_migrations/20260914000003_add_lifecycle_mark_active_tmp_index.sql
new file mode 100644
index 000000000000..233f4997d77e
--- /dev/null
+++ b/rust/persons_migrations/20260914000003_add_lifecycle_mark_active_tmp_index.sql
@@ -0,0 +1,11 @@
+-- no-transaction
+--
+-- Shadow-table counterpart of lifecycle_op_person_mark_active.
+--
+-- Recovery note: if this CONCURRENTLY build is ever interrupted, it leaves the index
+-- INVALID and a rerun's IF NOT EXISTS will NOT rebuild it. Recover manually:
+-- DROP INDEX CONCURRENTLY lifecycle_op_person_tmp_mark_active;
+-- then re-run migrations.
+CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS lifecycle_op_person_tmp_mark_active
+ ON lifecycle_op_person_tmp (team_id, person_id)
+ WHERE mark_active = true;