Skip to content

Add partial index on oauth_access_grants for cleanup worker

What does this MR do and why?

Add partial index on oauth_access_grants for cleanup worker

Adds partial index on (id) WHERE revoked_at IS NOT NULL to optimize the upcoming OauthAccessGrantArchiveWorker.

Relates: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/377995
Changelog: performance

References

Main: #377995 (closed)
Worker: !207837 (merged)

Details

Table size: 43 GB (bloated - actual data ~6 GB)
Estimated storage cost: ~42 MB

image

image

Database

Migration

>>> Executing: bin/rails db:migrate:up:main VERSION=20251007154446
main: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 67734
main: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: migrating ========
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0164s
main: -- index_exists?(:oauth_access_grants, [:id], {:where=>"revoked_at IS NOT NULL", :name=>"index_oauth_access_grants_on_id_where_revoked", :algorithm=>:concurrently})
main:    -> 0.0035s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- add_index(:oauth_access_grants, [:id], {:where=>"revoked_at IS NOT NULL", :name=>"index_oauth_access_grants_on_id_where_revoked", :algorithm=>:concurrently})
main:    -> 0.0166s
main: -- execute("RESET statement_timeout")
main:    -> 0.0004s
main: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: migrated (0.0721s) 

main: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 67734
>>> Executing: bin/rails db:migrate:up:ci VERSION=20251007154446
ci: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 67786
ci: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: migrating ========
ci: -- transaction_open?(nil)
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0134s
ci: -- index_exists?(:oauth_access_grants, [:id], {:where=>"revoked_at IS NOT NULL", :name=>"index_oauth_access_grants_on_id_where_revoked", :algorithm=>:concurrently})
ci:    -> 0.0059s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0003s
ci: -- add_index(:oauth_access_grants, [:id], {:where=>"revoked_at IS NOT NULL", :name=>"index_oauth_access_grants_on_id_where_revoked", :algorithm=>:concurrently})
ci:    -> 0.0052s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0003s
ci: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: migrated (0.0674s) 

ci: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 67786

Rollback

>>> Executing: bin/rails db:migrate:down:main VERSION=20251007154446
main: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 70614
main: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: reverting ========
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0181s
main: -- indexes(:oauth_access_grants)
main:    -> 0.0023s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0003s
main: -- remove_index(:oauth_access_grants, {:algorithm=>:concurrently, :name=>"index_oauth_access_grants_on_id_where_revoked"})
main:    -> 0.0022s
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: reverted (0.0598s) 

main: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 70614
>>> Executing: bin/rails db:migrate:down:ci VERSION=20251007154446
ci: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 70696
ci: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: reverting ========
ci: -- transaction_open?(nil)
ci:    -> 0.0000s
ci: -- view_exists?(:postgres_partitions)
ci:    -> 0.0183s
ci: -- indexes(:oauth_access_grants)
ci:    -> 0.0059s
ci: -- execute("SET statement_timeout TO 0")
ci:    -> 0.0004s
ci: -- remove_index(:oauth_access_grants, {:algorithm=>:concurrently, :name=>"index_oauth_access_grants_on_id_where_revoked"})
ci:    -> 0.0031s
ci: -- execute("RESET statement_timeout")
ci:    -> 0.0004s
ci: == 20251007154446 AddIndexToOauthAccessGrantsIdWhereRevoked: reverted (0.0786s) 

ci: == [advisory_lock_connection] object_id: 129160, pg_backend_pid: 70696

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Daniele Bracciani

Merge request reports

Loading