More Related Content
Similar to MySQL 入門的なはなし (13)
More from Yuya Takeyama (14)
MySQL 入門的なはなし
- 1. M yS Q L
入門的なはなし
@yuya_takeyama
- 4. アジェンダ
•何故 MySQL 勉強会なのか
• MySQL のアーキテクチャ
•インデックスを使うと何故速い?
•MySQL の勉強の仕方
間に合いませんでした...
検索ワードに nippondanji を追加すれば情報の質が上がるのでオススメ
- 20. 悪い例
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
1 | SIMPLE | person | ALL | NULL | NULL | NULL | NULL | 1679821 | Using where; Using filesort |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
良い例
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | person | const | PRIMARY | PRIMARY | 34 | const | 1 | |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | person | range | PRIMARY | PRIMARY | 34 | NULL | 1484 | Using where |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
- 21. 悪い例
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
1 | SIMPLE | person | ALL | NULL | NULL | NULL | NULL | 1679821 | Using where; Using filesort |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
良い例
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | person | const | PRIMARY | PRIMARY | 34 | const | 1 | |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | person | range | PRIMARY | PRIMARY | 34 | NULL | 1484 | Using where |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
評価対象の行数
- 22. 悪い例
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
1 | SIMPLE | person | ALL | NULL | NULL | NULL | NULL | 1679821 | Using where; Using filesort |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
良い例
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | person | const | PRIMARY | PRIMARY | 34 | const | 1 | |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | person | range | PRIMARY | PRIMARY | 34 | NULL | 1484 | Using where |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
インデックスは使われているか
- 23. 悪い例
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
1 | SIMPLE | person | ALL | NULL | NULL | NULL | NULL | 1679821 | Using where; Using filesort |
----+-------------+--------+------+---------------+------+---------+------+---------+-----------------------------+
良い例
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | person | const | PRIMARY | PRIMARY | 34 | const | 1 | |
+----+-------------+--------+-------+---------------+---------+---------+-------+------+-------+
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | person | range | PRIMARY | PRIMARY | 34 | NULL | 1484 | Using where |
+----+-------------+--------+-------+---------------+---------+---------+------+------+-------------+
実行時のソートは
発生していないか
- 26. ストレージエンジン
• データの入れ物
• MySQL ではプラッガブル
•InnoDB, MyISAM, Memory,
Spider, Mroonga...
• それぞれ得意・不得意などがある
- 31. 参考動画
http://academicearth.org/lectures/run-times-and-algorithms-recursion
4:30 あたり
※単純化のために二分探索 (Binary Search) を
取り上げていますが, MySQL では B-Tree によ
る探索が使われています (根本的な原理はだいたい
一緒 (のはず (?)))