Skip to content

Remove indices with namespace_id on vulnerability_reads 1 of 3

What does this MR do and why?

Removes unused index with namespace_id on vulnerability_reads as we have started to use namespace_id since 2 weeks ago with the change to finder here.

In this MR we are removing index_vuln_reads_on_namespace_id_state_severity_and_vuln_id and the usage of this index can be verified by running the below PromQL in Thanos or Grafana

sum by (type)(rate(pg_stat_user_indexes_idx_scan{env="gprd", indexrelname="index_vuln_reads_on_namespace_id_state_severity_and_vuln_id"}[3h]))

Screenshot_2024-07-11_at_5.47.26_PM

Migration output

bundle exec rake db:migrate:up:main VERSION=20240710130455
main: == [advisory_lock_connection] object_id: 130240, pg_backend_pid: 15772
main: == 20240710130455 DropIdxNsStateSeverityVulnOnReads: migrating ================
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0113s
main: -- indexes(:vulnerability_reads)
main:    -> 0.0133s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0001s
main: -- remove_index(:vulnerability_reads, {:algorithm=>:concurrently, :name=>"index_vuln_reads_on_namespace_id_state_severity_and_vuln_id"})
main:    -> 0.0052s
main: -- execute("RESET statement_timeout")
main:    -> 0.0001s
main: == 20240710130455 DropIdxNsStateSeverityVulnOnReads: migrated (0.0437s) =======

main: == [advisory_lock_connection] object_id: 130240, pg_backend_pid: 15772
bundle exec rake db:migrate:down:main VERSION=20240710130455
main: == [advisory_lock_connection] object_id: 130240, pg_backend_pid: 16252
main: == 20240710130455 DropIdxNsStateSeverityVulnOnReads: reverting ================
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- view_exists?(:postgres_partitions)
main:    -> 0.0145s
main: -- index_exists?(:vulnerability_reads, "namespace_id, state, severity, vulnerability_id DESC", {:name=>"index_vuln_reads_on_namespace_id_state_severity_and_vuln_id", :algorithm=>:concurrently})
main:    -> 0.0075s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0001s
main: -- add_index(:vulnerability_reads, "namespace_id, state, severity, vulnerability_id DESC", {:name=>"index_vuln_reads_on_namespace_id_state_severity_and_vuln_id", :algorithm=>:concurrently})
main:    -> 0.0080s
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == 20240710130455 DropIdxNsStateSeverityVulnOnReads: reverted (0.0448s) =======

main: == [advisory_lock_connection] object_id: 130240, pg_backend_pid: 16252

Related to #470937 (closed)

Edited by Bala Kumar

Merge request reports