From d6d67fe5c5e930338b9bac9783a97868bc20077a Mon Sep 17 00:00:00 2001 From: NisanthanNanthakumar Date: Fri, 15 Sep 2023 12:53:46 -0700 Subject: [PATCH] feat(escalating-issues): Create new index on Group for more efficient query (#56345) ## Objective: Re-revert of https://github.com/getsentry/sentry/pull/56180 This time with `is_dangerous=True` --- migrations_lockfile.txt | 2 +- ...3_add_new_index_to_groupedmessage_table.py | 39 +++++++++++++++++++ src/sentry/models/group.py | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/sentry/migrations/0553_add_new_index_to_groupedmessage_table.py diff --git a/migrations_lockfile.txt b/migrations_lockfile.txt index 8276c0c589bd59..09be0e07f83b43 100644 --- a/migrations_lockfile.txt +++ b/migrations_lockfile.txt @@ -8,5 +8,5 @@ will then be regenerated, and you should be able to merge without conflicts. feedback: 0002_feedback_add_org_id_and_rename_event_id nodestore: 0002_nodestore_no_dictfield replays: 0003_add_size_to_recording_segment -sentry: 0552_create_neglectedalert_table +sentry: 0553_add_new_index_to_groupedmessage_table social_auth: 0002_default_auto_field diff --git a/src/sentry/migrations/0553_add_new_index_to_groupedmessage_table.py b/src/sentry/migrations/0553_add_new_index_to_groupedmessage_table.py new file mode 100644 index 00000000000000..536bb78a59b4b6 --- /dev/null +++ b/src/sentry/migrations/0553_add_new_index_to_groupedmessage_table.py @@ -0,0 +1,39 @@ +# Generated by Django 3.2.20 on 2023-09-15 19:22 + +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 + + dependencies = [ + ("sentry", "0552_create_neglectedalert_table"), + ] + + operations = [ + migrations.AlterIndexTogether( + name="group", + index_together={ + ("project", "status", "last_seen", "id"), + ("project", "status", "type", "last_seen", "id"), + ("project", "id"), + ("project", "status", "substatus", "id"), + ("project", "status", "substatus", "last_seen", "id"), + ("project", "status", "substatus", "type", "last_seen", "id"), + ("project", "first_release"), + ("status", "substatus", "id"), + }, + ), + ] diff --git a/src/sentry/models/group.py b/src/sentry/models/group.py index 8e0091b98bfc9a..434c3f902bc3f4 100644 --- a/src/sentry/models/group.py +++ b/src/sentry/models/group.py @@ -544,6 +544,7 @@ class Meta: ("project", "status", "substatus", "last_seen", "id"), ("project", "status", "substatus", "type", "last_seen", "id"), ("project", "status", "substatus", "id"), + ("status", "substatus", "id"), ] unique_together = ( ("project", "short_id"),