スローログの中味
# Time: 2017-10-02T12:51:35.321319+09:00
#User@Host: root[root] @ localhost [] Id: 78
# Query_time: 0.000497 Lock_time: 0.000176 Rows_sent: 8 Rows_ex
amined: 247
SET timestamp=1506916295;
SELECT code FROM country WHERE continent = 'Asia' AND region = 'E
astern Asia' ORDER BY population;
10/77
スローログの中味
# Time: 2017-10-02T12:51:35.321319+09:00
#User@Host: root[root] @ localhost [] Id: 78
# Query_time: 0.000497 Lock_time: 0.000176 Rows_sent: 8 Rows_ex
amined: 247
SET timestamp=1506916295;
SELECT code FROM country WHERE continent = 'Asia' AND region = 'E
astern Asia' ORDER BY population;
13/77
Rows_examined / Rows_sent31くらい
# Time: 2017-10-02T12:51:35.321319+09:00
# User@Host: root[root] @ localhost [] Id: 78
# Query_time: 0.000497 Lock_time: 0.000176 Rows_sent: 8 Rows_ex
amined: 247
SET timestamp=1506916295;
SELECT code FROM country WHERE continent = 'Asia' AND region = 'E
astern Asia' ORDER BY population;
17/77
MySQLの(インデックスの)得意な操作
特定のキーの値を狙い撃ち( = 演算⼦とAND 演算⼦)
概観図でいうところの「右に進む」操作-
IN 演算⼦なんかも効くっちゃ効くけど、 ORDER BY まで波及しないケ
ースあり
-
リーフノードが並んでいる順番での ORDER BY
概観図でいうところの「下に進む」操作-
EXPLAIN で Extra: Using filesort になっているケースの⾼速化-
JOIN はこれを狙うのに慣れがいるので敬遠されがち-
58/77
60.
簡単な憶え⽅
インデックスは WHERE 句のカラムを列挙してからORDER BY
句のカラムを列挙する
= と AND しか使ってない場合はこれでいける
SELECT ..
FROM country
WHERE continent = 'Asia' AND
region = 'Eastern Asia'
ORDER BY population;
↓
KEY(continent, region, population)
59/77
61.
簡単な憶え⽅(︖)
こう︖
SELECT ..
FROM countryJOIN
countrylanguage ON country.code= countrylanguage.countrycode
WHERE country.continent = 'Asia'
ORDER BY countrylanguage.percentage LIMIT 5;
↓
country: KEY(continent)
countrylanguage: KEY(countrycode, percentage)
60/77