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

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -