Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(game): add player_sessions indices #1958

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

luchaos
Copy link
Member

@luchaos luchaos commented Oct 30, 2023

500ms+ to 44ms for this query:

-- EXPLAIN
SELECT
    `user_id`,
    `User`,
    `rich_presence`,
    MAX(rich_presence_updated_at) AS rich_presence_updated_at
FROM
    `player_sessions`
    INNER JOIN `UserAccounts` ON `UserAccounts`.`ID` = `user_id`
WHERE
    `game_id` = 228
    -- AND `UserAccounts`.`Permissions` >= 0
    -- AND `rich_presence` IS NOT NULL 
GROUP BY
    `user_id`
ORDER BY
    `rich_presence_updated_at` DESC;

Prepares for user-centric queries, too:

-- EXPLAIN
SELECT
    `user_id`,
    `User`,
    `rich_presence`,
    `rich_presence_updated_at`
FROM
    `player_sessions`
    INNER JOIN `UserAccounts` ON `UserAccounts`.`ID` = `user_id`
WHERE
    `user_id` = 472770
    AND `game_id` = 228
ORDER BY
    `rich_presence_updated_at` DESC;

Copy link
Member

@Jamiras Jamiras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before (228): 47ms, 43ms, 41ms, 40ms, 46ms (average: 43ms)
After (228): 10ms, 10ms, 12ms, 10ms, 10ms (average: 10ms)

4x improvement

Before (1446): 25ms, 19ms, 20ms, 18ms, 18ms (average: 20ms)
After (1446): 10ms, 10ms, 8ms, 9ms, 7ms (average: 8ms)

2.5x improvement

@luchaos luchaos merged commit 5b3b36c into RetroAchievements:master Oct 30, 2023
5 checks passed
@luchaos luchaos deleted the player-session-index branch October 30, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants