Note that there are some explanatory texts on larger screens.

plurals
  1. POSlow mysql select
    primarykey
    data
    text
    <p>I have a table with the following structure:</p> <pre><code>CREATE TABLE `game_entries` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `player_id` int(11) unsigned NOT NULL, `game_id` int(11) unsigned NOT NULL, `hero_id` int(11) unsigned NOT NULL, `game_avg_pts` smallint(4) unsigned NOT NULL DEFAULT '0', `game_season` tinyint(2) unsigned NOT NULL, `game_length` smallint(11) unsigned NOT NULL, `game_mode` char(10) NOT NULL, `game_is_tb` tinyint(1) unsigned NOT NULL DEFAULT '0', `game_map` char(10) NOT NULL, `game_date` datetime NOT NULL, `game_playersnum` tinyint(2) NOT NULL, `side` tinyint(2) unsigned NOT NULL, `won` tinyint(1) unsigned NOT NULL DEFAULT '0', `pts` smallint(11) unsigned NOT NULL, `pts_change` smallint(4) NOT NULL, `kills` smallint(4) unsigned NOT NULL DEFAULT '0', `deaths` smallint(4) unsigned NOT NULL DEFAULT '0', `assists` smallint(4) unsigned NOT NULL DEFAULT '0', `creeps` smallint(4) unsigned NOT NULL DEFAULT '0', `towers` tinyint(2) unsigned NOT NULL DEFAULT '0', `deleted_at` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `player_game` (`player_id`,`game_id`), KEY `index_game` (`game_id`), KEY `index_player` (`player_id`), KEY `index_hero` (`hero_id`) ) ENGINE=InnoDB AUTO_INCREMENT=11706564 DEFAULT CHARSET=utf8; </code></pre> <p>The table has more than 11M rows. When I try to select all game_entries for a specific player_id, the query takes too long:</p> <pre><code>mysql&gt; SELECT * FROM `game_entries` WHERE player_id = 4; 227 rows in set (1.68 sec) mysql&gt; SELECT * FROM `game_entries` WHERE player_id = 4 LIMIT 25; 25 rows in set (0.27 sec) mysql&gt; EXPLAIN SELECT * FROM `game_entries` WHERE player_id = 4; +----+-------------+--------------+------+--------------------------+-------------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+--------------+------+--------------------------+-------------+---------+-------+------+-------+ | 1 | SIMPLE | game_entries | ref | player_game,index_player | player_game | 4 | const | 226 | | +----+-------------+--------------+------+--------------------------+-------------+---------+-------+------+-------+ 1 row in set (0.00 sec) </code></pre> <p>Is there any way to improve the speed of this query?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload