MySQL: INNER JOIN vs. separate queries in case of fixed amount of entries in one of the tables -


here question.

option 1:

select b.some_field  inner join b  on a.id = b.a_id ((a.field1 = '1' ,  a.field2 = '2') or (a.field1 = '2' ,  a.field2 = '1')) 

option 2:

$id1 = select id a.field1 = '1' ,  a.field2 = '2' $id2 = select id a.field1 = '2' ,  a.field2 = '1'  select b.some_field b b.a_id = '$id1' or b.a_id = '$id2' 

this of course pseudo code, $id1 , $id2 should contain values of a.id of corresponding rows.

which on has better performance?

the reason i'm asking know there 2 rows in fit condition, i'm afraid joining tables result in overhead of mysql going on huge table consist of each row in each row in b. way inner join behaves?

i'll more specific: in case primary key of (field1, field2). mysql smart enough conclude where ((a.field1 = '1' , a.field2 = '2') or (a.field1 = '2' , a.field2 = '1')) won't yield more 2 rows first extract these row/s , won't create table of rows in b each row in a?

i've tried find similar question in no success.

option 1 has better performance.

since ( field1, field2 ) primary key, , have same thing in clause. mysql is, first filter out on table a , 2 rows that. after join pretty simple.

still in case of doubt use explain command. see explain command here


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -