Zend_DbパフォーマンスZend_Dbはデータベースを抽象化するレイヤーで、SQL操作のための
共通APIを提供する意図があります。
Zend_Db_Tableはテーブルデータのゲートウェィで、抽象的な
共通のテーブルレベルでのデータベース操作を提供する意図があります。
Due to their abstract nature and the "magic" they do under
the hood to perform their operations, they can sometimes introduce
performance overhead.
テーブルのメタデータを取得する際にZend_Db_Tableによってもたらされる
オーバーヘッドをどのようにしたら減らせますか?
In order to keep usage as simple as possible, and also to support
constantly changing schemas during development,
Zend_Db_Table does some magic under the hood: on
first use, it fetches the table schema and stores it within object
members. This operation is typically expensive, regardless of the
database -- which can contribute to bottlenecks in production.
Fortunately, there are techniques for improving the situation.
メタデータキャッシュの利用Zend_Db_Tableではテーブルのメタデータをキャッシュする
ためにZend_Cacheを任意で利用できます。
This is
typically faster to access and less expensive than fetching the
metadata from the database itself.
Zend_Db_Table
のドキュメントにメタデータをキャッシュすることについての情報があります。
テーブル定義でメタデータをハードコーディングする
As of 1.7.0, Zend_Db_Table also provides support
for hardcoding metadata in the table definition. This is
an advanced use case, and should only be used when you know the
table schema is unlikely to change, or that you're able to keep
the definitions up-to-date.
Zend_Db_Selectで生成されたSQLがインデックスにヒットしません。
どのようにしたらより良く出来ますか?Zend_Db_Select is relatively good at its job. However,
if you are performing complex queries requiring joins or
sub-selects, it can often be fairly naive.
自分で最適化したSQLを書く
現実的な唯一の答えは自分でSQLを書くことです;
自分で用意できるなら、Zend_Dbで必ず
Zend_Db_Selectを使わずに、調整されたselect文の
SQLが完璧で筋の通った道筋です。
Run EXPLAIN on your queries, and test a variety of
approaches until you can reliably hit your indices in the most
performant way -- and then hardcode the SQL as a class property
or constant.
If the SQL requires variable arguments, provide placeholders in
the SQL, and utilize a combination of vsprintf and
array_walk to inject the values into the SQL:
getAdapter().
$sql = vsprintf(
self::SELECT_FOO,
array_walk($values, array($adapter, 'quoteInto'))
);
]]>