Draft: Modify index_non_requested_project_members_on_source_id_and_type on members table
What does this MR do?
Modify the index_non_requested_project_members_on_source_id_and_type
index on the members
table. Since we can't actually modify the index, we need to remove
and add it back with the modified options.
This is taken from #329936 (comment 581777031).
!62759 (merged) modified the SQL query generated by Group#billed_project_members
to improve performance. The modified index in this MR further improves the performance of the Group#billed_project_members
SQL query, by allowing an index-only scan to be used.
Migration:
== 20210528151425 ModifyProjectMembersIndex: migrating ========================
-- execute("SET statement_timeout TO 0")
-> 0.0027s
-- execute("CREATE INDEX CONCURRENTLY index_non_requested_project_members_on_source_id_and_type1 ON members USING btree (source_id, source_type) INCLUDE (user_id, invite_token, access_level)WHERE ((requested_at IS NULL) AND ((type):: text = 'ProjectMember' :: text))")
-> 0.0047s
-- execute("RESET ALL")
-> 0.0007s
-- execute("COMMENT ON INDEX index_non_requested_project_members_on_source_id_and_type1 IS 'Included columns (user_id, invite_token, access_level) improve performance of the Group#billed_project_members query'")
-> 0.0012s
== 20210528151425 ModifyProjectMembersIndex: migrated (0.0111s) ===============
== 20210528154239 RemoveProjectMembersIndex: migrating ========================
-- transaction_open?()
-> 0.0000s
-- indexes("members")
-> 0.0044s
-- remove_index("members", {:algorithm=>:concurrently, :name=>"index_non_requested_project_members_on_source_id_and_type"})
-> 0.0016s
== 20210528154239 RemoveProjectMembersIndex: migrated (0.0068s) ===============
Revert migration:
== 20210528154239 RemoveProjectMembersIndex: reverting ========================
-- transaction_open?()
-> 0.0000s
-- index_exists?(:members, [:source_id, :source_type], {:where=>"requested_at IS NULL and type = 'ProjectMember'", :name=>"index_non_requested_project_members_on_source_id_and_type", :algorithm=>:concurrently})
-> 0.0047s
-- execute("SET statement_timeout TO 0")
-> 0.0007s
-- add_index(:members, [:source_id, :source_type], {:where=>"requested_at IS NULL and type = 'ProjectMember'", :name=>"index_non_requested_project_members_on_source_id_and_type", :algorithm=>:concurrently})
-> 0.0160s
-- execute("RESET ALL")
-> 0.0025s
== 20210528154239 RemoveProjectMembersIndex: reverted (0.0250s) ===============
== 20210528151425 ModifyProjectMembersIndex: reverting ========================
-- transaction_open?()
-> 0.0000s
-- indexes("members")
-> 0.0064s
-- execute("SET statement_timeout TO 0")
-> 0.0007s
-- remove_index("members", {:algorithm=>:concurrently, :name=>"index_non_requested_project_members_on_source_id_and_type1"})
-> 0.0020s
-- execute("RESET ALL")
-> 0.0009s
== 20210528151425 ModifyProjectMembersIndex: reverted (0.0111s) ===============
Original index
CREATE INDEX index_non_requested_project_members_on_source_id_and_type ON members USING btree (source_id, source_type)
WHERE
(
(requested_at IS NULL)
AND (
(type):: text = 'ProjectMember' :: text
)
)
Query with the original index: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/4591/commands/16245
Time: 3.160 s
- planning: 9.996 ms
- execution: 3.150 s
- I/O read: 1.470 s
- I/O write: 0.000 ms
Shared buffers:
- hits: 1117944 (~8.50 GiB) from the buffer pool
- reads: 63288 (~494.40 MiB) from the OS file cache, including disk I/O
- dirtied: 984 (~7.70 MiB)
- writes: 0
Query using gitlab-org group ID with original index: https://console.postgres.ai/shared/8851cef4-26ed-40c5-a88d-2b984c5b122a
Time: 228.889 ms
- planning: 10.585 ms
- execution: 218.304 ms
- I/O read: 188.794 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 8135 (~63.60 MiB) from the buffer pool
- reads: 4986 (~39.00 MiB) from the OS file cache, including disk I/O
- dirtied: 129 (~1.00 MiB)
- writes: 0
Modified index
CREATE INDEX index_non_requested_project_members_on_source_id_and_type1 ON members USING btree (source_id, source_type) include (
user_id, access_level
)
WHERE
(
requested_at IS NULL AND
invite_token IS NULL AND
(
(type):: text = 'ProjectMember' :: text
)
)
Query with the modified index: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/4591/commands/16207
Time: 1.643 s
- planning: 9.593 ms
- execution: 1.634 s
- I/O read: 398.252 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 82564 (~645.00 MiB) from the buffer pool
- reads: 16131 (~126.00 MiB) from the OS file cache, including disk I/O
- dirtied: 979 (~7.60 MiB)
- writes: 0
Query using gitlab-org group ID with modified index: https://console.postgres.ai/shared/9b84440e-ef61-41ee-b9df-1f833d91a82c
Time: 162.114 ms
- planning: 10.071 ms
- execution: 152.043 ms
- I/O read: 126.215 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 8846 (~69.10 MiB) from the buffer pool
- reads: 3875 (~30.30 MiB) from the OS file cache, including disk I/O
- dirtied: 124 (~992.00 KiB)
- writes: 0
Screenshots (strongly suggested)
Does this MR meet the acceptance criteria?
Conformity
-
I have included a changelog entry, or it's not needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Security
Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.
- Label as security and @ mention
@gitlab-com/gl-security/appsec
- The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- Security reports checked/validated by a reviewer from the AppSec team
Related to #331837