content_image/676065.jpg content_image/676064.jpg content_image/676063.jpg
For this example, make the following assumptions: 

•The columns being compared have been declared as follows. 

AND tt.ActualPC = et.EMPLOYID AND tt.AssignedPC = et_1.EMPLOYID AND tt.ClientID = do.CUSTNMBR; 

<img src='content_image/676065.jpg'>

•The tables have the following indexes. 

<img src='content_image/676064.jpg'>

•The tt.ActualPC  values are not evenly distributed. 

Initially, before any optimizations have been performed, the EXPLAIN  statement produces the following information: 

<img src='content_image/676063.jpg'>

Because type  is ALL  for each table, this output indicates that MySQL is generating a Cartesian product of all the tables; that is, every combination of rows. This takes quite a long time, because the product of the number of rows in each table must be examined. For the case at hand, this product is 74 × 2135 × 74 × 3872 = 45,268,558,720 rows. If the tables were bigger, you can only imagine how long it would take. 

One problem here is that MySQL can use indexes on columns more efficiently if they are declared as the same type and size. In this context, VARCHAR  and CHAR  are considered the same if they are declared as the same size. tt.ActualPC  is declared as CHAR(10)  and et.EMPLOYID  is CHAR(15) , so there is a length mismatch. 

To fix this disparity between column lengths, use ALTER TABLE  to lengthen ActualPC  from 10 characters to 15 characters: 

mysql> ALTER TABLE tt MODIFY ActualPC VARCHAR(15); 

Now tt.ActualPC  and et.EMPLOYID  are both VARCHAR(15) . Executing the EXPLAIN  statement again produces this result: 

