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(data-warehouse): index the saved query list ordering (#95557)

posthog[bot]428865c70866
diff --git a/products/data_modeling/backend/migrations/0046_dwsavedquery_team_live_created_idx.py b/products/data_modeling/backend/migrations/0046_dwsavedquery_team_live_created_idx.py
new file mode 100644
index 000000000000..f4ed64c33d17
--- /dev/null
+++ b/products/data_modeling/backend/migrations/0046_dwsavedquery_team_live_created_idx.py
@@ -0,0 +1,22 @@
+from django.db import migrations, models
+
+from posthog.migration_helpers import SafeAddIndexConcurrently
+
+
+class Migration(migrations.Migration):
+ atomic = False
+
+ dependencies = [
+ ("data_modeling", "0045_node_metric_indexes"),
+ ]
+
+ operations = [
+ SafeAddIndexConcurrently(
+ model_name="datawarehousesavedquery",
+ index=models.Index(
+ condition=models.Q(("deleted", True), _negated=True),
+ fields=["team_id", "-created_at"],
+ name="dwsavedquery_team_live_created",
+ ),
+ ),
+ ]
diff --git a/products/data_modeling/backend/migrations/max_migration.txt b/products/data_modeling/backend/migrations/max_migration.txt
index c4864d3f066b..0eddef7ef760 100644
--- a/products/data_modeling/backend/migrations/max_migration.txt
+++ b/products/data_modeling/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0045_node_metric_indexes
+0046_dwsavedquery_team_live_created_idx
diff --git a/products/data_modeling/backend/models/datawarehouse_saved_query.py b/products/data_modeling/backend/models/datawarehouse_saved_query.py
index 38e669477c49..2d6e50f715f0 100644
--- a/products/data_modeling/backend/models/datawarehouse_saved_query.py
+++ b/products/data_modeling/backend/models/datawarehouse_saved_query.py
@@ -226,6 +226,11 @@ class DataWarehouseSavedQuery(CreatedMetaFields, UUIDTModel, UpdatedMetaFields,
name="dwsavedquery_team_live_matvw",
condition=~models.Q(deleted=True),
),
+ models.Index(
+ fields=["team_id", "-created_at"],
+ name="dwsavedquery_team_live_created",
+ condition=~models.Q(deleted=True),
+ ),
]
@property