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.
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.
EDIT: 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.
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:
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.