Skip to content

Commit 1bf17d3

Browse files
committed
db: add partial indexes on players for active=true query path
Drop redundant plain-ASC rating indexes (players_standard/rapid/blitz_idx) since Postgres can scan the existing DESC NULLS LAST indexes backwards for ASC queries. Add WHERE active=true partial indexes for all API-facing queries: - players_standard_active_idx - players_rapid_active_idx - players_blitz_active_idx - players_federation_id_active_idx The planner will prefer these smaller, denser indexes over the full players_*_desc_idx variants whenever the query includes active=true, which is the case for all public API endpoints.
1 parent 7e64055 commit 1bf17d3

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- Drop plain ASC rating indexes: redundant because Postgres can scan DESC indexes
2+
-- backward for ASC queries, and partial indexes below cover the hot path.
3+
DROP INDEX IF EXISTS players_standard_idx;
4+
DROP INDEX IF EXISTS players_rapid_idx;
5+
DROP INDEX IF EXISTS players_blitz_idx;
6+
7+
-- Partial indexes scoped to active players.
8+
-- All API queries filter WHERE active = true; the planner will prefer these
9+
-- smaller, denser indexes over the full players_*_desc_idx alternatives.
10+
CREATE INDEX players_standard_active_idx ON players (standard DESC NULLS LAST) WHERE active = true;
11+
CREATE INDEX players_rapid_active_idx ON players (rapid DESC NULLS LAST) WHERE active = true;
12+
CREATE INDEX players_blitz_active_idx ON players (blitz DESC NULLS LAST) WHERE active = true;
13+
14+
-- Partial index for federation-scoped lookups (replaces players_federation_id_idx for
15+
-- the active-player query path; the full index is kept for crawler/admin queries).
16+
CREATE INDEX players_federation_id_active_idx ON players (federation_id) WHERE active = true;

0 commit comments

Comments
 (0)