iftechfoundation / ifdb-suggestion-tracker

Bugs and feature requests for a future IFDB update
10 stars 0 forks source link

Slow Query: gameRatingsSandbox0 has no primary key #401

Closed dfabulich closed 6 months ago

dfabulich commented 9 months ago

Querying gameRatingsSandbox0 requires a full scan.

Slow query log:

# User@Host: ifdb[ifdb] @ localhost [127.0.0.1]
# Thread_id: 8085357  Schema: ifdb  QC_hit: No
# Query_time: 10.694581  Lock_time: 0.000029  Rows_sent: 1  Rows_examined: 223009
# Rows_affected: 0  Bytes_sent: 408
# Tmp_tables: 4  Tmp_disk_tables: 0  Tmp_table_sizes: 6740088
# Full_scan: Yes  Full_join: No  Tmp_table: Yes  Tmp_table_on_disk: No
# Filesort: Yes  Filesort_on_disk: No  Merge_passes: 1  Priority_queue: No
#
# explain: id   select_type table   type    possible_keys   key key_len ref rows    r_rows  filtered    r_filtered  Extra
# explain: 1    PRIMARY <derived4>  ALL NULL    NULL    NULL    NULL    68129   7869.00 100.00  0.01    Using where
# explain: 4    DERIVED <derived5>  ALL NULL    NULL    NULL    NULL    68129   22611.00    100.00  100.00  Using temporary; Using filesort
# explain: 5    DERIVED reviews ALL NULL    NULL    NULL    NULL    68129   68129.00    100.00  93.12   Using where; Using temporary; Using filesort
# explain: 5    DERIVED users   eq_ref  PRIMARY PRIMARY 34  ifdb.reviews.userid 1   1.00    100.00  100.00  Using where
#
SET timestamp=1697055135;
select
           numRatingsInAvg, numRatingsTotal, avgRating, numMemberReviews
         from
           gameRatingsSandbox0
         where
           gameid = 'ebqzkpo6d9s3wbwm';
MariaDB [ifdb]> describe gameRatingsSandbox0;
+------------------+---------------+------+-----+---------+-------+
| Field            | Type          | Null | Key | Default | Extra |
+------------------+---------------+------+-----+---------+-------+
| gameid           | varchar(32)   | NO   |     |         |       |
| rated1           | decimal(42,0) | YES  |     | NULL    |       |
| rated2           | decimal(42,0) | YES  |     | NULL    |       |
| rated3           | decimal(42,0) | YES  |     | NULL    |       |
| rated4           | decimal(42,0) | YES  |     | NULL    |       |
| rated5           | decimal(42,0) | YES  |     | NULL    |       |
| numRatingsInAvg  | decimal(42,0) | YES  |     | NULL    |       |
| numRatingsTotal  | decimal(42,0) | YES  |     | NULL    |       |
| numMemberReviews | decimal(42,0) | YES  |     | NULL    |       |
| avgRating        | decimal(51,4) | YES  |     | NULL    |       |
| stdDevRating     | double        | YES  |     | NULL    |       |
| starsort         | double        | YES  |     | NULL    |       |
+------------------+---------------+------+-----+---------+-------+
12 rows in set (0.002 sec)