I have 2 queries which should produce exactly the same result set
First query:
SELECT *
FROM rms_tests where Id in (SELECT TestId
FROm rms_test_results
where RegressionResultID = 106967
and Failed is NULL);
Second query:
SELECT t.*
FROM rms_test_results tr
LEFT JOIN rms_tests t ON tr.testid=t.id
where tr.regressionresultId = 106967
and tr.failed is NULL;
However the second one takes 0.008 seconds while the first one never finished and hangs my "MySQL Query Browser".
How does SQL evaluate the queries of type one that causes them to blow up and hang the browser forever.
NOTE: rms_test_results is incredibly large and many times larger than rms_tests. also as you can see they are related on rms_tests.id = rms_test_result.testid
Sorry if this was covered somewhere.
++++++++++++++++++++++++++++++++++++++++++++ PS I am just really confused because If I break up the query #1 into two of them and execute them one after another they take no time at all either:
SELECT TestId FROm rms_test_results where RegressionResultID = 106967 and Failed is NULL; SELECT * FROM rms_tests where Id in (1234,1235,.....);