MySQL Forums
Forum List  »  MySQL Query Browser

Join Optimization Question
Posted by: Jeremy Calbreath
Date: April 21, 2011 09:21AM

I have two tables, T1 and T2. T2 is very large and takes a tremendous amount of time to query, unless I specify specific index values. The id from T1 is an indexed column in T2. I want to get a subset from T1 and join only those rows from T2 that match my subset from T1. What I would normally do is:

select * from T1
left join T2 on T2.T1_id = T1.id
where T1.id in(1,2,3,4);

My question is how does this actually work? Does it join all of the matching records between both tables and then select the ones that match the T1.id's I requested, thereby requiring the processing of all the rows in T2. Or, does it only grab the rows from T2 that match my T1 id's and join them? The 2nd scenario seems much more efficient than the 1st?

What would be the best way to optimize this query? Thanks.

Options: ReplyQuote


Subject
Written By
Posted
Join Optimization Question
April 21, 2011 09:21AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.