Improve DB performance of Issuable finders
requested to merge 361687-group-activity-analytics-analytics-group_activity-merge_requests_count-api-exceeds-target-duration into master
What does this MR do and why?
This MR tries to improve performance of issuables fetching query. No user facing changes here.
Database migration
main: == 20220602130306 AddNamespaceTypeIndex: reverting ============================
main: -- transaction_open?()
main: -> 0.0000s
main: -- indexes(:namespaces)
main: -> 0.0682s
main: -- remove_index(:namespaces, {:algorithm=>:concurrently, :name=>"index_groups_on_parent_id_id"})
main: -> 0.0066s
main: == 20220602130306 AddNamespaceTypeIndex: reverted (0.0928s) ===================
main: == 20220602130306 AddNamespaceTypeIndex: migrating ============================
main: -- transaction_open?()
main: -> 0.0000s
main: -- index_exists?(:namespaces, [:parent_id, :id], {:where=>"type = 'Group'", :name=>"index_groups_on_parent_id_id", :algorithm=>:concurrently})
main: -> 0.0599s
main: -- add_index(:namespaces, [:parent_id, :id], {:where=>"type = 'Group'", :name=>"index_groups_on_parent_id_id", :algorithm=>:concurrently})
main: -> 0.0113s
main: == 20220602130306 AddNamespaceTypeIndex: migrated (0.0859s) ===================
Query plans
Query | Before | After | Performance stats |
---|---|---|---|
Issues count | 87k hits 200ms | 85k hits 170ms | +- the same |
MRs count | 113k hits 140ms | 56k hits 100ms | 40% faster, 50% less data reads |
Issues list | 113k hits 230ms | 85k hits 230ms | 20% less data reads |
MRs list | 109k hits 190ms | 52k hit 120ms | 60% faster, 50% less data reads |
There is one more problem I found: primary key of project_authorizations
seem to be corrupted or something. It's not picked up in query plan but if you remove it and recreate again - it will be picked up. I'm not sure if it's database-lab only problem. Also not sure on the best approach how to fix it. Fixing that will save us few thousands buffer reads.
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.
Related to #361687 (closed)
Edited by Pavel Shutsin