当我触发下面的mysql查询时,它需要查询[显示行0 - 29(总计13,436,查询花费0.1715秒)]时间,但是显示约3到5分钟需要更多时间。我总共delivery_to_shop有13,418行和table shopdelivery_to_client b 7000行和其他几行。我正在努力优化但不是成功, 我正试图找出问题是什么?查询如下:
SELECT
DISTINCT(a.`factory_deli_id`),a.`shop_id`,a.`entry_date`,(a.slip_no) AS FSNo,(s.shop_name) AS FShopName,(i.dress_type_entry) AS FInitItem,(a.item_qty) AS FQty,FORMAT(i.price_rate_max, 2) AS FItemRate,FORMAT(a.item_qty*i.price_rate_max, 2) AS FTot,
b.`entry_date`,b.`shop_id`, b.`factory_item_id`, b.`slip_no`
FROM delivery_to_shop a
INNER JOIN init_item_entry i
ON a.factory_item_id = i.factory_item_id
INNER JOIN shop_name_entry s
ON a.shop_id = s.shop_id
LEFT JOIN shopdelivery_to_client b
ON a.`slip_no` = b.`slip_no`
AND a.`factory_item_id` = b.`factory_item_id`
AND a.`shop_id` = b.`shop_id`
任何帮助?
答案 0 :(得分:0)
为开始添加一些索引:
ALTER TABLE delivery_to_shop ADD INDEX index1 (factory_item_id, shop_id, slip_no)
ALTER TABLE init_item_entry ADD INDEX index2 (init_item_entry)
ALTER TABLE shop_name_entry ADD INDEX index3 (shop_id)
ALTER TABLE shopdelivery_to_client ADD INDEX index4 (factory_item_id, shop_id, slip_no)