I need advice regarding subselect performance in MySQL. For a reason that I can’t change, I am not able to use JOIN to create quesry filter, I can only add another AND clause in WHERE.
What is the peformance of:
select tasks.* from tasks where some criteria and task.project_id not in (select id from project where project.is_template = 1);
compared to:
select tasks.* from tasks, project where some criteria and task.project_id = project.id and project.is_template <> 1;
Note that there is relatively small number of projects whete is_template = 1, and there could be large number of projects where is_template <> 1.
Is there other way to achieve the same result without subselects if I can’t change anything but and filter?
I believe that the second is more efficient as it requires only one select, but to be sure, you should EXPLAIN each query and check the results.