fix: use NOT EXISTS for superseding score set filter to prevent row m…#707
Open
bencap wants to merge 1 commit intorelease-2026.1.3from
Open
fix: use NOT EXISTS for superseding score set filter to prevent row m…#707bencap wants to merge 1 commit intorelease-2026.1.3from
bencap wants to merge 1 commit intorelease-2026.1.3from
Conversation
…ultiplication in search The score set search query filtered out superseded score sets using a LEFT OUTER JOIN on the superseding_score_set relationship. Because replaces_id has no unique constraint, score sets with multiple superseding versions produced N rows per original, all counted against the SQL LIMIT. This caused paginated searches to return fewer unique score sets than requested (~84 instead of 100 on prod). Replace the LEFT JOIN + OR filter with a NOT EXISTS subquery (via .has()), which produces exactly one row per score set regardless of how many superseders exist. Also strengthens the regression test to use multiple keywords per experiment and adds a new test for the multiple-superseders scenario.
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.
The score set search query filtered out superseded score sets using a LEFT OUTER JOIN on the superseding_score_set relationship. Because replaces_id has no unique constraint, score sets with multiple superseding versions produced N rows per original, all counted against the SQL LIMIT. This caused paginated searches to return fewer unique score sets than requested (~84 instead of 100 on prod).
Replace the LEFT JOIN + OR filter with a NOT EXISTS subquery (via .has()), which produces exactly one row per score set regardless of how many superseders exist. Also strengthens the regression test to use multiple keywords per experiment and adds a new test for the multiple-superseders scenario.
Opens #706, which is the root cause of this issue. This fix mitigates consequences for the search endpoint specifically, but does not address all issues caused by the bug.
Although it turns out the
joined_loadsweren't the root cause of this specific issue, I'm leaving the newselect_in_loadsas they still represent an improvement over the prior code and could protect us from future row multiplication.