Are there any ways that the following query could be optimised for speed? It takes about 6 seconds to execute. Each table only contains around 1000 records so it’s not huge.
SELECT c. * , q.qualification_name, CONCAT( u.firstname, ' ', u.lastname ) AS name, v.venue_name, v.address_town
FROM p_courses c
LEFT JOIN p_qualifications q ON c.qualification_name = q.ref
LEFT JOIN p_users u ON c.instructor_number = u.instructor_number
LEFT JOIN p_venues v ON c.venue_token = v.token
WHERE (
c.status = 'completed'
OR c.status = 'confirmed'
)
The above query works and retrieves all data as requested, it just takes a long time as soon as I add more than one LEFT JOIN.
Thanks.
EDITED.
Adding EXPLAIN in front of the query returns this…
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE c ALL NULL NULL NULL NULL 1288 Using where
1 SIMPLE q ALL NULL NULL NULL NULL 21
1 SIMPLE u ALL NULL NULL NULL NULL 518
1 SIMPLE v ALL NULL NULL NULL NULL 669
Sorry but I’m not quite sure how to interpret that.
EXPLAINin front of your query.EXPLAINagainhints: you probably want an index on: