-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up existing indices on
Upload
(aka ReportSession
)
This in particular cleans up the existing indices that exist in the production DB but not in django: - `reports_upload_order_number_upload_type_report_id_index`: This index actually has the *reverse* order that the one above, which means that frequent updates to the `order_number` lead to a lot of costly index updates. - `reports_upload_report_id_f6b4ffae`: Queries on `report_id` should already been covered by the newly added index on `report_id`+`upload_type`.
- Loading branch information
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
shared/django_apps/reports/migrations/0036_upload_indices_part2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.2.16 on 2024-11-28 12:37 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
atomic = False | ||
|
||
dependencies = [ | ||
("reports", "0035_upload_indices_part1"), | ||
] | ||
|
||
operations = [ | ||
migrations.SeparateDatabaseAndState( | ||
state_operations=[ | ||
migrations.RemoveIndex( | ||
model_name="reportsession", | ||
name="upload_index_id_type_number", | ||
), | ||
], | ||
database_operations=[ | ||
# We drop these indices for the following reasons: | ||
# - `upload_index_id_type_number`: This matches the above state migration, | ||
# and it looks like the index does not actually exist in the production DB. | ||
# The following indices exist in the production DB, but not in django state/migrations: | ||
# - `reports_upload_order_number_upload_type_report_id_index`: | ||
# This index actually has the *reverse* order that the one above, which means that frequent updates | ||
# to the `order_number` lead to a lot of costly index updates. | ||
# - `reports_upload_report_id_f6b4ffae`: Queries on `report_id` should already been covered by the | ||
# newly added index on `report_id`+`upload_type`. | ||
migrations.RunSQL( | ||
sql=""" | ||
DROP INDEX CONCURRENTLY IF EXISTS "upload_index_id_type_number"; | ||
DROP INDEX CONCURRENTLY IF EXISTS "reports_upload_order_number_upload_type_report_id_index"; | ||
DROP INDEX CONCURRENTLY IF EXISTS "reports_upload_report_id_f6b4ffae"; | ||
""" | ||
), | ||
], | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters