Add indices for protected_environments and protected_environment_approval_rules
requested to merge add-indices-on-created-at-for-protected-environments-and-protected-environment-approval-rules into master
What does this MR do and why?
This merge request adds a new index for the following two tables:
-
protected_environments
: onrequired_approval_count
andcreated_at
-
protected_environment_approval_rules
: onrequired_approvals
andcreated_at
The indices are added to ensure metrics introduced in !90089 (merged) avoid sequential scans when querying the tables (check this and this if you need to learn more).
Queries Before & After
Please check the links from database-lab below for queries before/after the changes introduced here for verification:
Before:
- query for
protected_environments
- query for
protected_environment_approval_rules
After:
- query for
protected_environments
- query for
protected_environment_approval_rules
Resolves #366559 (closed).
Migration & Rollback Output
Migration
main: == 20220708142744 AddCompositeIndexForProtectedEnvironments: migrating ========
main: -- transaction_open?()
main: -> 0.0000s
main: -- index_exists?(:protected_environments, [:required_approval_count, :created_at], {:name=>"index_protected_environments_on_approval_count_and_created_at", :algorithm=>:concurrently})
main: -> 0.0077s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0005s
main: -- add_index(:protected_environments, [:required_approval_count, :created_at], {:name=>"index_protected_environments_on_approval_count_and_created_at", :algorithm=>:concurrently})
main: -> 0.0020s
main: -- execute("RESET statement_timeout")
main: -> 0.0005s
main: == 20220708142744 AddCompositeIndexForProtectedEnvironments: migrated (0.0202s)
main: == 20220708142803 AddCompositeIndexForProtectedEnvironmentApprovalRules: migrating
main: -- transaction_open?()
main: -> 0.0000s
main: -- index_exists?(:protected_environment_approval_rules, [:required_approvals, :created_at], {:name=>"index_pe_approval_rules_on_required_approvals_and_created_at", :algorithm=>:concurrently})
main: -> 0.0041s
main: -- add_index(:protected_environment_approval_rules, [:required_approvals, :created_at], {:name=>"index_pe_approval_rules_on_required_approvals_and_created_at", :algorithm=>:concurrently})
main: -> 0.0013s
main: == 20220708142803 AddCompositeIndexForProtectedEnvironmentApprovalRules: migrated (0.0093s)
Rollback
main: == 20220708142803 AddCompositeIndexForProtectedEnvironmentApprovalRules: reverting
main: -- transaction_open?()
main: -> 0.0000s
main: -- index_exists?(:protected_environment_approval_rules, [:required_approvals, :created_at], {:name=>"index_pe_approval_rules_on_required_approvals_and_created_at", :algorithm=>:concurrently})
main: -> 0.0223s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0006s
main: -- remove_index(:protected_environment_approval_rules, {:name=>"index_pe_approval_rules_on_required_approvals_and_created_at", :algorithm=>:concurrently, :column=>[:required_approvals, :created_at]})
main: -> 0.0071s
main: -- execute("RESET statement_timeout")
main: -> 0.0006s
main: == 20220708142803 AddCompositeIndexForProtectedEnvironmentApprovalRules: reverted (0.0430s)
main: == 20220708142744 AddCompositeIndexForProtectedEnvironments: reverting ========
main: -- transaction_open?()
main: -> 0.0000s
main: -- index_exists?(:protected_environments, [:required_approval_count, :created_at], {:name=>"index_protected_environments_on_approval_count_and_created_at", :algorithm=>:concurrently})
main: -> 0.0088s
main: -- execute("SET statement_timeout TO 0")
main: -> 0.0004s
main: -- remove_index(:protected_environments, {:name=>"index_protected_environments_on_approval_count_and_created_at", :algorithm=>:concurrently, :column=>[:required_approval_count, :created_at]})
main: -> 0.0060s
main: -- execute("RESET statement_timeout")
main: -> 0.0004s
main: == 20220708142744 AddCompositeIndexForProtectedEnvironments: reverted (0.0259s)
For more details, please check out the db:check-migrations
job.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Ahmed Hemdan