Improve query for getting users for review #1891
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous query had a problem where if some user was missing in the
review_prefs
table, it would not be returned from the query. This is problematic, because for several reasons, thereview_prefs
table might be incomplete, and in general, it should be possible to get users even if they are not in thereview_prefs
table.There is one problem with the new query though, because there is no index on the
users.username
column, this will result in a sequential scan on theusers
table. It's probably still fast enough, but I wanted to mention it.The
LEAST
clause was not required, I think. The addedCOALESCE
is needed to treat the number of PRs for people missing inreview_prefs
as zero, otherwise they would be again ignored.You can experiment with this in https://onecompiler.com/postgresql/43722tb3w.