Use a CTE for the unscoped issuable label filter

What does this MR do and why?

Without a project or group scope the label filter matches labels by title. One title can be shared by millions of label rows, so the planner drives the query from label_links and times out.

Apply the label filter after the other filters, behind a materialized CTE, so it runs against the already-narrowed set. Gated on a specific user filter being present, since the CTE needs a bounded inner set, and skipped for priority sorts and grouped queries, which rebuild the relation and would discard the CTE.

Plans

Merge request:

https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/55636/commands/159479

Issues:

https://console.postgres.ai/gitlab/projects/gitlab-production-main/sessions/55636/commands/159481

References

#603780

Screenshots or screen recordings

Before After

How to set up and validate locally

MR acceptance checklist

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

Edited by Phil Hughes

Merge request reports

Loading
Loading