: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(signals): turn off gin fastupdate on scratchpad trigram indexes (#119155)
posthog[bot]0b349e942f7c
diff --git a/products/signals/backend/migrations/0197_signalscratchpad_trgm_fastupdate_off.py b/products/signals/backend/migrations/0197_signalscratchpad_trgm_fastupdate_off.pynew file mode 100644index 000000000000..00430be5615b--- /dev/null+++ b/products/signals/backend/migrations/0197_signalscratchpad_trgm_fastupdate_off.py@@ -0,0 +1,49 @@+from django.contrib.postgres.indexes import GinIndex, OpClass+from django.db import migrations+from django.db.models.functions import Upper+++class Migration(migrations.Migration):+ dependencies = [("signals", "0196_signalreport_tags")]++ # ALTER INDEX changes the storage parameter in place, so the indexes are not rebuilt.+ operations = [+ migrations.SeparateDatabaseAndState(+ database_operations=[+ migrations.RunSQL(+ sql=[+ # fastupdate takes ACCESS EXCLUSIVE on the index, and queries that plan against+ # the table queue behind a waiting request. Fail fast and let bin/migrate retry.+ "SET LOCAL lock_timeout = '5s'",+ 'ALTER INDEX IF EXISTS "signal_scratchpad_content_trgm" SET (fastupdate = off)',+ 'ALTER INDEX IF EXISTS "signal_scratchpad_key_trgm" SET (fastupdate = off)',+ ],+ reverse_sql=[+ "SET LOCAL lock_timeout = '5s'",+ 'ALTER INDEX IF EXISTS "signal_scratchpad_content_trgm" SET (fastupdate = on)',+ 'ALTER INDEX IF EXISTS "signal_scratchpad_key_trgm" SET (fastupdate = on)',+ ],+ ),+ ],+ state_operations=[+ migrations.RemoveIndex(model_name="signalscratchpad", name="signal_scratchpad_content_trgm"),+ migrations.RemoveIndex(model_name="signalscratchpad", name="signal_scratchpad_key_trgm"),+ migrations.AddIndex(+ model_name="signalscratchpad",+ index=GinIndex(+ OpClass(Upper("content"), name="gin_trgm_ops"),+ name="signal_scratchpad_content_trgm",+ fastupdate=False,+ ),+ ),+ migrations.AddIndex(+ model_name="signalscratchpad",+ index=GinIndex(+ OpClass(Upper("key"), name="gin_trgm_ops"),+ name="signal_scratchpad_key_trgm",+ fastupdate=False,+ ),+ ),+ ],+ ),+ ]diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txtindex 4d74765f45f3..f1cfa062fe32 100644--- a/products/signals/backend/migrations/max_migration.txt+++ b/products/signals/backend/migrations/max_migration.txt@@ -1 +1 @@-0196_signalreport_tags+0197_signalscratchpad_trgm_fastupdate_offdiff --git a/products/signals/backend/models.py b/products/signals/backend/models.pyindex 72e803f28cb8..11163f880019 100644--- a/products/signals/backend/models.py+++ b/products/signals/backend/models.py@@ -3521,9 +3521,18 @@ class SignalScratchpad(TeamScopedRootMixin, UUIDModel):opclasses=["int4_ops", "varchar_pattern_ops"],),# Back the `text` search. On UPPER(...) because icontains compiles to- # UPPER(col::text) LIKE UPPER(pattern) on Postgres.- GinIndex(OpClass(Upper("content"), name="gin_trgm_ops"), name="signal_scratchpad_content_trgm"),- GinIndex(OpClass(Upper("key"), name="gin_trgm_ops"), name="signal_scratchpad_key_trgm"),+ # UPPER(col::text) LIKE UPPER(pattern) on Postgres. Direct updates avoid pending-list+ # merges that make one insert absorb the batched GIN maintenance of earlier writes.+ GinIndex(+ OpClass(Upper("content"), name="gin_trgm_ops"),+ name="signal_scratchpad_content_trgm",+ fastupdate=False,+ ),+ GinIndex(+ OpClass(Upper("key"), name="gin_trgm_ops"),+ name="signal_scratchpad_key_trgm",+ fastupdate=False,+ ),]