Skip to content

Commit 5f14aef

Browse files
committed
fix: update SQL queries to use QUALIFY instead of LIMIT for row selection
1 parent 2c6d675 commit 5f14aef

File tree

6 files changed

+6
-12
lines changed

6 files changed

+6
-12
lines changed

glicko-mmr/src/types.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ impl Glicko2HistoryEntry {
2323
r"
2424
SELECT ?fields FROM glicko
2525
WHERE match_id < ?
26-
ORDER BY match_id DESC
27-
LIMIT 1 BY account_id
26+
QUALIFY ROW_NUMBER() OVER (PARTITION BY account_id ORDER BY match_id DESC) = 1
2827
",
2928
)
3029
.bind(match_id)

mmr-calc/hero_mmr_calc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ def get_all_player_mmrs(client, at_match_id: int) -> dict[tuple[int, int], float
182182
SELECT account_id, hero_id, player_score
183183
FROM hero_mmr_history FINAL
184184
WHERE match_id <= {at_match_id}
185-
ORDER BY account_id, match_id DESC
186-
LIMIT 1 BY account_id;
185+
QUALIFY ROW_NUMBER() OVER (PARTITION BY account_id, hero_id ORDER BY match_id DESC) = 1;
187186
"""
188187
result = client.execute(query)
189188
return {(row[0], row[1]): row[2] for row in result}

mmr-calc/hero_mmr_calc_optim.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ def get_all_player_mmrs(client, at_match_id: int) -> dict[tuple[int, int], float
182182
SELECT account_id, hero_id, player_score
183183
FROM hero_mmr_history2 FINAL
184184
WHERE match_id <= {at_match_id}
185-
ORDER BY account_id, match_id DESC
186-
LIMIT 1 BY account_id;
185+
QUALIFY ROW_NUMBER() OVER (PARTITION BY account_id, hero_id ORDER BY match_id DESC) = 1;
187186
"""
188187
result = client.execute(query)
189188
return {(row[0], row[1]): row[2] for row in result}

mmr-calc/mmr_calc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ def get_all_player_mmrs(client, at_match_id: int) -> dict[int, float]:
182182
SELECT account_id, player_score
183183
FROM mmr_history FINAL
184184
WHERE match_id <= {at_match_id}
185-
ORDER BY account_id, match_id DESC
186-
LIMIT 1 BY account_id;
185+
QUALIFY ROW_NUMBER() OVER (PARTITION BY account_id ORDER BY match_id DESC) = 1;
187186
"""
188187
result = client.execute(query)
189188
return {row[0]: row[1] for row in result}

mmr-calc/mmr_calc_optim.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ def get_all_player_mmrs(client, at_match_id: int) -> dict[int, float]:
182182
SELECT account_id, player_score
183183
FROM mmr_history2 FINAL
184184
WHERE match_id <= {at_match_id}
185-
ORDER BY account_id, match_id DESC
186-
LIMIT 1 BY account_id;
185+
QUALIFY ROW_NUMBER() OVER (PARTITION BY account_id ORDER BY match_id DESC) = 1;
187186
"""
188187
result = client.execute(query)
189188
return {row[0]: row[1] for row in result}

rank-fetcher/player_rank_fetcher.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def get_accounts(client: Client, empty_cards: set) -> list[int]:
3838
query = """
3939
WITH last_cards AS (SELECT *
4040
FROM player_card
41-
ORDER BY account_id, created_at DESC
42-
LIMIT 1 BY account_id)
41+
QUALIFY ROW_NUMBER() OVER (PARTITION BY account_id ORDER BY created_at DESC) = 1)
4342
SELECT account_id
4443
FROM last_cards
4544
ORDER BY created_at

0 commit comments

Comments
 (0)