Closed taiwork closed 11 months ago
こちらのissue https://github.com/taiwork/isucon13/issues/13
Count: 5937 Time=0.04s (244s) Lock=0.00s (0s) Rows=3.6 (21203), isucon[isucon]@localhost SELECT * FROM livestream_tags WHERE livestream_id = 'S'
mysql> explain SELECT * FROM livestream_tags WHERE livestream_id = 'S'; +----+-------------+-----------------+------------+------+---------------+------+---------+------+-------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-----------------+------------+------+---------------+------+---------+------+-------+----------+-------------+ | 1 | SIMPLE | livestream_tags | NULL | ALL | NULL | NULL | NULL | NULL | 10640 | 10.00 | Using where | +----+-------------+-----------------+------------+------+---------------+------+---------+------+-------+----------+-------------+ 1 row in set, 2 warnings (0.01 sec)
ALTER TABLE `livestream_tags` ADD INDEX `idx_livestream_id` (`livestream_id`);
mysql> show index from livestream_tags; +-----------------+------------+-------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression | +-----------------+------------+-------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+ | livestream_tags | 0 | PRIMARY | 1 | id | A | 10640 | NULL | NULL | | BTREE | | | YES | NULL | | livestream_tags | 1 | idx_livestream_id | 1 | livestream_id | A | 7305 | NULL | NULL | | BTREE | | | YES | NULL | +-----------------+------------+-------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
mysql> explain SELECT * FROM livestream_tags WHERE livestream_id = 'S'; +----+-------------+-----------------+------------+------+-------------------+-------------------+---------+-------+------+----------+-----------------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-----------------+------------+------+-------------------+-------------------+---------+-------+------+----------+-----------------------+ | 1 | SIMPLE | livestream_tags | NULL | ref | idx_livestream_id | idx_livestream_id | 8 | const | 1 | 100.00 | Using index condition | +----+-------------+-----------------+------------+------+-------------------+-------------------+---------+-------+------+----------+-----------------------+ 1 row in set, 2 warnings (0.00 sec)
こちらのissue https://github.com/taiwork/isucon13/issues/13
before
実行
after