如何在postgresql上删除或更改cakephp分页计数查询?

编程入门 行业动态 更新时间:2024-10-27 03:29:49
本文介绍了如何在postgresql上删除或更改cakephp分页计数查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将cakephp与postgresql一起使用.我的一些表非常大.使用cakephp的分页时,它在大表上运行COUNT(),然后查询实际结果.计数查询需要2.5分钟,而返回数据的实际查询则需要95ms.

I am using cakephp with postgresql. Some of my tables are very large.When using cakephp's pagination, it runs COUNT() on the large table and then it queries for the actual result. The count query takes 2.5 minutes, while the actual query that returns the data takes 95ms.

是否可以消除对计数的需要,或者用速度更快的计数代替它? 我不需要返回确切的行数,就像Google搜索返回结果1-10(约76.5万)的方式一样.

Is it possible to remove the need for the count, or replace it with something that may go faster? I don't need an exact number of rows returned, much like the way a Google search returns results 1-10 of about 765,000.

或者,有没有一种方法可以完全禁用计数?知道不需要多少页通常会有很多结果.我需要的是一个下一步"按钮,该按钮会像cakephp分页一样增加SQL OFFSET,并且如果在下一页上没有返回行,那就很好了.

Alternately, is there a way I can disable count altogether? There will often be so many results knowing how many pages is not necessary. All I need is a "Next" button that increases the SQL OFFSET like the cakephp pagination already has, and if no rows are returned on the next page then that is fine.

推荐答案

我找到了绕过cakephp中分页计数查询的方法. 在要分页的模型中,您可以覆盖运行计数查询的函数,该函数为paginateCount($conditions = null, $recursive = 0, $extra = array())

I found the way to bypass the pagination count query in cakephp. In the model that you want to paginate you can override the function that runs the count query, the function is paginateCount($conditions = null, $recursive = 0, $extra = array())

我使用以下代码解决了我的问题:

I used the following code to fix my issue:

function paginateCount($conditions = null, $recursive = 0, $extra = array()) { return 0; }

然后,我在视图中编辑了分页,以始终显示下一个按钮.转到没有结果的页面只会显示任何内容.

Then I edited the pagination in the view to always display the next button. Going to a page with no results will just display nothing.

更多推荐

如何在postgresql上删除或更改cakephp分页计数查询?

本文发布于:2023-10-15 12:10:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1494297.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分页   如何在   postgresql   cakephp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!