【发布时间】:2010-09-25 08:39:06
【问题描述】:
我需要有关 MySQL 中子选择性能的建议。由于我无法更改的原因,我无法使用 JOIN 创建查询过滤器,我只能在 WHERE 中添加另一个 AND 子句。
性能如何:
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;
请注意,is_template = 1 的项目数量相对较少,而 is_template 1 的项目数量可能很多。
如果除了过滤器我不能改变任何东西,还有其他方法可以在没有子选择的情况下获得相同的结果吗?
【问题讨论】:
标签: mysql optimization subquery