Skip to content

Commit a0e0094

Browse files
authored
add index for query leaderboard ranking (#451)
add index for query leaderboard ranking
1 parent 871c774 commit a0e0094

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""
2+
queryindex
3+
"""
4+
5+
from yoyo import step
6+
7+
__depends__ = {'20260225_01_aW5Bu-add-leaderboard-performance-indexes'}
8+
9+
10+
steps = [
11+
# Most critical: partial composite index on runs
12+
step(
13+
"""
14+
CREATE INDEX IF NOT EXISTS idx_runs_valid_scores
15+
ON leaderboard.runs (submission_id, runner, score)
16+
WHERE NOT secret AND score IS NOT NULL AND passed;
17+
""",
18+
"""
19+
DROP INDEX IF EXISTS leaderboard.idx_runs_valid_scores;
20+
"""
21+
),
22+
# Secondary: index on submission.leaderboard_id
23+
step(
24+
"""
25+
CREATE INDEX IF NOT EXISTS idx_submission_leaderboard_id
26+
ON leaderboard.submission (leaderboard_id);
27+
""",
28+
"""
29+
DROP INDEX IF EXISTS leaderboard.idx_submission_leaderboard_id;
30+
"""
31+
),
32+
# Secondary: index on submission.user_id
33+
step(
34+
"""
35+
CREATE INDEX IF NOT EXISTS idx_submission_user_id
36+
ON leaderboard.submission (user_id);
37+
""",
38+
"""
39+
DROP INDEX IF EXISTS leaderboard.idx_submission_user_id;
40+
"""
41+
),
42+
]

0 commit comments

Comments
 (0)