1
votes

As you know in cakephp with every find (select) query an automatic count( * ) query is being generated (cakephp use it for pagination) I'm running a query in a table with 2 million records and my query runs in 0.0016 sec. but the count( * ) generated by cakephp takes several seconds Is there a way to prevent cakephp from running this query? Can I disable or false it? My cakephp version is 1.3

Edited (Solved): I've found that when I use manual joins in my query, cakephp find count query will be so expensive. So the solution is to remove all manual joins and then set recursive of find count to -1 in cakephp paginate function

1
You might also want to take a look at the reason why a count(*) takes too long, generally speaking these queries should not be that expensive, is table properly indexed?Guillermo Mansilla
Yes the table is indexed and I've tried to set the count query recursive to -1 in paginate function of cakephp core.MOHA
Can you run the query directly in your database? if there is not much difference in the response time then there is definitely something wrong in your table design.Guillermo Mansilla
@GuillemoMansilla I've tried to set the query recursive to -1 and use manual joins to speed up the query.And now this is what makes count(*) query slow. Manual joins will affect count query even when I set its recursive to -1MOHA

1 Answers

1
votes

Try like it's suggested in the manual. You should be able to figure it out from now.