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.

chore(taxonomy): drop the team-keyed property definition query index (#114846)

Eli Reisman7084a2f8735c
diff --git a/products/event_definitions/backend/migrations/0015_drop_index_property_def_query.py b/products/event_definitions/backend/migrations/0015_drop_index_property_def_query.py
new file mode 100644
index 000000000000..640bc54b3d3c
--- /dev/null
+++ b/products/event_definitions/backend/migrations/0015_drop_index_property_def_query.py
@@ -0,0 +1,16 @@
+from django.db import migrations
+
+from posthog.migration_helpers import SafeRemoveIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ # Concurrent index drops cannot run inside a transaction.
+ atomic = False
+
+ dependencies = [("event_definitions", "0014_drop_taxonomy_project_id_fk_idx")]
+
+ operations = [
+ # The team-keyed twin of index_property_def_query_proj. Readers moved to the project key, and the
+ # remaining team-keyed reads plan on posthog_pro_team_id_eac36d_idx without it.
+ SafeRemoveIndexConcurrently(model_name="propertydefinition", name="index_property_def_query"),
+ ]
diff --git a/products/event_definitions/backend/migrations/max_migration.txt b/products/event_definitions/backend/migrations/max_migration.txt
index 7e3789e2a6c1..4469ee86d027 100644
--- a/products/event_definitions/backend/migrations/max_migration.txt
+++ b/products/event_definitions/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0014_drop_taxonomy_project_id_fk_idx
+0015_drop_index_property_def_query
diff --git a/products/event_definitions/backend/models/property_definition.py b/products/event_definitions/backend/models/property_definition.py
index 67f08c6f6252..e5bd193fe2d7 100644
--- a/products/event_definitions/backend/models/property_definition.py
+++ b/products/event_definitions/backend/models/property_definition.py
@@ -117,14 +117,6 @@ class PropertyDefinition(Taggable, UUIDTModel):
models.Index(fields=["project"], name="posthog_prop_proj_id_d3eb982d"),
# This indexes the query in api/property_definition.py
# :KLUDGE: django ORM typing is off here
- models.Index(
- F("team_id"),
- F("type"),
- Coalesce(F("group_type_index"), -1),
- F("query_usage_30_day").desc(nulls_last=True),
- F("name").asc(),
- name="index_property_def_query",
- ),
models.Index(
Coalesce(F("project_id"), F("team_id")),
F("type"),