副問い合わせに続いて、今度はINNER JOINのパフォーマンス比較です。
測定環境についてはこちらを参照して下さい。
・データ件数は100万件
・こちらの構造のテーブルをInnoDBとMyISAMで作成して処理速度を比較
・entryとentry2は記事を格納するテーブルで100万件登録されています。
・entry_commentとentry_comment2はコメントを格納するテーブルで、こちらも100万件登録されています。
・PRIMARY KEYであるidには1~1000000の値がセットされています。
・1記事に対して、1コメントが存在しています。・以下の構造のテーブルをInnoDBとMyISAMで作成して処理速度を比較
以下SQL中の「テーブル名 entryとentry_comment」にはMyISAMなら entry2とentry_comment2 がセットされます。
InnerJoinのパフォーマンス比較用のSQL
-
SELECT e.id, e.STATUS,
-
e.category_id,
-
e.user_type,
-
e.name, e.favorites,
-
e.comments, e.trackbacks,
-
e.favorite_permission,
-
e.comment_permission,
-
e.comment_captcha_permission,
-
e.trackback_permission,
-
e.edited,
-
e.image,
-
e.caption,
-
e.user_name,
-
e.created,
-
e.modified,
-
e.removed,
-
e.title,
-
e.body
-
FROM entry e, entry_comment c
-
WHERE c.user_name = %s
-
AND c.removed IS NULL
-
AND c.entry_id = e.id
-
AND ( e.STATUS = 1 OR e.STATUS = 2)
-
AND e.removed IS NULL
-
ORDER BY c.created DESC
※%sはランダムに変化します。
InnoDBの実行計画(explainの結果)
-
*************************** 1. row ***************************
-
id: 1
-
select_type: SIMPLE
-
TABLE: c
-
type: ref
-
possible_keys: entry_comment_idx1,entry_comment_idx2,entry_comment_idx3,entry_comment_idx4
-
KEY: entry_comment_idx2
-
key_len: 204
-
ref: const,const
-
rows: 1
-
Extra: USING WHERE; USING filesort
-
*************************** 2. row ***************************
-
id: 1
-
select_type: SIMPLE
-
TABLE: e
-
type: eq_ref
-
possible_keys: PRIMARY
-
KEY: PRIMARY
-
key_len: 4
-
ref: testsuite.c.entry_id
-
rows: 1
-
Extra: USING WHERE
MyISAMの実行計画(explainの結果)
-
*************************** 1. row ***************************
-
id: 1
-
select_type: SIMPLE
-
TABLE: c
-
type: ref
-
possible_keys: entry_comment_idx1,entry_comment_idx2,entry_comment_idx3,entry_comment_idx4
-
KEY: entry_comment_idx2
-
key_len: 204
-
ref: const,const
-
rows: 1
-
Extra: USING WHERE; USING filesort
-
*************************** 2. row ***************************
-
id: 1
-
select_type: SIMPLE
-
TABLE: e
-
type: eq_ref
-
possible_keys: PRIMARY
-
KEY: PRIMARY
-
key_len: 4
-
ref: testsuite.c.entry_id
-
rows: 1
-
Extra: USING WHERE
実行計画は同じですね。
計測結果
| スレッド数 | MyISAM | InnoDB |
4同時スレッドのピーク時性能で15%程度、InnoDBのほうが高速です。
同時スレッド数に対するスケーラビリィティの傾向が他のものと異なっています。
次回はLeftJoinを試してみます。





