E.3. Zend_Db Performance
2010-01-22 12:00:06 来源： 评论：0 点击：
Zend_Db is a database abstraction layer, and is intended to
provide a common API for SQL operations.
Zend_Db_Table is a
Table Data Gateway, intended to abstract common table-level database
operations. Due to their abstract nature and the "magic" they do under
the hood to perform their operations, they can sometimes introduce
E.3.1. How can I reduce overhead introduced by Zend_Db_Table for retrieving table metadata
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.
E.3.1.1. Use the metadata cache
Zend_Db_Table can optionally utilize
Zend_Cache to cache table metadata. This is
typically faster to access and less expensive than fetching the
metadata from the database itself.
documentation includes information on metadata caching.
E.3.1.2. Hardcode your metadata in the table definition
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.
E.3.2. SQL generated with Zend_Db_Select s not hitting my indexes; how can I make it better
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.
E.3.2.1. Write your own tuned SQL
The only real answer is to write your own SQL;
Zend_Db does not require the usage of
Zend_Db_Select, so providing your own, tuned
SQL select statements is a perfectly legitimate approach,
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
If the SQL requires variable arguments, provide placeholders in
the SQL, and utilize a combination of
inject the values into the SQL:
// $adapter is the DB adapter. In Zend_Db_Table, retrieve
// it using $this->getAdapter().
$sql = vsprintf(
array_walk($values, array($adapter, 'quoteInto'))
- ·phpcms高级应用与部署 —— 推荐位高级应用(9)
- ·phpcms高级应用与部署 —— 万能字段应用(8)
- ·推荐：PHPCMS v9 安全防范教程！(4)
- ·PHPCMS V9.5.5下载(2)
- ·phpcms 用户自定义函数库 extention....(2)
- ·phpcms api.php 详解(1)
- ·10天学会CSS：第一天 XHTML CSS基础知识(1)
- ·phpcms 采集无法采集的错误分析处理(1)