sql - MySQL Join: Conditions in WHERE or in ON (2) -


i know if putting conditions join in on () clause better, maintaining, in latter where.

example:

select * persons p   inner join x on (x.id = p.id , x.other = p.other)  select * persons p   inner join x on (x.id = p.id) x.other = p.other 

here seems good, multiple joins, more difficult, think:

select * persons p   inner join x on (x.id = p.id)   inner join x2 on (x2.id = p.id)   inner join x3 on (x3.id = p.id) x.other = p.other , x2.other = p.other2 , x3.other = p.other3  select * persons p   inner join x on (x.id = p.id , x.other = p.other)   inner join x2 on (x2.id = p.id , x2.other = p.other2)   inner join x3 on (x3.id = p.id , x3.other = p.other3) 

i have test app i'm developing , switching conditions produces same execution plan, thought don't know if i'm missing something, or if can find performance impact in situations.

thanks

edit: not same question being marked duplicated. not ask difference between join , where. ask difference of putting conditions in , not in on clause when using join statement.

as said in comment in previous question, shouldn't faster second join process filtered data process data later?

the difference between putting conditions on joins versus putting them in clause shape of data in each query.

let's assume have 1000 rows in persons table, 800 rows in x, 600 rows in x2, , 500 rows in x3 match persons.id join conditions you've specified.

in query:

select * persons p   inner join x on (x.id = p.id)   inner join x2 on (x2.id = p.id)   inner join x3 on (x3.id = p.id) x.other = p.other , x2.other = p.other2 , x3.other = p.other3 

by time reach clause evaluating 500 rows on conditions you've specified.

whereas in query:

select * persons p   inner join x on (x.id = p.id , x.other = p.other)   inner join x2 on (x2.id = p.id , x2.other = p2.other)   inner join x3 on (x3.id = p.id , x3.other = p3.other) 

you may still end evaluating 500 rows in worst case scenario (all of x.other = p.other conditions evaluate true), end evaluating fewer rows time reach last join.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -