sql - mysql query with OR optimization -
can following query optimized? indexes can created?
select column_a table_b join table_a table_b.id_b = table_a.id_a or table_b.id_b = table_a.id_b;
your query should be:
select column_a table_b join table_a on table_b.id_b in (table_a.id_a, table_a.id_b)
if don't provide on criteria join, mysql accepts being cross join
-- result cartesian product (that's bad, unless that's want). if knew table column_a
came from, might suggest different approach query...
index following:
- table_b.id_b
- table_a.id_a
- table_a.id_b
the 2 columns in table_a covering index, rather separate ones.
Comments
Post a Comment