mysql - Where inside JOIN ON clause? -
if have following tables:
table_a
id | name |tbl_b_key| status -----+---------+---------+-------- 0 | | 1 | 0 1 | b | 2 | 0 2 | c | 3 | 1
table_b
id | type | status -----+---------+--------- 0 | | 0 1 | b | 0 2 | b | 1 3 | | 1
is there difference in terms of performance between these 2 queries?
select table_a.name, table_b.type table_a join table_b on (table_a.status = table_b.status , table_b.type = a); select table_a.name, table_b.type table_a join table_b on (table_a.status = table_b.status) table_b.type = a;
my understanding first query faster, first reduces amount of rows being joined whereas second query join performs where. or there no real difference between two?
edit: pointed out made mistake in first query, fixed now.
the 2 queries equivalent. there's no difference.
when have 2 valid queries want compare, can run explain
on each see execution plan mysql use.
and can execute each query measure performance. (run each query several times, bypassing mysql query cache,measure elapsed time each execution, , throw out time first execution.)
in general, mysql ignore superfluous parens. predicate predicate predicate. doesn't matter if it's in clause or in on clause of inner join condition. mysql sees same
mysql sees of these forms equivalent:
... join b on a.foo = b.foo , b.bar = '1' ... ... join b on (a.foo = b.foo , b.bar = '1') ... ... join b on a.foo = b.foo b.bar = '1' , ... ... join b on (a.foo = b.foo) b.bar = '1' , ... ... join b a.foo = b.foo , b.bar = '1' , ...
we can run explain
on of different forms, , see exact same execution plan. don't expect difference in performance.
(with outer join, there's difference between predicates in on clause , in clause.)
Comments
Post a Comment