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(signals): turn off gin fastupdate on signal report trigram indexes (#127099)

posthog[bot]6b001c02f3b4
diff --git a/products/signals/backend/migrations/0226_signalreport_trgm_fastupdate_off.py b/products/signals/backend/migrations/0226_signalreport_trgm_fastupdate_off.py
new file mode 100644
index 000000000000..5e27eff25fbd
--- /dev/null
+++ b/products/signals/backend/migrations/0226_signalreport_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", "0225_anomalyscoringdueinsight")]
+
+ # 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 "signals_report_title_trgm" SET (fastupdate = off)',
+ 'ALTER INDEX IF EXISTS "signals_report_summary_trgm" SET (fastupdate = off)',
+ ],
+ reverse_sql=[
+ "SET LOCAL lock_timeout = '5s'",
+ 'ALTER INDEX IF EXISTS "signals_report_title_trgm" SET (fastupdate = on)',
+ 'ALTER INDEX IF EXISTS "signals_report_summary_trgm" SET (fastupdate = on)',
+ ],
+ ),
+ ],
+ state_operations=[
+ migrations.RemoveIndex(model_name="signalreport", name="signals_report_title_trgm"),
+ migrations.RemoveIndex(model_name="signalreport", name="signals_report_summary_trgm"),
+ migrations.AddIndex(
+ model_name="signalreport",
+ index=GinIndex(
+ OpClass(Upper("title"), name="gin_trgm_ops"),
+ name="signals_report_title_trgm",
+ fastupdate=False,
+ ),
+ ),
+ migrations.AddIndex(
+ model_name="signalreport",
+ index=GinIndex(
+ OpClass(Upper("summary"), name="gin_trgm_ops"),
+ name="signals_report_summary_trgm",
+ fastupdate=False,
+ ),
+ ),
+ ],
+ ),
+ ]
diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txt
index 7a5ec262518e..8ab28bae09ce 100644
--- a/products/signals/backend/migrations/max_migration.txt
+++ b/products/signals/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0225_anomalyscoringdueinsight
+0226_signalreport_trgm_fastupdate_off
diff --git a/products/signals/backend/models.py b/products/signals/backend/models.py
index e3d9167fb5f2..e42c6ff9294d 100644
--- a/products/signals/backend/models.py
+++ b/products/signals/backend/models.py
@@ -530,9 +530,18 @@ class SignalReport(UUIDModel):
name="signals_report_first_visible",
),
# Back the inbox `search` filter. On UPPER(...) because icontains compiles to
- # UPPER(col) LIKE UPPER(pattern) on Postgres.
- GinIndex(OpClass(Upper("title"), name="gin_trgm_ops"), name="signals_report_title_trgm"),
- GinIndex(OpClass(Upper("summary"), name="gin_trgm_ops"), name="signals_report_summary_trgm"),
+ # UPPER(col) 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("title"), name="gin_trgm_ops"),
+ name="signals_report_title_trgm",
+ fastupdate=False,
+ ),
+ GinIndex(
+ OpClass(Upper("summary"), name="gin_trgm_ops"),
+ name="signals_report_summary_trgm",
+ fastupdate=False,
+ ),
]
constraints = [
# The barrier itself, not a lookup aid: two emits racing on one key both reach the