I have very big database of customers. This query was ok before I added ORDER BY
. How can I optimize my query speed?
$sql = "SELECT * FROM customers LEFT JOIN ids ON customer_ids.customer_id = customers.customer_id AND ids.type = '10' ORDER BY customers.name LIMIT 10";
ids.type
and customers.name
are my indexes
Explain query
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE customers ALL NULL NULL NULL NULL 955 Using temporary; Using filesort 1 SIMPLE ids ALL type NULL NULL NULL 3551 Using where; Using join buffer (Block Nested Loop)
customer_ids
is not defined. – Gordon Linofffrom
clause does not contain such a table:FROM customers LEFT JOIN ids ON ...
so the query contains a reference to the tablecustomers
and the tableids
. – a_horse_with_no_nameLEFT JOIN ids ON ids.customer_id...
– lingo