jackleeonlyone 2018-01-16 04:41 采纳率: 100%
浏览 1289
已结题

求助大佬们,oracle SQL优化,一条SQL语句要加载一两分钟(真心求助),慢得要死

SELECT t.id,t.code,t.creater,st_createName.lastName createName,t.createDept,st_createDeptName.departmentName createDeptName,t.createDay,t.type,t.content,t.score,t.accepter,st_accepterName.lastName accepterName,t.acceptDept,st_acceptDeptName.departmentName acceptDeptName,st_acceptSubCpyName.subCompanyName acceptSubCpyName,t.acceptStatus,t.underTaker,st_underTakerName.lastName underTakerName,t.underTakeSender,t.planFinishDay,t.reason, '' Auto_Carry_Empty_Column ,(case t.type when 'QI' then '品质改善' when 'PEI' then '工艺、设备改进' when 'EI' then '现场环境改善' when 'PQ' then '产品使用品质' when 'PAS' then '产品应用服务' when 'MA' then '营销的方法' when 'ED' then '设备研发' when 'RM' then '方法研发' when 'PD' then '产品研发' when 'MI' then '管理创新' when 'CI' then '文化创新' else '' end) typeText,(case t.acceptStatus when 'Init' then '初始' when 'Back' then '采纳' when 'Execute' then '采纳' when 'Finish' then '完成' when 'CA' then '确认' when 'Recommend' then '确认' when 'Unable' then '无效' when 'DoNotAccept' then '不采纳' when 'Switch' then '初始' else '' end) statusText,(select count(s.id) from WV_Advice_Log s where s.adv = t.id and s.logType = 'Browse') browserCount,(select count(s.id) from WV_Advice_Log s where s.adv = t.id and s.logType = 'Talk') talkCount,concat(concat(concat(concat(''),t.content),'') showLink from WV_Advice t left join hrmResource st_createName on to_char(st_createName.id) = t.creater left join hrmDepartment st_createDeptName on to_char(st_createDeptName.id) = t.createDept left join hrmResource st_accepterName on to_char(st_accepterName.id) = t.accepter left join hrmDepartment st_acceptDeptName on to_char(st_acceptDeptName.id) = t.acceptDept left join hrmSubCompany st_acceptSubCpyName on to_char(st_acceptSubCpyName.id) = t.acceptDept left join hrmResource st_underTakerName on to_char(st_underTakerName.id) = t.underTaker where 1=1 and (1!=1 or acceptDept = '93' or accepter = '2304') and (1!=1 or acceptStatus = 'Init' or acceptStatus = 'Back' or acceptStatus = 'Switch') ORDER BY t.createDay desc , t.id desc

  • 写回答

9条回答 默认 最新

  • deathlover9527 2018-01-16 05:14
    关注

    不懂业务的没法优化。
    LEFT JOIN 的时候,数据量小的放前面。
    原则就是:
    1. 有索引的,用索引
    2. 对大表做数据关联时,尽量不要把大表放到子查询中;有时可以考虑直接关联该表,并用 on 的条件做过滤。
    3. 尽量减少使用函数

    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线边框
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题