which one is faster
select * from parents p
inner join children c on p.id = c.pid
where p.x = 2
OR
select * from
(select * from parents where p.x = 2)
p
inner join children c on p.id = c.pid
where p.x = 2
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In
MySQL, the first one is faster:, since using an inline view implies generating and passing the records twice.
In other engines, they are usually optimized to use one execution plan.
MySQLis not very good in parallelizing and pipelining the result streams.Like this query:
is instant, while this one (which is semantically identical):
will first select all values from
mytable, buffer them somewhere and then fetch the first record.For
Oracle,SQL ServerandPostgreSQL, the queries above (and both of your queries) will most probably yield the same execution plans.