Skip to content

Add GIN index to member_roles.permissions

What does this MR do and why?

This change adds a GIN index to the member_roles.permissions JSONB column to optimize the queries in !161384 (closed), !161385 (merged) and https://gitlab.com/gitlab-org/gitlab/-/blob/ee92b24be36fb097ce275fff4ace5ff7d75278f9/ee/app/models/preloaders/user_member_roles_in_groups_preloader.rb#L65.

Related to:

MR acceptance checklist

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

Screenshots or screen recordings

SELECT "member_roles".* FROM "member_roles" WHERE (member_roles.permissions @> ('{"admin_runners":true}')::jsonb);

Before:

 Seq Scan on public.member_roles  (cost=0.00..502.01 rows=1 width=372) (actual time=10.876..14.663 rows=1 loops=1)
   Filter: (member_roles.permissions @> '{"admin_runners": true}'::jsonb)
   Rows Removed by Filter: 1868
   Buffers: shared read=119 dirtied=2
   I/O Timings: read=13.386 write=0.000

Time: 15.713 ms
  - planning: 0.994 ms
  - execution: 14.719 ms
    - I/O read: 13.386 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 0 from the buffer pool
  - reads: 119 (~952.00 KiB) from the OS file cache, including disk I/O
  - dirtied: 2 (~16.00 KiB)
  - writes: 0

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/30608/commands/94925

After:

 Bitmap Heap Scan on public.member_roles  (cost=4.50..6.01 rows=1 width=372) (actual time=0.172..0.227 rows=1 loops=1)
   Buffers: shared hit=37
   I/O Timings: read=0.000 write=0.000
   ->  Bitmap Index Scan using idx_member_roles_permissions  (cost=0.00..4.50 rows=1 width=0) (actual time=0.066..0.066 rows=108 loops=1)
         Index Cond: (member_roles.permissions @> '{"admin_runners": true}'::jsonb)
         Buffers: shared hit=5
         I/O Timings: read=0.000 write=0.000

Time: 1.606 ms
  - planning: 1.310 ms
  - execution: 0.296 ms
    - I/O read: 0.000 ms
    - I/O write: 0.000 ms

Shared buffers:
  - hits: 37 (~296.00 KiB) from the buffer pool
  - reads: 0 from the OS file cache, including disk I/O
  - dirtied: 0
  - writes: 0

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/30608/commands/94927

Edited by mo khan

Merge request reports

Loading