Mysql 在我所看到的每种情况下,即使查询为In操作返回一组不变的行,也会为主查询的每个结果运行子查询。 select tasks.* from tasks where some criteria and task.project_id not in (s

Mysql 在我所看到的每种情况下,即使查询为In操作返回一组不变的行,也会为主查询的每个结果运行子查询。 select tasks.* from tasks where some criteria and task.project_id not in (s,mysql,optimization,subquery,Mysql,Optimization,Subquery,在我所看到的每种情况下,即使查询为In操作返回一组不变的行,也会为主查询的每个结果运行子查询。 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


在我所看到的每种情况下,即使查询为In操作返回一组不变的行,也会为主查询的每个结果运行子查询。
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;
EXPLAIN select tasks.*
from tasks
where 
  some criteria
  and task.project_id not in (select id from project where project.is_template = 1);

EXPLAIN select tasks.*
from tasks, project
where
  some criteria
  and task.project_id = project.id and project.is_template <> 1;
select tasks.*
from tasks
where 
  some criteria
  and task.project_id in (select id from project where project.is_template <> 1);