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

IFDB Recommends is doing a full scan of the games table (when logged in) #1260

Open
dfabulich opened this issue Jan 18, 2025 · 1 comment
Open
Labels
performance Make the site faster slow query Slow database queries

Comments

@dfabulich
Copy link
Collaborator

MariaDB [ifdb]> explain select sql_calc_found_rows
    ->               distinct games.id as id,
    ->                        games.title as title,
    ->                        games.author as author,
    ->                        games.desc as description,
    ->                        games.tags as tags,
    ->                        games.moddate as moddate,
    ->                        games.system as devsys,
    ->                        if (time(games.published) = '00:00:00',
    ->                            date_format(games.published, '%Y'),
    ->                            date_format(games.published, '%M %e, %Y'))
    ->                          as pubfmt,
    ->                        if (time(games.published) = '00:00:00',
    ->                            date_format(games.published, '%Y'),
    ->                            date_format(games.published, '%Y-%m-%d'))
    ->                          as published,
    ->                        date_format(games.published, '%Y') as pubyear,
    ->                        (games.coverart is not null) as hasart,
    ->                        avgRating as avgrating,
    ->                        numRatingsInAvg as ratingcnt,
    ->                        stdDevRating as ratingdev,
    ->                        numRatingsTotal,
    ->                        numMemberReviews,
    ->                        starsort,
    ->                        games.sort_title as sort_title,
    ->                        games.sort_author as sort_author,
    ->                        ifnull(games.published, '9999-12-31') as sort_pub,
    ->                        games.pagevsn,
    ->                        games.flags
    ->
    ->             from
    ->               games
    ->                           left join gameRatingsSandbox0_mv on games.id = gameid left join playedgames as pg on games.id = pg.gameid and pg.userid = 'oyrrw74upu8n2dds' left join wishlists as wl on games.id = wl.gameid and wl.userid = 'oyrrw74upu8n2dds' left join unwishlists as ul on games.id = ul.gameid and ul.userid = 'oyrrw74upu8n2dds' left join reviews as reviewed on games.id = reviewed.gameid and reviewed.review is not null and reviewed.userid = 'oyrrw74upu8n2dds' left join reviews as rated on games.id = rated.gameid and rated.rating is not null and rated.userid = 'oyrrw74upu8n2dds'
    ->
    ->             where
    ->               pg.gameid is null AND wl.gameid is null AND ul.gameid is null AND reviewed.gameid is null AND rated.gameid is null
    ->
    ->
    ->
    ->             order by
    ->               starsort desc
    ->
    ->             limit 0, 12;
+------+-------------+------------------------+------------+-------------------------+---------------+---------+---------------------+--------+-------------------------------------------------------+
| id   | select_type | table                  | type       | possible_keys           | key           | key_len | ref                 | rows   | Extra                                                 |
+------+-------------+------------------------+------------+-------------------------+---------------+---------+---------------------+--------+-------------------------------------------------------+
|    1 | SIMPLE      | games                  | ALL        | NULL                    | NULL          | NULL    | NULL                | 14010  | Using temporary; Using filesort                       |
|    1 | SIMPLE      | gameRatingsSandbox0_mv | eq_ref     | PRIMARY                 | PRIMARY       | 130     | ifdb.games.id       | 1      |                                                       |
|    1 | SIMPLE      | pg                     | ref|filter | userid,gameid           | gameid|userid | 130|130 | ifdb.games.id       | 9 (0%) | Using where; Not exists; Distinct; Using rowid filter |
|    1 | SIMPLE      | wl                     | ref|filter | gameid,userid           | gameid|userid | 130|130 | ifdb.games.id       | 9 (0%) | Using where; Not exists; Distinct; Using rowid filter |
|    1 | SIMPLE      | ul                     | ref        | gameid,userid           | gameid        | 130     | ifdb.games.id       | 1      | Using where; Not exists; Distinct                     |
|    1 | SIMPLE      | reviewed               | ref        | userid,gameid,user_game | user_game     | 260     | const,ifdb.games.id | 1      | Using where; Not exists; Distinct                     |
|    1 | SIMPLE      | rated                  | ref        | userid,gameid,user_game | user_game     | 260     | const,ifdb.games.id | 1      | Using where; Not exists; Distinct                     |
+------+-------------+------------------------+------------+-------------------------+---------------+---------+---------------------+--------+-------------------------------------------------------+
@dfabulich dfabulich added performance Make the site faster slow query Slow database queries labels Jan 18, 2025
@dfabulich
Copy link
Collaborator Author

This is happening for two reasons: sql_calc_found_rows, and the joins. When I get rid of sql_calc_found_rows and convert the joins to gameid not in subselects, it stops scanning all rows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Make the site faster slow query Slow database queries
Projects
None yet
Development

No branches or pull requests

1 participant