I have the following query where
- A has 1 000 000 rows
- B, C, D has 150 000 rows each
- E has 50 000 rows
The query itself seems to take around 50 seconds to complete. It will usually contain a WHERE clause as it is doing a search through all the possible data in the database. Is there any way this could be improved?
SELECT A.one, A.two, A.three
FROM A
LEFT JOIN B ON ( A.id = B.id )
LEFT JOIN C ON ( A.id = C.d )
LEFT JOIN D ON ( A.id = D.id )
LEFT JOIN E ON ( A.name = E.name
AND E.date <= A.date )
ORDER BY A.id ASC
Explain query:
+----+-------------+-------+--------+---------------+----------+---------+-----------+--------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+---------------+----------+---------+-----------+--------+-------------+
| 1 | SIMPLE | A | index | NULL | PRIMARY | 17 | NULL | 357752 | |
| 1 | SIMPLE | B | eq_ref | PRIMARY | PRIMARY | 17 | db.A.id | 1 | Using index |
| 1 | SIMPLE | C | eq_ref | PRIMARY | PRIMARY | 17 | db.A.id | 1 | Using index |
| 1 | SIMPLE | D | eq_ref | PRIMARY | PRIMARY | 17 | db.A.id | 1 | Using index |
| 1 | SIMPLE | E | ref | Name,Date | Name | 62 | db.A.name | 1 | |
+----+-------------+-------+--------+---------------+----------+---------+-----------+--------+-------------+