Zend Framework 中的大量 DESCRIBE 查询

发布于 2024-08-20 23:46:25 字数 911 浏览 2 评论 0原文

我刚刚在 Zend 中设置了 FirePHP,我注意到有大量的 DESCRIBE 查询。某些页面在同一个表上有 50 个或更多相同的查询。例如

0.00198     connect      NULL
0.00449 DESCRIBE `nodes`    NULL
0.00041 SELECT `nodes`.* FROM `nodes` WHERE (((`nodes`.`id` = 111)))    NULL
0.0037  DESCRIBE `nodes`    NULL
0.00155 SELECT `nodes`.* FROM `nodes` WHERE (((`nodes`.`id` = 111)))    NULL
0.00059 SELECT `nodes`.* FROM `nodes` WHERE (parent_id = '111') ORDER BY `order` ASC, `id` ASC  NULL
0.00366 DESCRIBE `nodes`    NULL
0.0054  DESCRIBE `nodes`    NULL
0.0049  DESCRIBE `nodes`    NULL
0.00519 DESCRIBE `nodes`    NULL
0.00492 DESCRIBE `nodes`    NULL
0.00691 DESCRIBE `nodes`    NULL
0.00741 DESCRIBE `nodes`    NULL
0.0048  DESCRIBE `nodes`    NULL
0.00556 DESCRIBE `nodes`    NULL
0.00516 DESCRIBE `nodes`    NULL
0.00487 DESCRIBE `nodes`    NULL

......而且它还在继续。

所有这些 DESCRIBE 查询都是由框架生成的吗(我正在使用 Zend_DbTable)?它们都是必要的吗?我应该担心它们还是它们不太可能影响性能?

I just set up FirePHP in Zend and I'm noticing a huge number of DESCRIBE queries. Some pages have 50 or more identical queries all on the same table. e.g.

0.00198     connect      NULL
0.00449 DESCRIBE `nodes`    NULL
0.00041 SELECT `nodes`.* FROM `nodes` WHERE (((`nodes`.`id` = 111)))    NULL
0.0037  DESCRIBE `nodes`    NULL
0.00155 SELECT `nodes`.* FROM `nodes` WHERE (((`nodes`.`id` = 111)))    NULL
0.00059 SELECT `nodes`.* FROM `nodes` WHERE (parent_id = '111') ORDER BY `order` ASC, `id` ASC  NULL
0.00366 DESCRIBE `nodes`    NULL
0.0054  DESCRIBE `nodes`    NULL
0.0049  DESCRIBE `nodes`    NULL
0.00519 DESCRIBE `nodes`    NULL
0.00492 DESCRIBE `nodes`    NULL
0.00691 DESCRIBE `nodes`    NULL
0.00741 DESCRIBE `nodes`    NULL
0.0048  DESCRIBE `nodes`    NULL
0.00556 DESCRIBE `nodes`    NULL
0.00516 DESCRIBE `nodes`    NULL
0.00487 DESCRIBE `nodes`    NULL

...and it goes on.

Are all those DESCRIBE queries generated by the framework (I'm using Zend_DbTable)? Are they all necessary? Should I be worried about them or are they not likely to be impacting performance?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

誰ツ都不明白 2024-08-27 23:46:26

我使用单例模式将 Zend_DbTable 实例存储在基本模型类的静态数组中。这将数据库查询减少到每个请求一次,这对我来说已经足够好了,并且还减少了需要实例化的对象的数量。

例如:

protected $_dbTable;
protected $_table; //override the database table name in subclass

private static $_dbTableCache = array();

public function __construct()
{
    $this->_dbTable = $this->getDbTableInstance($this->_table);
}

protected function getDbTableInstance($tableName) {
    if (self::$_dbTableCache[$tableName] === null) {
        self::$_dbTableCache[$tableName] = new Zend_Db_Table($tableName);
    }
    return self::$_dbTableCache[$tableName];
}

I used a singleton pattern to store the Zend_DbTable instances in a static array on my base model class. This reduces the DB queries to one per request which is good enough for me and also reduces the number of objects which need to be instantiated.

For example:

protected $_dbTable;
protected $_table; //override the database table name in subclass

private static $_dbTableCache = array();

public function __construct()
{
    $this->_dbTable = $this->getDbTableInstance($this->_table);
}

protected function getDbTableInstance($tableName) {
    if (self::$_dbTableCache[$tableName] === null) {
        self::$_dbTableCache[$tableName] = new Zend_Db_Table($tableName);
    }
    return self::$_dbTableCache[$tableName];
}
世界和平 2024-08-27 23:46:25

这些查询由 Zend_Db_Table 执行以检测表的模式。您可以要求 Zend_Db_Table 使用 Zend_Cache 缓存结果以防止不断调用,但如果您更改模式,请记住这一点。

您可以使用以下方法来做到这一点:

Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);

Those queries are executed by Zend_Db_Table to detect the schema of the tables. You can ask Zend_Db_Table to cache the results using a Zend_Cache to prevent constant calls, but bare that in mind if you change the schema.

You can do so by using:

Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
心奴独伤 2024-08-27 23:46:25

Zend_Db_Adapter_Abstract::describeTable() 在使用 Zend_Db_Table 时执行这些查询来获取表的元数据。例如,当您没有显式指定主键时,将使用此查询。您可以启用元数据缓存或仅使用 Zend_Db 而不是 Zend_Db_Table

我认为您不应该有这么多描述查询。一旦设置了 Zend_Db_Table 实例,它将在剩余请求的第一次查询后存储元数据。尝试使用 Zend_Debugger 或 Xdebug 找出导致此问题的原因。

请参阅

Zend_Db_Adapter_Abstract::describeTable() does these queries to get the Metadata of your tables when using Zend_Db_Table This is used for instance when you do not specify a primary key explicitly. You can enable the MetaData cache or just use Zend_Db instead of Zend_Db_Table.

I think you should not have this many describe queries though. Once a Zend_Db_Table instance is set up, it will store the metadata after the first query for the remaining request. Try to use Zend_Debugger or Xdebug to find out what's causing this.

See

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文