这是EXPLAIN图
sql语句如下 该加的索引都加了 可就是不走索引
SELECT
e.*, u.user_name,
MAx(yc. STATUS)AS jzstatus,
u.real_name URealName,
au.real_name auditRealName,
su.real_name settleRealName,
u.mobile,
c.zh_name customer_name,
c. CODE customer_code,
c.total_amount customer_total_amount,
l.boat_name,
l.voyage_num,
l.leave_time,
l.boat_company_name,
l.boat_voyage,
l.loading_name,
l.unload_name,
l.change_name,
b.business_type,
b.container_type,
b.container_num,
b.container_no,
b.business_no,
ct.zh_name conName,
ct. CODE conCode,
ct.con_length,
oe.send_user_name,
oe.order_user_name,
oe.address,
oe.loading_address,
og. NAME goods_name,
IFNULL(sl.real_name, sl.user_name)salesUserRealName,
IFNULL(bu.real_name, bu.user_name)bookUserRealName,
sl.user_name salesUserName,
bu.user_name bookUserName,
op. STATUS oStatus,
op.is_locked oIsLock
FROM
ymcms_expenses e
LEFT JOIN ymcms_user u ON u.id = e.input_people
LEFT JOIN ymcms_user au ON au.id = e.audit_uid
LEFT JOIN ymcms_user su ON su.id = e.settle_uid
LEFT JOIN ymcms_customer c ON c.id = e.customer
LEFT JOIN ymcms_order_lane l ON l.order_id = e.order_id
LEFT JOIN ymcms_order_basic b ON b.id = e.order_id
LEFT JOIN ymcms_container_type ct ON ct.id = b.container_type
LEFT JOIN ymcms_order_entrust oe ON oe.order_id = b.id
LEFT JOIN ymcms_order_product og ON og.order_id = b.id
LEFT JOIN ymcms_user sl ON sl.id = b.sales_user
LEFT JOIN ymcms_order_operation op ON op.order_id = b.id
LEFT JOIN ymcms_user bu ON bu.id = b.book_operation_user
LEFT JOIN ymcms_container yc ON b.id = yc.order_id
WHERE
1 = 1
AND(
(
op. STATUS = 0
AND op.is_deleted = 0
AND e.input_people = '2f67225416cc4b74b6d1113118a43aa9'
)
OR op. STATUS > 0
)
AND e.site_id = '1'
AND l.leave_time >= 1514736000000
GROUP BY
e.id
ORDER BY
l.leave_time DESC,
b.business_no,
e.input_time DESC
各位大佬 帮忙给出一个优化的思路 谢谢
你确定要把这么对列一次读出来吗,可以试试分成几次查询,如果必须一次读出来我再想想办法
这么多字段显示,group by 却只有一个e.id ?
有些where 条件可以 在 join 在处里了,那就在join 中处理了试试
,max(yc. STATUS)
可以在LEFT JOIN ymcms_container yc 中就取了最大值试试,
索引没有被使用,在确定添加了索引的情况下,你需要看下你的关联字段在两表中的字符编码是不是一致,如果不一致,索引不会被使用
这是Oracle数据库?可以使用hint走索引