简体   繁体   English

Codeigniter / Datamapper“ where_related”导致查询过多

[英]Codeigniter/Datamapper “where_related” causing too many queries

I have a many-to-many mapping between profiles and categories . 我在profilescategories之间有多对多映射。 This query: 该查询:

$profiles = new Profile();  
$profiles->where('foobar_flag',1);
$profiles->where_related($category);
$profiles->get();

Is taking almost 30 seconds to run, with about 1000 entries in that profiles table. 运行大约需要30秒,该概要文件表中大约有1000个条目。 There is also a category table, and a profiles_categories table. 还有一个类别表和profiles_categories表。 I end up with a staggering 4000 queries per execution. 我最终每次执行都会遇到4000个查询。

How do I make this faster? 我该如何加快速度?

If you are unhappy with a function in datamapper, either find a simplified way of doing it as your active record query might just be too costly as you say. 如果您对datamapper中的函数不满意,请选择一种简化的方法,因为您的活动记录查询可能会像您所说的那样成本太高。

Always run your profiler: 始终运行您的探查器:

$this->output->enable_profiler(TRUE);

This will give you a true idea of what is being done behind the scenes. 这将使您真正了解幕后的情况。 Optimize from there on. 从那里开始进行优化。 Otherwise we need more code to go on here to give relevant answers. 否则,我们需要更多代码才能继续给出相关答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM