MySQL Forums
Forum List  »  Optimizer & Parser

Re: Three(or Four)-Way Joins
Posted by: Rick James
Date: August 12, 2009 08:35PM

MySQL will usually come up with the best way to join tables. The most useful control you have is in the INDEXes you create.

Based on what you say, it will probably want to start with table1, then table2, then the others.

Possibly you need
table2: INDEX(X)
table3, table4: INDEX(K) (or, more likely, PRIMARY KEY(K))

Are A,B,C the other values you are fetching? If so, it _might_ help to have
table2: INDEX(X,K,A)
table3: INDEX(K,B)
table4: INDEX(K,C)
Then it might be more efficient by "Using index" (see the EXPLAIN).

It would really help to see the SELECT statement.

To assist in analyzing slow SELECTs, please provide
* SHOW CREATE TABLE tbl\G
* SHOW TABLE STATUS LIKE 'tbl'\G
* EXPLAIN SELECT ...\G
and surround them with [ code ] and [ / code ]

Options: ReplyQuote


Subject
Views
Written By
Posted
3760
August 11, 2009 07:10PM
Re: Three(or Four)-Way Joins
2118
August 12, 2009 08:35PM
1863
August 12, 2009 09:31PM
1966
August 13, 2009 12:16AM
1946
August 13, 2009 12:26PM
2642
August 13, 2009 10:34PM


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.