优化查询以减少响应时间

时间:2018-02-05 12:47:35

标签: mysql

在我的Spring MVC应用程序中,我使用Spring JDBC模板,获取记录并将其显示给用户。

像往常一样,它从后端获取记录,但我的查询至少需要3-4秒。

我想调整或优化它,这样可以节省更多时间。只有5000条记录,请建议我最好的解决方案。

SELECT a.APPLICATION_NO ,
  a.APPROVED_DATE ,
  e.ESTIMATE_NO ,
  lcd.NAME ,
  uam_c.NAME circleName ,
  uam_dc.NAME dcName ,
  ksd.CONTRACTOR_ID ,
  UR.NAME CONTRACTOR_NAME ,
  UR.FIRM_NAME ,
  UR.REG_UNIQUE_ID ,
  UD.PUBLIC_PATH ,
  e.ESTIMATE_PDF_FILE_URL ,
  ele.WO_ELE_ID ,
  ele.UPDATE_BY ,
  ele.APPROVE_STATUS ,
  ele.REJECT_STATUS ,
  ele.REJECT_DATE ,
  ele.ACCEPT_STATUS ,
  ele.ACCEPT_DATE ,
  ele.UPDATE_DATE WO_UPDATE_DATE ,
  ele.APPROVE_DATE WO_APPROVE_DATE ,
  ele.WO_ELE_NO WO_ELE_NO ,
  ele.WO_AMOUNT WO_AMOUNT ,
  ele.ACCEPT_STATUS WO_ACCEPT_STATUS ,
  SUD.PUBLIC_PATH SLD_PATH ,
  CUD.PUBLIC_PATH CHECK_PATH ,
  b.BOQ_ID ,
  ahr.APPLICATION_NO,
  ahr.REASON_ID ,
  ahr.UPLOAD_ID ,
  ahr.STATUS APP_HOLD_STATUS ,
  b.PDF_FOR_CONTRACTOR ,
  b.PDF_FOR_MPMKVVCL ,
  row_number() OVER(ORDER BY APPROVED_DATE ASC ) rnum
FROM NSC_USER.APPLICATION a
JOIN NSC_USER.LT_CONTACT_DETAIL lcd
ON lcd.APPLICATION_NO   =a.APPLICATION_NO
AND a.APPLICATION_STATUS='Approved'
AND a.CONNECTION_TYPE   =1
AND a.APPLICATION_TYPE  =4
JOIN NSC_USER.LT_ADDRESS_DETAIL lad
ON lad.APPLICATION_NO=a.APPLICATION_NO
JOIN NSC_USER.ESTIMATE e
ON a.APPLICATION_NO=e.APPLICATION_NO
AND E.Status       ='Approved'
JOIN NSC_USER.KAY_SUBSIDY_DETAIL ksd
ON ksd.APPLICATION_NO      =a.APPLICATION_NO
AND ksd.PROCEED_BY         ='MPMKVVCL'
AND ((ksd.STATUS           =3
AND ksd.IS_SUBSIDYUSED     ='Y')
OR ((ksd.IS_SUBSIDYUSED    ='N'
OR (ksd.IS_SUBSIDYUSED     ='Y'
AND ksd.IS_SUBSIDYAVAILABLE='N'))
AND ksd.STATUS             =1) )
JOIN NSC_USER.UPLOAD UD
ON UD.UPLOAD_ID = a.UPLOAD_APP_PDF
JOIN NSC_USER.UPLOAD SUD
ON SUD.UPLOAD_ID = a.UPLOAD_SLD
JOIN NSC_USER.UPLOAD CUD
ON CUD.UPLOAD_ID = a.UPLOAD_CHECK_LIST
JOIN UAM_USER.FEEDER f
ON f.FEEDER_ID=lad.CONN_FEEDER_ID
JOIN UAM_USER.SUBSTATION uam_s
ON uam_s.SUBSTATION_ID = f.SUBSTATION_ID
JOIN UAM_USER.DC uam_dc
ON uam_s.DC_ID = uam_dc.DC_ID
JOIN UAM_USER.SUB_DIVISION uam_sd
ON uam_dc.SUBDIVISION_ID = uam_sd.SUBDIVISION_ID
JOIN UAM_USER.DIVISION uam_d
ON uam_sd.DIVISION_ID = uam_d.DIVISION_ID
JOIN UAM_USER.CIRCLE uam_c
ON lad.CIRCLE_ID = uam_c.CIRCLE_ID
LEFT JOIN CONTRACTOR_USER.USER_REGISTRATION UR
ON UR.CONTRACTOR_ID = ksd.CONTRACTOR_ID
LEFT JOIN CONTRACTOR_USER.WORK_ORDER_ELE ele
ON ele.APPLICATION_NO  = a.APPLICATION_NO
AND (ele.REJECT_STATUS =0
OR ele.REJECT_STATUS  IS NULL)
LEFT JOIN CONTRACTOR_USER.BOQ b
ON b.WO_ELE_ID = ele.WO_ELE_ID
LEFT JOIN CONTRACTOR_USER.APPLICATION_HOLD_REASON ahr
ON ahr.APPLICATION_NO = ele.APPLICATION_NO
LEFT JOIN
  (SELECT Ai.Application_No
  FROM CONTRACTOR_USER.Nsc_Application_Item ai
  WHERE Ai.Work_Order_Status=1
  AND Ai.Accecp_Status      =1
  ) t1
ON t1.Application_No=a.APPLICATION_NO
LEFT JOIN
  (SELECT Oa.Application_No FROM CONTRACTOR_USER.Offline_Applications oa
  ) t2
ON t2.Application_No=a.APPLICATION_NO
LEFT JOIN
  (SELECT A.Application_No
  FROM NSC_USER.Application A
  LEFT JOIN NSC_USER.Lt_Connection_Detail lt
  ON Lt.Application_No = A.Application_No
  LEFT JOIN CONTRACTOR_USER.Work_Order_Ele ele
  ON Ele.Application_No    = A.Application_No
  WHERE Lt.Dtr_Required    ='N'
  AND Lt.Dtr_Length       <=45
  AND Ele.Wo_Ele_Id       IS NULL
  ) t3 ON t3.Application_No=a.APPLICATION_NO
WHERE t1.Application_No   IS NULL
AND t2.Application_No     IS NULL
AND t3.application_no     IS NULL
AND ahr.STATUS             ='Hold'
ORDER BY APPROVED_DATE ASC; 

0 个答案:

没有答案