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

Home page query for new reviews does a full table scan #1275

Open
dfabulich opened this issue Feb 3, 2025 · 0 comments
Open

Home page query for new reviews does a full table scan #1275

dfabulich opened this issue Feb 3, 2025 · 0 comments
Labels
performance Make the site faster slow query Slow database queries

Comments

@dfabulich
Copy link
Collaborator

Edit dbconnect.php and set logging_level = 2 in mysql_query, then refresh the home page logged out.

We're doing this query, which does a full table scan of the reviews table.

MariaDB [ifdb]> explain select
    ->   reviews.id as id, gameid, summary, review, rating, special,
    ->   games.title as title,
    ->   users.id as userid, users.name as username,
    ->   greatest(reviews.createdate,
    ->            ifnull(reviews.embargodate, '0000-00-00')) as d,
    ->   date_format(greatest(reviews.createdate,
    ->               ifnull(reviews.embargodate, '0000-00-00')),
    ->               '%M %e, %Y') as fmtdate,
    ->   (games.coverart is not null) as hasart,
    ->   games.pagevsn,
    ->   (users.picture is not null) as haspic,
    ->   games.flags
    -> from
    ->   reviews
    ->   join games
    ->   join users
    ->   left outer join specialreviewers on specialreviewers.id = special
    -> where
    ->   games.id = reviews.gameid
    ->   and users.id = reviews.userid
    ->   and reviews.review is not null
    ->   and ifnull(now() >= reviews.embargodate, 1)
    ->   and ifnull(specialreviewers.code, '') <> 'external'
    ->   and users.sandbox in (0)
    ->   and 1
    ->
    -> order by d desc, id desc
    -> limit 8;
+------+-------------+------------------+--------+-------------------------+---------+---------+----------------------+-------+-----------------------------+
| id   | select_type | table            | type   | possible_keys           | key     | key_len | ref                  | rows  | Extra                       |
+------+-------------+------------------+--------+-------------------------+---------+---------+----------------------+-------+-----------------------------+
|    1 | SIMPLE      | reviews          | ALL    | userid,gameid,user_game | NULL    | NULL    | NULL                 | 73088 | Using where; Using filesort |
|    1 | SIMPLE      | games            | eq_ref | PRIMARY                 | PRIMARY | 130     | ifdb.reviews.gameid  | 1     |                             |
|    1 | SIMPLE      | users            | eq_ref | PRIMARY                 | PRIMARY | 130     | ifdb.reviews.userid  | 1     | Using where                 |
|    1 | SIMPLE      | specialreviewers | eq_ref | PRIMARY                 | PRIMARY | 4       | ifdb.reviews.special | 1     | Using where                 |
+------+-------------+------------------+--------+-------------------------+---------+---------+----------------------+-------+-----------------------------+
@dfabulich dfabulich added performance Make the site faster slow query Slow database queries labels Feb 3, 2025
dfabulich added a commit to dfabulich/ifdb that referenced this issue Feb 3, 2025
dfabulich added a commit that referenced this issue Feb 3, 2025
dfabulich added a commit to dfabulich/ifdb that referenced this issue Feb 3, 2025
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