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 ]