Remove DISTINCT from game queries, refix #901#1314
Merged
Conversation
In #902 I added `DISTINCT` to the game search query, to fix a bug where searches by competition could show duplicates, if the same game appeared in multiple divisions. It turns out that adding `DISTINCT` prevents the query planner from doing simple index scans, e.g. when simply querying for the newest games. So I've removed `DISTINCT` in this commit, and re-fixed #901 by querying `compgames` with a subquery with a `distinct` clause. Fixes #1287.
ff6b8a1 to
23d04de
Compare
salty-horse
approved these changes
Aug 16, 2025
This was referenced Aug 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In #902 I added
DISTINCTto the game search query, to fix a bug where searches by competition could show duplicates, if the same game appeared in multiple divisions.It turns out that adding
DISTINCTprevents the query planner from doing fast index scans, e.g. when simply querying for the newest games, it would do a full scan of all rows in the index, rather than just the N newest rows.So I've removed
DISTINCTin this commit, and re-fixed #901 by queryingcompgameswith a subquery with adistinctclause.Fixes #1287
Before
Simple query for new games, full scan
http://localhost:8080/search?browse&sortby=lnew
Query for IFComp 2024 games
http://localhost:8080/search?searchbar=competitionid:4lxgmwam7owmbb9h
After
Simple query for new games, fast index scan
In particular note
r_rowsbefore and after. Before this PR it was 14371, but after it was 100.rowsis the planners estimate of how many rows it would have to scan.Query for IFComp 2024 games