Zend_Paginator - 增加查询
我开始使用 Zend_Paginator, 它一切正常,但我注意到还有一个查询会减慢加载时间。 附加查询:
SELECT COUNT(1) AS `zend_paginator_row_count` FROM `content`
正常查询:
SELECT `content`.`id`, `content`.`name` FROM `content` LIMIT 2
PHP:
$adapter = new Zend_Paginator_Adapter_DbSelect($table->select()->from($table, array('id', 'name')));
$paginator = new Zend_Paginator($adapter);
我可以将两个查询合并为一个(以获得更好的性能)吗?
I started using Zend_Paginator,
it works everything fine but I noticed that there is one more query which slows the load time down.
The additional query:
SELECT COUNT(1) AS `zend_paginator_row_count` FROM `content`
The normal query:
SELECT `content`.`id`, `content`.`name` FROM `content` LIMIT 2
PHP:
$adapter = new Zend_Paginator_Adapter_DbSelect($table->select()->from($table, array('id', 'name')));
$paginator = new Zend_Paginator($adapter);
Could I merge the two querys into one (for better performance)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保所选表的一个或多个基于 int 的列有索引。因此计数查询不会对性能产生太大影响。您可以使用 setRowCount() 来提供计数(如果有的话)。
来自 http://framework.zend.com/manual/en/zend .paginator.usage.html:
Make sure you have an index on one or more int-based columns of the selected table. So the count query will not have much of a performance inpact. You can use
setRowCount()
to provide the count (if you have it).From http://framework.zend.com/manual/en/zend.paginator.usage.html :
合并两者实际上不会有太大的性能提升(如果有的话)。实际的选择内容中有 limit 语句(因为您试图获取数据库中整个表的子集),其中计数需要对数据库中的所有行进行计数。这样做的原因是为了防止仅仅为了获取计数而选择非常大的数据集。
Merging the two wouldn't really have much of a performance increase if any. The actual select content has the limit statement in it (as you are trying to get a subset of the entire table in the database) where the count needs to count all rows in the database. The reason it is done like this is to prevent having to select a very large set of data simply to get the count.