Skip to content

Add index for member_namespace and related columns

Alex Pooley requested to merge ap-namespace-members-assoc-indexes into master

What does this MR do and why?

In !105781 (merged) we are adding a set of new Project and Group member relationships. This index supports those new relationships.

CREATE INDEX CONCURRENTLY "index_members_on_member_namespace_id_compound" ON "members" (
  "member_namespace_id", "type", "requested_at", "id"
)

SQL Query Plans

15846663 is the ID of the project namespace for the gitlab project.

9970 is the gitlab-org group

project.namespace_members
SELECT 
  "members".* 
FROM 
  "members" 
WHERE 
  "members"."type" = 'ProjectMember' 
  AND "members"."member_namespace_id" = 15846663 
  AND "members"."requested_at" IS NULL

Query plan: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/14090/commands/49219


project.namespace_requesters
SELECT 
  "members".* 
FROM 
  "members" 
WHERE 
  "members"."type" = 'ProjectMember' 
  AND "members"."member_namespace_id" = 15846663 
  AND "members"."requested_at" IS NOT NULL

Query plan: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/14090/commands/49220


group.namespace_members
SELECT 
  "members".* 
FROM 
  "members" 
WHERE 
  "members"."type" = 'GroupMember' 
  AND "members"."member_namespace_id" = 9970 
  AND "members"."requested_at" IS NULL 
  AND "members"."access_level" != 5

Query plan: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/14090/commands/49221


group.namespace_requesters
SELECT 
  "members".* 
FROM 
  "members" 
WHERE 
  "members"."type" = 'GroupMember' 
  AND "members"."member_namespace_id" = 9970 
  AND "members"."requested_at" IS NOT NULL

Query plan: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/14090/commands/49222

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alex Pooley

Merge request reports