Add missing indexes on foreign key columns in high-volume tables #74
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/major-domo-database#74
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
PostgreSQL does NOT auto-index foreign key columns (unlike SQLite where the DB is small enough to not matter). The following high-volume columns lack indexes:
stratplay(game_id)— FK join columnstratplay(batter_id)— filtered in batting stats aggregationstratplay(pitcher_id)— filtered in pitching stats aggregationstratplay(runner_id)— filtered in running statsstratgame(season)— heavily filteredstratgame(season, week, game_num)— standings recalculation query orderThese missing indexes cause sequential scans on the largest tables.
Fix
Add a migration to create these indexes. Also add index declarations to the Peewee model
Metaclasses.Severity
Medium — performance degradation, especially as data grows.
PR opened: #95
Added
Metaclasses withindexestoStratGame(indexes onseasonand compositeseason/week/game_num) andStratPlay(indexes ongame_id,batter_id,pitcher_id,runner_id). Also createdmigrations/2026-03-27_add_stratplay_stratgame_indexes.sqlwithCREATE INDEX IF NOT EXISTSstatements for all 6 indexes.