25 lines
1.1 KiB
SQL
25 lines
1.1 KiB
SQL
-- Migration: Add missing indexes on foreign key columns in stratplay and stratgame
|
|
-- Created: 2026-03-27
|
|
--
|
|
-- PostgreSQL does not auto-index foreign key columns. These tables are the
|
|
-- highest-volume tables in the schema and are filtered/joined on these columns
|
|
-- in batting, pitching, and running stats aggregation and standings recalculation.
|
|
|
|
-- stratplay: FK join column
|
|
CREATE INDEX IF NOT EXISTS idx_stratplay_game_id ON stratplay(game_id);
|
|
|
|
-- stratplay: filtered in batting stats aggregation
|
|
CREATE INDEX IF NOT EXISTS idx_stratplay_batter_id ON stratplay(batter_id);
|
|
|
|
-- stratplay: filtered in pitching stats aggregation
|
|
CREATE INDEX IF NOT EXISTS idx_stratplay_pitcher_id ON stratplay(pitcher_id);
|
|
|
|
-- stratplay: filtered in running stats
|
|
CREATE INDEX IF NOT EXISTS idx_stratplay_runner_id ON stratplay(runner_id);
|
|
|
|
-- stratgame: heavily filtered by season
|
|
CREATE INDEX IF NOT EXISTS idx_stratgame_season ON stratgame(season);
|
|
|
|
-- stratgame: standings recalculation query ordering
|
|
CREATE INDEX IF NOT EXISTS idx_stratgame_season_week_game_num ON stratgame(season, week, game_num);
|