副問い合わせに続いて、今度は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

SQL:
  1. SELECT e.id, e.STATUS,
  2. e.category_id,
  3. e.user_type,
  4. e.name, e.favorites,
  5. e.comments, e.trackbacks,
  6. e.favorite_permission,
  7. e.comment_permission,
  8. e.comment_captcha_permission,
  9. e.trackback_permission,
  10. e.edited,
  11. e.image,
  12. e.caption,
  13. e.user_name,
  14. e.created,
  15. e.modified,
  16. e.removed,
  17. e.title,
  18. e.body
  19. FROM entry e, entry_comment c
  20. WHERE c.user_name = %s
  21. AND c.removed IS NULL
  22. AND c.entry_id = e.id
  23. AND ( e.STATUS = 1 OR e.STATUS = 2)
  24. AND e.removed IS NULL
  25. ORDER BY c.created DESC

※%sはランダムに変化します。

InnoDBの実行計画(explainの結果)

SQL:
  1. *************************** 1. row ***************************
  2. id: 1
  3. select_type: SIMPLE
  4. TABLE: c
  5. type: ref
  6. possible_keys: entry_comment_idx1,entry_comment_idx2,entry_comment_idx3,entry_comment_idx4
  7. KEY: entry_comment_idx2
  8. key_len: 204
  9. ref: const,const
  10. rows: 1
  11. Extra: USING WHERE; USING filesort
  12. *************************** 2. row ***************************
  13. id: 1
  14. select_type: SIMPLE
  15. TABLE: e
  16. type: eq_ref
  17. possible_keys: PRIMARY
  18. KEY: PRIMARY
  19. key_len: 4
  20. ref: testsuite.c.entry_id
  21. rows: 1
  22. Extra: USING WHERE

MyISAMの実行計画(explainの結果)

SQL:
  1. *************************** 1. row ***************************
  2. id: 1
  3. select_type: SIMPLE
  4. TABLE: c
  5. type: ref
  6. possible_keys: entry_comment_idx1,entry_comment_idx2,entry_comment_idx3,entry_comment_idx4
  7. KEY: entry_comment_idx2
  8. key_len: 204
  9. ref: const,const
  10. rows: 1
  11. Extra: USING WHERE; USING filesort
  12. *************************** 2. row ***************************
  13. id: 1
  14. select_type: SIMPLE
  15. TABLE: e
  16. type: eq_ref
  17. possible_keys: PRIMARY
  18. KEY: PRIMARY
  19. key_len: 4
  20. ref: testsuite.c.entry_id
  21. rows: 1
  22. Extra: USING WHERE

実行計画は同じですね。

計測結果

スレッド数 MyISAM InnoDB

INNER JOIN


4同時スレッドのピーク時性能で15%程度、InnoDBのほうが高速です。
同時スレッド数に対するスケーラビリィティの傾向が他のものと異なっています。

次回はLeftJoinを試してみます。