Zend_Paginator - 增加查询

发布于 2024-08-27 19:37:12 字数 474 浏览 12 评论 0原文

我开始使用 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 技术交流群。

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

发布评论

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

评论(2

无可置疑 2024-09-03 19:37:12

确保所选表的一个或多个基于 int 的列有索引。因此计数查询不会对性能产生太大影响。您可以使用 setRowCount() 来提供计数(如果有的话)。

来自 http://framework.zend.com/manual/en/zend .paginator.usage.html

注意:不要选择每个
给定查询的匹配行,
DbSelect 和 DbTableSelect 适配器
只检索最小数量的
显示所需的数据
当前页面。正因为如此,一个
第二个查询是动态生成的
来确定总数
匹配的行。然而,有可能
直接提供计数或计数
问问你自己。请参阅 setRowCount()
DbSelect 适配器中的方法
更多信息。

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 :

Note: Instead of selecting every
matching row of a given query, the
DbSelect and DbTableSelect adapters
retrieve only the smallest amount of
data necessary for displaying the
current page. Because of this, a
second query is dynamically generated
to determine the total number of
matching rows. However, it is possible
to directly supply a count or count
query yourself. See the setRowCount()
method in the DbSelect adapter for
more information.

暗地喜欢 2024-09-03 19:37:12

合并两者实际上不会有太大的性能提升(如果有的话)。实际的选择内容中有 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.

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