Rewrite the combos query so it stops timing out - #3380
Merged
Merged
Conversation
howardchung
approved these changes
Sep 16, 2026
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 Combos page joins player_matches once per player slot, ten times, even when you only pick two heroes. Against the explorer's 15s statement timeout that query doesn't come back: I ran the page's own query for a 1v1 and a 2v2 and both timed out.
The plan explains it. 18 nested loops, and the inner node is estimated at 1.1 billion rows. The top line cost looks small (434) only because the planner assumes LIMIT 500 will be satisfied early, so when the combination isn't common it grinds until the timeout instead.
This does the lookup in one pass: filter player_matches to the picked heroes, group by match_id, let HAVING enforce that each side has its own, then read the compositions back for the few matches that survive.
Measured against the current query within the same minute:
Output is unchanged: same columns, and the composition arrays keep the layout the results table depends on, team A ending with the picked heroes in reverse pick order and team B starting with them. Verified on a real result.
One caveat, this is faster but not immune. The read replica varies a lot right now (the same query ran in 6.3s at one point and timed out an hour later), so heavy selections can still hit the cap. odota/core#2982 helps from the other side by covering match_id in the hero_id index, which is where most of the remaining cost sits.