PHPのPDO::mysql。prepared statementはquery cacheを使っている!

PHP

目的

  • PHPのPDO::mysqlはquery cacheを使っているかを知る。
  • 使っていたらqueryメソッドとの速度差はどのくらいかを知る。

実験環境

VM上のLinuxで実験

  • CPU: Core2 Duo 2GHz(Host OS)
  • OS: Windows XP(Host) CentOS release 4.4 (VM)
  • PHP 5.2.3 (CLI)
  • MySQL 5.0.41
  • 郵便番号テーブル 121973件
  • 検索するカラム: INT(10) unsigned

実験1

prepared statementがquery cacheを使っているかを求める。

  • 条件
    • 10000 times

marker time index ex time

prepared statement 1186039399.87295300 4.21059203148

  • 条件
  • 100 times
  • mysql

set global query_cache_size = 0

marker time index ex time

prepared statement 1186039289.14549200 34.6095161438

  • 結果
    • Query cacheをONにしてprepared statementを使った場合は、OFFにした場合に比べて約823倍速い。

実験2

  • 条件
    • 10000 times

marker time index ex time perct

exec 1186039395.66236100 4.05659389496 49.07%

prepared statement 1186039399.87295300 4.21059203148 50.93%

  • 結果
  • execの方が4%早い!

結論

PHPのPDO::mysqlはquery cacheを利用している。

コメント