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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -