performance-database.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <!-- EN-Revision: 15099 -->
  4. <sect1 id="performance.database">
  5. <title>Zend_Dbパフォーマンス</title>
  6. <para>
  7. <classname>Zend_Db</classname>はデータベースを抽象化するレイヤーで、SQL操作のための
  8. 共通APIを提供する意図があります。
  9. <classname>Zend_Db_Table</classname>はテーブルデータのゲートウェィで、抽象的な
  10. 共通のテーブルレベルでのデータベース操作を提供する意図があります。
  11. Due to their abstract nature and the "magic" they do under
  12. the hood to perform their operations, they can sometimes introduce
  13. performance overhead.
  14. </para>
  15. <sect2 id="performance.database.tableMetadata">
  16. <title>テーブルのメタデータを取得する際にZend_Db_Tableによってもたらされる
  17. オーバーヘッドをどのようにしたら減らせますか?</title>
  18. <para>
  19. In order to keep usage as simple as possible, and also to support
  20. constantly changing schemas during development,
  21. <classname>Zend_Db_Table</classname> does some magic under the hood: on
  22. first use, it fetches the table schema and stores it within object
  23. members. This operation is typically expensive, regardless of the
  24. database -- which can contribute to bottlenecks in production.
  25. </para>
  26. <para>
  27. Fortunately, there are techniques for improving the situation.
  28. </para>
  29. <sect3 id="performance.database.tableMetadata.cache">
  30. <title>メタデータキャッシュの利用</title>
  31. <para>
  32. <classname>Zend_Db_Table</classname>ではテーブルのメタデータをキャッシュする
  33. ために<classname>Zend_Cache</classname>を任意で利用できます。
  34. This is
  35. typically faster to access and less expensive than fetching the
  36. metadata from the database itself.
  37. </para>
  38. <para>
  39. <link linkend="zend.db.table.metadata.caching"><classname>Zend_Db_Table</classname>
  40. のドキュメントにメタデータをキャッシュすることについての情報があります。</link>
  41. </para>
  42. </sect3>
  43. <sect3 id="performance.database.tableMetadata.hardcoding">
  44. <title>テーブル定義でメタデータをハードコーディングする</title>
  45. <para>
  46. As of 1.7.0, <classname>Zend_Db_Table</classname> also provides <link
  47. linkend="zend.db.table.metadata.caching.hardcoding">support
  48. for hardcoding metadata in the table definition</link>. This is
  49. an advanced use case, and should only be used when you know the
  50. table schema is unlikely to change, or that you're able to keep
  51. the definitions up-to-date.
  52. </para>
  53. </sect3>
  54. </sect2>
  55. <sect2 id="performance.database.select">
  56. <title>Zend_Db_Selectで生成されたSQLがインデックスにヒットしません。
  57. どのようにしたらより良く出来ますか?</title>
  58. <para>
  59. <classname>Zend_Db_Select</classname> is relatively good at its job. However,
  60. if you are performing complex queries requiring joins or
  61. sub-selects, it can often be fairly naive.
  62. </para>
  63. <sect3 id="performance.database.select.writeyourown">
  64. <title>自分で最適化したSQLを書く</title>
  65. <para>
  66. 現実的な唯一の答えは自分でSQLを書くことです;
  67. 自分で用意できるなら、<classname>Zend_Db</classname>で必ず
  68. <classname>Zend_Db_Select</classname>を使わずに、調整されたselect文の
  69. SQLが完璧で筋の通った道筋です。
  70. </para>
  71. <para>
  72. Run <code>EXPLAIN</code> on your queries, and test a variety of
  73. approaches until you can reliably hit your indices in the most
  74. performant way -- and then hardcode the SQL as a class property
  75. or constant.
  76. </para>
  77. <para>
  78. If the SQL requires variable arguments, provide placeholders in
  79. the SQL, and utilize a combination of <code>vsprintf</code> and
  80. <code>array_walk</code> to inject the values into the SQL:
  81. </para>
  82. <programlisting role="php"><![CDATA[
  83. // $adapter is the DB adapter. In Zend_Db_Table, retrieve
  84. // it using $this->getAdapter().
  85. $sql = vsprintf(
  86. self::SELECT_FOO,
  87. array_walk($values, array($adapter, 'quoteInto'))
  88. );
  89. ]]></programlisting>
  90. </sect3>
  91. </sect2>
  92. </sect1>
  93. <!--
  94. vim:se ts=4 sw=4 et:
  95. -->