0
有沒有一個完美的解釋,爲什麼我的查詢往往加載速度慢到100secs?爲什麼我的查詢加載速度比正常查詢慢
是否有任何可能的重建使我的查詢加載速度更快?
SELECT IF(IMI.BRANCH_CODE IS NOT NULL AND IMI.PRODCODE IS NOT NULL AND IMI.POLNO IS NOT NULL,"Y","N") as STATUS,
NOW(),ICH.CLAIM_NO,ICH.BRANCH_CODE,
ICH.PRODUCT_TYPE,ICH.POLICY_NO,ICH.ASSURED_NAME,
ICH.AGENT_NO,ICH.INCEPTION_DT,ICH.EXPIRY_DT,
ICH.DT_REPORTED,IMI.BASIC_PREMIUM,ICH.CLAIM_STATUS,
IRPD.CLAIM_RESERVE,IRPD.TOTAL_AMT_RECOMMENDED,IRPD.DT_RECOMMENDED,
IMI.UW_YEAR,ICDO.PLATE_NO,ICDO.CHASSIS_NO,
ICDO.MOTOR_NO,IMI.LOCATION,IMI.RISKNO,IMI.SEQNO
FROM `ICATS_CLAIM_HEADER` ICH
LEFT JOIN `ICATS_CLAIM_DETAILS_OD` ICDO ON ICH.CLAIM_NO = ICDO.CLAIM_NO
LEFT JOIN `ICATS_MULTIPLE_LOSS` IML ON ICH.CLAIM_NO = IML.CLAIM_NO
LEFT JOIN (SELECT * FROM ICATS_RESERVE_PAYMENT_DETAILS
WHERE DATEDIFF(NOW(),DT_RECOMMENDED)=1 OR DATEDIFF(NOW(),RESERVE_DT)=1) IRPD
ON ICH.CLAIM_NO = IRPD.CLAIM_NO
LEFT JOIN (SELECT POLNO,PRODCODE,BRANCH_CODE,MAX(SEQNO)as SEQNO FROM IWRITE_MOTOR_INFO
GROUP BY POLNO,PRODCODE,BRANCH_CODE) IM
ON ICH.POLICY_NO = IM.POLNO AND ICH.BRANCH_CODE = IM.BRANCH_CODE AND ICH.PRODUCT_TYPE = IM.PRODCODE
JOIN IWRITE_MOTOR_INFO IMI
ON IM.POLNO = IMI.POLNO AND IM.PRODCODE = IMI.PRODCODE AND IM.BRANCH_CODE = IMI.BRANCH_CODE AND IM.SEQNO = IMI.SEQNO
WHERE (DATEDIFF(CURDATE(),ICH.CLAIM_STATUS_DT)=1
OR DATEDIFF(NOW(),ICDO.TRANSACTION_DT)=1
OR DATEDIFF(NOW(),IRPD.RESERVE_DT)=1
OR DATEDIFF(NOW(),IRPD.DT_RECOMMENDED)=1)
ORDER BY ICH.CLAIM_NO,IRPD.SEQUENCE_NO ASC
在整體這裏是我的整個query.Just的事實,同時檢查所有的DATAS要插入我的查詢似乎加載緩慢,以100secs。
INSERT INTO `ICATS_IINSURE_CLAIM_HEADER`(IINSURE_EXIST,RECORD_CREATED_DT,CLAIM_NUMBER,BRANCH_CODE,PRODCODE,POLNO,ASSURED_NAME1,
AGENT_CODE,INCEPTION,EXPIRY,DATE_REPORTED,BASIC_PREMIUM,
CLAIM_STATUS,RESERVE_AMOUNT,CLAIMS_PAID_AMOUNT,
DATE_RECOMMEND_PAYMENT,UW_YEAR,PLATE_NUMBER,
CHASSIS,ENGINE,LOCATION,RISKNO,SEQ)
SELECT IF(IMI.BRANCH_CODE IS NOT NULL AND IMI.PRODCODE IS NOT NULL AND IMI.POLNO IS NOT NULL,"Y","N") as STATUS,
NOW(),ICH.CLAIM_NO,ICH.BRANCH_CODE,
ICH.PRODUCT_TYPE,ICH.POLICY_NO,ICH.ASSURED_NAME,
ICH.AGENT_NO,ICH.INCEPTION_DT,ICH.EXPIRY_DT,
ICH.DT_REPORTED,IMI.BASIC_PREMIUM,ICH.CLAIM_STATUS,
IRPD.CLAIM_RESERVE,IRPD.TOTAL_AMT_RECOMMENDED,IRPD.DT_RECOMMENDED,
IMI.UW_YEAR,ICDO.PLATE_NO,ICDO.CHASSIS_NO,
ICDO.MOTOR_NO,IMI.LOCATION,IMI.RISKNO,IMI.SEQNO
FROM `ICATS_CLAIM_HEADER` ICH
LEFT JOIN `ICATS_CLAIM_DETAILS_OD` ICDO ON ICH.CLAIM_NO = ICDO.CLAIM_NO
LEFT JOIN `ICATS_MULTIPLE_LOSS` IML ON ICH.CLAIM_NO = IML.CLAIM_NO
LEFT JOIN (SELECT * FROM ICATS_RESERVE_PAYMENT_DETAILS
WHERE DATEDIFF(NOW(),DT_RECOMMENDED)=1 OR DATEDIFF(NOW(),RESERVE_DT)=1) IRPD
ON ICH.CLAIM_NO = IRPD.CLAIM_NO
LEFT JOIN (SELECT POLNO,PRODCODE,BRANCH_CODE,MAX(SEQNO)as SEQNO FROM IWRITE_MOTOR_INFO
GROUP BY POLNO,PRODCODE,BRANCH_CODE) IM
ON ICH.POLICY_NO = IM.POLNO AND ICH.BRANCH_CODE = IM.BRANCH_CODE AND ICH.PRODUCT_TYPE = IM.PRODCODE
JOIN IWRITE_MOTOR_INFO IMI
ON IM.POLNO = IMI.POLNO AND IM.PRODCODE = IMI.PRODCODE AND IM.BRANCH_CODE = IMI.BRANCH_CODE AND IM.SEQNO = IMI.SEQNO
WHERE (DATEDIFF(CURDATE(),ICH.CLAIM_STATUS_DT)=1
OR DATEDIFF(NOW(),ICDO.TRANSACTION_DT)=1
OR DATEDIFF(NOW(),IRPD.RESERVE_DT)=1
OR DATEDIFF(NOW(),IRPD.DT_RECOMMENDED)=1)
ORDER BY ICH.CLAIM_NO,IRPD.SEQUENCE_NO ASC
儘量避免使用內部選擇(我可以看到一些在你的「左連接」) – SNpn 2013-03-19 02:13:53
ORs臭名昭着的表現不佳 – 2013-03-19 02:14:30
@SNpn,我看到通過從子查詢而不是實際表中選擇性能提高。 – 2013-03-19 02:20:29