-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new indexes on reporting_patient_states (#5349)
**Story card:** [sc-11600](https://app.shortcut.com/simpledotorg/story/11600/optimize-queries-used-by-dhis2-exporter) The current queries for our monthly DHIS2 exports are slow. We want to add a couple of indexes to the reporting_patient_states table to improve this. This PR adds a migration to create four composite indexes: - on month_date and assigned_facility_id - on month_date and assigned_facility_region_id - on month_date and registration_facility_id - on month_date and registration_facility_region_id We're accounting for both the facility and the facility region because both these fields are used throughout the codebase and we don't want one query to pick up the correct index and not another.
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
db/migrate/20231208091419_add_indexes_to_reporting_patient_states.rb
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,11 @@ | ||
class AddIndexesToReportingPatientStates < ActiveRecord::Migration[6.1] | ||
# Cannot create index concurrently inside a transaction block | ||
self.disable_ddl_transaction = true | ||
|
||
def change | ||
add_index :reporting_patient_states, %i[month_date assigned_facility_id], name: "patient_states_month_date_assigned_facility", algorithm: :concurrently | ||
add_index :reporting_patient_states, %i[month_date assigned_facility_region_id], name: "patient_states_month_date_assigned_facility_region", algorithm: :concurrently | ||
add_index :reporting_patient_states, %i[month_date registration_facility_id], name: "patient_states_month_date_registration_facility", algorithm: :concurrently | ||
add_index :reporting_patient_states, %i[month_date registration_facility_region_id], name: "patient_states_month_date_registration_facility_region", algorithm: :concurrently | ||
end | ||
end |
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