Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve query for getting users for review #1891

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kobzol
Copy link
Contributor

@Kobzol Kobzol commented Jan 24, 2025

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, the review_prefs table might be incomplete, and in general, it should be possible to get users even if they are not in the review_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 the users table. It's probably still fast enough, but I wanted to mention it.

The LEAST clause was not required, I think. The added COALESCE is needed to treat the number of PRs for people missing in review_prefs as zero, otherwise they would be again ignored.

You can experiment with this in https://onecompiler.com/postgresql/43722tb3w.

@apiraino
Copy link
Contributor

The LEAST clause was not required, I think.

So in my comment I was wrong about LEAST, right? 🤔

@Kobzol
Copy link
Contributor Author

Kobzol commented Jan 25, 2025

COALESCE should return the first non-null argument, so it should be enough to do COALESCE(NULL, 100000). I don't think that you need LEAST, if the first argument to COALESCE is non-NULL, it should be returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants