请帮我优化这个mysql查询。加载需要更多时间

时间:2012-11-19 10:01:47

标签: mysql

SELECT 
           f_workorders_shipments.date,
           f_inventory.id AS item_id,
           f_workorders_shipments.inventory_code AS code,
           f_inventory`.status,
           f_inventory.type,
           f_workorders.id AS order_id
         FROM f_workorders
         LEFT JOIN f_workorders_shipments
         ON f_workorders.id = f_workorders_shipments.order_id
         LEFT JOIN `f_inventory`
         ON f_workorders_shipments.inventory_code = f_inventory.code
         WHERE contact_id = "'.$_POST['id'].'"
         AND inventory_code IS NOT NULL
         ORDER BY due DESC'

1 个答案:

答案 0 :(得分:0)

由于联接将数量乘以要检查的行,因此必须注意索引。

请为每个重要的字段制作索引,以便过滤或与其他表中的其他字段连接。

良好的索引减少了执行sql命令的时间