fix: add missing indexes on FK columns in stratplay and stratgame (#74) #95
@ -31,6 +31,7 @@ db = PooledPostgresqlDatabase(
|
|||||||
autorollback=True, # Automatically rollback failed transactions
|
autorollback=True, # Automatically rollback failed transactions
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
date = f"{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}"
|
date = f"{datetime.datetime.now().year}-{datetime.datetime.now().month}-{datetime.datetime.now().day}"
|
||||||
logger = logging.getLogger("discord_app")
|
logger = logging.getLogger("discord_app")
|
||||||
|
|
||||||
@ -2481,6 +2482,12 @@ class StratGame(BaseModel):
|
|||||||
home_stan.save()
|
home_stan.save()
|
||||||
away_stan.save()
|
away_stan.save()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
indexes = (
|
||||||
|
(("season",), False),
|
||||||
|
(("season", "week", "game_num"), False),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class StratPlay(BaseModel):
|
class StratPlay(BaseModel):
|
||||||
game = ForeignKeyField(StratGame)
|
game = ForeignKeyField(StratGame)
|
||||||
@ -2555,6 +2562,14 @@ class StratPlay(BaseModel):
|
|||||||
re24_primary = FloatField(null=True)
|
re24_primary = FloatField(null=True)
|
||||||
re24_running = FloatField(null=True)
|
re24_running = FloatField(null=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
indexes = (
|
||||||
|
(("game",), False),
|
||||||
|
(("batter",), False),
|
||||||
|
(("pitcher",), False),
|
||||||
|
(("runner",), False),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Decision(BaseModel):
|
class Decision(BaseModel):
|
||||||
game = ForeignKeyField(StratGame)
|
game = ForeignKeyField(StratGame)
|
||||||
|
|||||||
24
migrations/2026-03-27_add_stratplay_stratgame_indexes.sql
Normal file
24
migrations/2026-03-27_add_stratplay_stratgame_indexes.sql
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
-- 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);
|
||||||
Loading…
Reference in New Issue
Block a user