我需要有关 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 的项目数量可能很多。
如果我除了过滤之外什么都不能改变,还有其他方法可以在没有子选择的情况下获得相同的结果吗?