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

feat: add index to icons table #16

Merged
merged 1 commit into from
Nov 25, 2023
Merged

feat: add index to icons table #16

merged 1 commit into from
Nov 25, 2023

Conversation

taiwork
Copy link
Owner

@taiwork taiwork commented Nov 25, 2023

こちらのissue
#14

Count: 11156  Time=0.01s (120s)  Lock=0.00s (0s)  Rows=0.7 (8153), isucon[isucon]@localhost
  SELECT image FROM icons WHERE user_id = 'S'

before

mysql> explain SELECT image FROM icons WHERE user_id = 'S';
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra       |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | icons | NULL       | ALL  | NULL          | NULL | NULL    | NULL |    1 |   100.00 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 2 warnings (0.00 sec)

実行

ALTER TABLE `icons` ADD INDEX `idx_user_id` (`user_id`);

after

mysql> explain SELECT image FROM icons WHERE user_id = 'S';
+----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-----------------------+
| id | select_type | table | partitions | type | possible_keys | key         | key_len | ref   | rows | filtered | Extra                 |
+----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-----------------------+
|  1 | SIMPLE      | icons | NULL       | ref  | idx_user_id   | idx_user_id | 8       | const |    1 |   100.00 | Using index condition |
+----+-------------+-------+------------+------+---------------+-------------+---------+-------+------+----------+-----------------------+
1 row in set, 2 warnings (0.00 sec)

@yoshiyoshiharu yoshiyoshiharu merged commit 6f4676d into master Nov 25, 2023
@taiwork taiwork mentioned this pull request Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants