Slow query to find user by public_email
From a current workload analysis in https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/6826, this query takes about 2,500ms and runs at 0.04 times per second. This puts it at TOP3 with respect to total database time in the observed 30-minute period on GitLab.com:
SELECT ? AS one FROM "users" WHERE "users"."public_email" = ? AND ("users"."id" != ?) LIMIT ?
A plan is here: https://explain.depesz.com/s/mWii
There is no index on users.public_email, which would speed up the query. We should add one.
Edited by Andreas Brandl