Jonah Heim Was Leading the Home Run Race
For a stretch, Ballpark Genius’s home run leaderboard had Jonah Heim on top. One home run. The query behind it filtered WHERE team_id = 0 to get season-total rows instead of per-team splits, correct for a player who’s been traded, MLB gives those a team_id = 0 aggregate row, and wrong for literally everyone else, who only has per-team rows. That left about seven hitters and eight pitchers as the entire eligible pool for every leaderboard on the site. Whoever had the highest single stat among that tiny, mostly-irrelevant group won.

Fixed with one query instead of two: DISTINCT ON (player_id) ORDER BY player_id, team_id ASC picks the team_id = 0 row for anyone who has one and falls through to their single per-team row otherwise, then the outer query sorts and takes the top N like it always should have. Checked it live after: Judge, Alvarez, Schwarber, back where they belong.
Small, dumb, expensive bug. The kind where the fix is three lines and the entire distance between “leaderboard” and “not a leaderboard” was one wrong WHERE clause the whole time.