Viewing all issues on namespace causes 500 error, 500 error also on certain MR searches within same namespace

Summary

From Zendesk ticket (internal link):

Just navigating to https://gitlab.com/groups/namespace/-/issues throws a 500 error. Users who wish to search Issues or MRs from the group scope get 500 errors.

For example: https://gitlab.com/groups/<namespace>/-/merge_requests?scope=all&state=opened&author_username=<redacted>&search=<redacted>

Request ID: 01G5PPNRV72EK79HD38H8BA0YQ https://gitlab.com/groups/<namespace>/-/issues?search=<redacted>&sort=updated_desc&state=opened&author_username=<redacted>

Request ID: 01G5PPGB76KMYJ1AY3ZDDWJVRJ

Even a simple author search throws 500 errors every time. https://gitlab.com/groups/<namespace>/-/merge_requests?scope=all&state=opened&author_username=<redacted>

Request ID: 01G5PQ99ZS9HPH1CHS5DQXYY6A

A few weeks ago this was working fine.

I searched for the first of those Request ID's in Kibana and saw PG::QueryCanceled: ERROR: canceling statement due to statement timeout.

Customer in question only has about 1800 open issues and 3100 MRs.

Steps to reproduce

Example Project

What is the current bug behavior?

What is the expected correct behavior?

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Michael Gibson