我需要关于MySQL中的子选择性能的建议。由于我无法更改的原因,我无法使用JOIN创建quesry过滤器,我只能在WHERE中添加另一个AND子句。MySQL子查询性能问题?
什么的peformance:
select tasks.*
from tasks
where
some criteria
and task.project_id not in (select id from project where project.is_template = 1);
相比:
select tasks.*
from tasks, project
where
some criteria
and task.project_id = project.id and project.is_template <> 1;
注意,这里的项目数量相对较少whete is_template = 1,并有可能是大量的项目中is_template <> 1.
如果我不能改变任何东西,但没有过滤器,还有其他方法可以实现同样的结果吗?
感谢您的EXPLAIN提示。 似乎在project.is_template上添加索引有很大帮助。 – Marko 2008-12-04 16:28:13