: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
perf(data-warehouse): add partial indexes for live catalog rows (#95112)
José Sequeira81977dcbbc04
diff --git a/products/data_modeling/backend/migrations/0032_datawarehousesavedquery_dwsavedquery_team_live_name.py b/products/data_modeling/backend/migrations/0032_datawarehousesavedquery_dwsavedquery_team_live_name.pynew file mode 100644index 000000000000..16ebb0b16eec--- /dev/null+++ b/products/data_modeling/backend/migrations/0032_datawarehousesavedquery_dwsavedquery_team_live_name.py@@ -0,0 +1,29 @@+# Generated by Django 5.2.17 on 2026-09-04 12:12++from django.conf import settings+from django.db import migrations, models++from posthog.migration_helpers import SafeAddIndexConcurrently+++class Migration(migrations.Migration):+ atomic = False++ dependencies = [+ ("data_modeling", "0031_datamodelingjob_run_mode"),+ ("data_tools", "0003_datawarehouseexpression"),+ ("posthog", "1340_drop_userproductlist_reason_columns"),+ ("warehouse_sources", "0159_externaldatajob_destination_ids_and_more"),+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),+ ]++ operations = [+ SafeAddIndexConcurrently(+ model_name="datawarehousesavedquery",+ index=models.Index(+ condition=models.Q(("deleted", True), _negated=True),+ fields=["team_id", "name"],+ name="dwsavedquery_team_live_name",+ ),+ ),+ ]diff --git a/products/data_modeling/backend/migrations/max_migration.txt b/products/data_modeling/backend/migrations/max_migration.txtindex 26aabf821c60..57f6099077f1 100644--- a/products/data_modeling/backend/migrations/max_migration.txt+++ b/products/data_modeling/backend/migrations/max_migration.txt@@ -1 +1 @@-0031_datamodelingjob_run_mode+0032_datawarehousesavedquery_dwsavedquery_team_live_namediff --git a/products/data_modeling/backend/models/datawarehouse_saved_query.py b/products/data_modeling/backend/models/datawarehouse_saved_query.pyindex ff23465f306f..aa27d02b1e4a 100644--- a/products/data_modeling/backend/models/datawarehouse_saved_query.py+++ b/products/data_modeling/backend/models/datawarehouse_saved_query.py@@ -200,6 +200,16 @@ class DataWarehouseSavedQuery(CreatedMetaFields, UUIDTModel, UpdatedMetaFields,)]db_table = "posthog_datawarehousesavedquery"+ indexes = [+ # The HogQL database build reads a team's live saved queries ordered by name on+ # every query. ~Q(deleted=True) compiles to the same SQL as .exclude(deleted=True),+ # so the planner matches the partial predicate without proving implication.+ models.Index(+ fields=["team_id", "name"],+ name="dwsavedquery_team_live_name",+ condition=~models.Q(deleted=True),+ )+ ]@propertydef name_chain(self) -> list[str]:diff --git a/products/warehouse_sources/backend/migrations/0160_datawarehousetable_dwtable_team_live_created.py b/products/warehouse_sources/backend/migrations/0160_datawarehousetable_dwtable_team_live_created.pynew file mode 100644index 000000000000..d38128dc12ec--- /dev/null+++ b/products/warehouse_sources/backend/migrations/0160_datawarehousetable_dwtable_team_live_created.py@@ -0,0 +1,27 @@+# Generated by Django 5.2.17 on 2026-09-04 12:12++from django.conf import settings+from django.db import migrations, models++from posthog.migration_helpers import SafeAddIndexConcurrently+++class Migration(migrations.Migration):+ atomic = False++ dependencies = [+ ("posthog", "1340_drop_userproductlist_reason_columns"),+ ("warehouse_sources", "0159_externaldatajob_destination_ids_and_more"),+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),+ ]++ operations = [+ SafeAddIndexConcurrently(+ model_name="datawarehousetable",+ index=models.Index(+ condition=models.Q(("deleted", True), _negated=True),+ fields=["team_id", "-created_at"],+ name="dwtable_team_live_created",+ ),+ ),+ ]diff --git a/products/warehouse_sources/backend/migrations/max_migration.txt b/products/warehouse_sources/backend/migrations/max_migration.txtindex 0f316a890750..4c371aefe89a 100644--- a/products/warehouse_sources/backend/migrations/max_migration.txt+++ b/products/warehouse_sources/backend/migrations/max_migration.txt@@ -1 +1 @@-0159_externaldatajob_destination_ids_and_more+0160_datawarehousetable_dwtable_team_live_createddiff --git a/products/warehouse_sources/backend/models/table.py b/products/warehouse_sources/backend/models/table.pyindex b0962a247d07..712bc03eaadb 100644--- a/products/warehouse_sources/backend/models/table.py+++ b/products/warehouse_sources/backend/models/table.py@@ -346,6 +346,16 @@ class DataWarehouseTable(CreatedMetaFields, UpdatedMetaFields, UUIDTModel, Deletclass Meta:db_table = "posthog_datawarehousetable"+ indexes = [+ # The HogQL database build reads a team's live tables ordered by created_at DESC on+ # every query. ~Q(deleted=True) compiles to the same SQL as .exclude(deleted=True),+ # so the planner matches the partial predicate without proving implication.+ models.Index(+ fields=["team_id", "-created_at"],+ name="dwtable_team_live_created",+ condition=~models.Q(deleted=True),+ )+ ]def save(self, *args: Any, internally_computed_url_pattern: bool = False, **kwargs: Any) -> None:if not internally_computed_url_pattern: