LoginSignup
0
3

More than 5 years have passed since last update.

MySQLクエリチューニング 〜SHOW PROFILEを試す〜

Posted at

再現性のあるスロークエリには SHOW PROFILE を試してみよう

MySQLサーバ組み込みプロファイラから情報を取り出すためのステートメント
使えるかどうかはビルドオプション( cmake - DENABLED_PROFILING=ON )を有効にすれば使用可能
EXPLAIN 上問題ないが、クエリの遅さに再現性がある場合に有効な場合がある
準備
以下のどちらかを実行すればプロファイラーが有効になる

SET SESSION profiling = 1

# もしくはこっち
SET @@profiling = 1

MySQL5.6から非推奨になっており、今後削除される可能せいのある機能なため、以下のようにwarningが出る

show warnings;

出力結果

Level Code Message
Warning 1287 '@@profiling' is deprecated and will be removed in a future release.
利用方法
クエリを叩いた後に以下のクエリを流すだけ

SHOW PROFILE;

# 出力結果
Status    Duration
starting    0.000076
checking permissions    0.000010
Opening tables    0.000026
init    0.000030
System lock    0.000014
optimizing    0.000010
statistics    0.000021
preparing    0.000032
executing    0.000003
Sending data    0.000299
end    0.000012
query end    0.000038
closing tables    0.000013
freeing items    0.000123
cleaning up    0.000037

これはそれぞれどの実行で時間がか方かを示している。

読み方

上から順番に実行されており、どこにどれだけ時間がかかったかがわかる。 sending data ストレージエンジンからデータをフェッチする時のステータスなので、ここに一番時間がかかっていることがわかる

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3