Cakephp中不需要的count(*)查询 [英] unwanted count(*) query in cakephp
问题描述
正如您在cakephp中所知道的那样,每个查找(选择)查询都会生成一个自动count(*)查询(cakephp将其用于分页)
我正在具有200万条记录的表中运行查询,并且我的查询运行时间为0.0016秒。但是cakephp生成的count(*)需要花费几秒钟
有没有一种方法可以阻止cakephp运行此查询?我可以禁用或伪造它吗?
我的cakephp版本是1.3
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
编辑(已解决):
我发现使用手动联接时在我的查询中,cakephp查找计数查询将是如此昂贵。因此,解决方案是删除所有手动联接,然后在cakephp分页函数中将查找计数的递归设置为-1
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
推荐答案
尝试像在手动。您应该现在就可以弄清楚。
Try like it's suggested in the manual. You should be able to figure it out from now.
这篇关于Cakephp中不需要的count(*)查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!