mysql查询执行/优化问题

时间:2017-09-15 14:58:44

标签: php mysql

SELECT cus.cust_id, cus.cust_name, cus.cust_lastname, cus.cust_zip,   
cus.cust_city, cus.cust_phone, cus.cust_email, cus.status,   
cus.cust_from, cus.cust_by, cus.added_date, zip.zipcode AS zipcode_val,
COUNT(ord.customer_id) AS custTotalOrders
FROM customers AS cus
LEFT JOIN orders AS ord ON cus.cust_id = ord.customer_id
LEFT JOIN zipcodes AS zip ON cus.cust_zip = zip.zip_id
WHERE cus.cust_id IS NOT NULL AND cus.cust_email IS NOT NULL 
GROUP BY cus.cust_id, cus.cust_email
ORDER BY cus.added_date DESC

customers表有69529条记录

订单表有295884条记录

zipcodes表有1257条记录

客户表结构&索引 enter image description here

订单表结构&索引 enter image description here

邮政编码表结构&索引 enter image description here

EXPLAIN QUERY enter image description here

以上查询执行时间超过200秒/正在进行加载.......

如何优化以上查询?

如何解决这个问题? 有人帮我吗?

提前致谢

0 个答案:

没有答案