perf(group): add type index to improve querying on groups 
diff --git a/migrations_lockfile.txt b/migrations_lockfile.txt
index baef691f7e39ac..d94801475b7348 100644
--- a/migrations_lockfile.txt
+++ b/migrations_lockfile.txt
@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0316_add_context_field_to_groupowner
+sentry: 0317_groupedmessage_type_index
 social_auth: 0001_initial
diff --git a/src/sentry/migrations/0317_groupedmessage_type_index.py b/src/sentry/migrations/0317_groupedmessage_type_index.py
new file mode 100644
index 00000000000000..e9320f31ad2db9
--- /dev/null
+++ b/src/sentry/migrations/0317_groupedmessage_type_index.py
@@ -0,0 +1,53 @@
+# Generated by Django 2.2.28 on 2022-09-19 18:59
+
+from django.db import migrations
+
+from sentry.new_migrations.migrations import CheckedMigration
+
+
+class Migration(CheckedMigration):
+    # This flag is used to mark that a migration shouldn't be automatically run in production. For
+    # the most part, this should only be used for operations where it's safe to run the migration
+    # after your code has deployed. So this should not be used for most operations that alter the
+    # schema of a table.
+    # Here are some things that make sense to mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that they can
+    #   be monitored and not block the deploy for a long period of time while they run.
+    # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+    is_dangerous = True
+
+    # This flag is used to decide whether to run this migration in a transaction or not. Generally
+    # we don't want to run in a transaction here, since for long running operations like data
+    # back-fills this results in us locking an increasing number of rows until we finally commit.
+    atomic = False
+
+    dependencies = [
+        ("sentry", "0316_add_context_field_to_groupowner"),
+    ]
+
+    operations = [
+        migrations.SeparateDatabaseAndState(
+            database_operations=[
+                migrations.RunSQL(
+                    """
+                    CREATE INDEX CONCURRENTLY IF NOT EXISTS "sentry_groupedmessage_project_id_type_status_l_074196b6_idx" ON "sentry_groupedmessage" ("project_id", "status", "type", "last_seen", "id");
+                    """,
+                    reverse_sql="DROP INDEX CONCURRENTLY IF EXISTS sentry_groupedmessage_project_id_type_status_l_074196b6_idx",
+                    hints={"tables": ["sentry_groupedmessage"]},
+                ),
+            ],
+            state_operations=[
+                migrations.AlterIndexTogether(
+                    name="group",
+                    index_together={
+                        ("project", "status", "last_seen", "id"),
+                        ("project", "first_release"),
+                        ("project", "status", "type", "last_seen", "id"),
+                        ("project", "id"),
+                    },
+                ),
+            ],
+        )
+    ]
diff --git a/src/sentry/models/group.py b/src/sentry/models/group.py
index 937fd5c5f3019e..df713b1b84cee7 100644
--- a/src/sentry/models/group.py
+++ b/src/sentry/models/group.py
@@ -449,6 +449,7 @@ class Meta:
             ("project", "first_release"),
             ("project", "id"),
             ("project", "status", "last_seen", "id"),
+            ("project", "status", "type", "last_seen", "id"),
         ]
         unique_together = (
             ("project", "short_id"),

Adds a compound index `("project", "type", "status", "last_seen", "id")` to improve query performance. 

Growth team is currently observing timeouts for large projects so this is required.

Fixes WOR-2122