안녕하세요! 여쭙고싶은게 있어 글을 올립니다.
다름이 아니고 기존 검색 프로그램에서 컬럼 하나를 추가했는데
속도가 다섯배ㅜ_ㅜ는 느려져 버렸는데요, 짐작가는 이유가 있다면 알려주시면 감사하겠습니다!!
날씨 추운데 몸조리 잘하세요!
------------------------------------------------------------------------------------------------------------------------------
SELECT T.REQ_NO
, T.ISSUE_NO
, T.OPEN_YN
, T.REQ_NAME
, T.REQ_PERSON
, T.REQ_LIST
, T.EXP_NAME
, T.MAKER_NAME
, T.RECEIPT_DATE
, T.EXPERIMENT_NO
, T.FIR_EMP_ID
, T.FIR_EMP_NAME
, T.SEC_EMP_ID
, T.SEC_EMP_NAME
, T.PAYER
, T.REQ_DATE
, T.RETAKE_NO
, T.OVER_DATE
, T.REQ_CUS_CD
, T.MAKER_CUS_CD
, T.PAY_CUS_CD
, T.TOT_PRICE
FROM (SELECT A.REQ_NO AS REQ_NO
, A.ISSUE_NO
, A.OPEN_YN
, NVL(GET_CUSTOMER_NAME(A.REQ_CUS_CD),A.REQ_NAME) AS REQ_NAME
, A.REQ_PERSON AS REQ_PERSON
, A.EXP_LIST AS REQ_LIST
, B.NAME AS EXP_NAME
, NVL(GET_CUSTOMER_NAME(A.MAKER_CUS_CD),A.MAKER_NAME) AS MAKER_NAME
, DECODE(NVL(TO_CHAR(RECEIPT_DATE, 'YYYY/MM/DD'), 'N'), 'N', '미입금', TO_CHAR(RECEIPT_DATE, 'YYYY/MM/DD')) AS RECEIPT_DATE
, A.EXPERIMENT_NO AS EXPERIMENT_NO
, A.FIR_EMP_ID
, C.NAME AS FIR_EMP_NAME
, A.SEC_EMP_ID
, D.NAME AS SEC_EMP_NAME
, NVL(GET_CUSTOMER_NAME(A.PAY_CUS_CD),A.PAYER) AS PAYER
, A.REQ_DATE
, A.RETAKE_NO
, CASE WHEN NVL(TO_CHAR(K.FINISH_DATE,'YYYYMMDD'),'0') = '0'
AND NVL(TO_CHAR(RECEIPT_DATE,'YYYYMMDD'),'0') != '0'
THEN TO_CHAR(TO_DATE(TO_CHAR(SYSDATE,'YYYYMMDD')) - TO_DATE(TO_CHAR(RECEIPT_DATE,'YYYYMMDD'))) + 1 || ''
ELSE '0'
END AS OVER_DATE
, A.REQ_CUS_CD
, A.MAKER_CUS_CD
, A.PAY_CUS_CD
, NVL(CASE WHEN A.RETAKE_RATE > 0
THEN TRUNC(Z.TOT_PRICE - ((Z.TOT_PRICE * A.RETAKE_RATE)/100),-1)
ELSE TRUNC(Z.TOT_PRICE,-1)
END,0) AS TOT_PRICE
FROM (SELECT U.REQ_NO
, U.OPEN_YN
, U.EXP_SUM + U.TECH_SUM + U.TRIP_SUM + U.TRUST_SUM AS TOT_PRICE
FROM ( SELECT P.REQ_NO
, P.OPEN_YN
, P.EXP_SUM
, P.TECH_SUM
, P.TRIP_SUM
, NVL(SUM(H.TRUST_AMT),0) + NVL(SUM(H.MANAGE_VALUE),0) AS TRUST_SUM
FROM ( SELECT V.REQ_NO
, V.OPEN_YN
, V.EXP_SUM
, V.TECH_SUM
, NVL(SUM(G.TRIP_VALUE),0) AS TRIP_SUM
FROM ( SELECT W.REQ_NO
, W.OPEN_YN
, W.EXP_SUM
, NVL(SUM(F.TOTAL_VALUE),0) + NVL(SUM(F.MANAGE_VALUE),0) AS TECH_SUM
FROM ( SELECT Y.REQ_NO
, Y.OPEN_YN
, NVL(SUM(E.EXP_AMT_1),0) + NVL(SUM(E.EXP_AMT_2),0)
+ NVL(SUM(E.EXP_AMT_3),0) + NVL(SUM(E.EXP_AMT_4),0)
+ NVL(SUM(E.EXP_AMT_5),0) + NVL(SUM(E.EXP_AMT_6),0) AS EXP_SUM
FROM (SELECT X.REQ_NO
, X.OPEN_YN
FROM EXPERIMENT_REQ X
WHERE TO_CHAR(X.REQ_DATE,'YYYYMM') BETWEEN #p_yearS# AND #p_yearE#
) Y
LEFT OUTER JOIN EXPERIMENT_EXP E ON Y.REQ_NO = E.REQ_NO
GROUP BY Y.REQ_NO
, Y.OPEN_YN
) W
LEFT OUTER JOIN EXPERIMENT_TECH_TRIP F ON W.REQ_NO = F.REQ_NO
GROUP BY W.REQ_NO
, W.OPEN_YN
, W.EXP_SUM
) V
LEFT OUTER JOIN EXPERIMENT_TRIP G ON V.REQ_NO = G.REQ_NO
GROUP BY V.REQ_NO
, V.OPEN_YN
, V.EXP_SUM
, V.TECH_SUM
) P
LEFT OUTER JOIN EXPERIMENT_TRUST H ON P.REQ_NO = H.REQ_NO
GROUP BY P.REQ_NO
, P.OPEN_YN
, P.EXP_SUM
, P.TECH_SUM
, P.TRIP_SUM
) U
) Z
INNER JOIN EXPERIMENT_REQ A ON Z.REQ_NO = A.REQ_NO
AND Z.OPEN_YN = A.OPEN_YN
INNER JOIN KMIS.CODE_G@KMIS.KDBMS B ON A.EXP_LIST = B.CODE
AND B.CODE_SEQ = 3
INNER JOIN KMIS.CODE_G@KMIS.KDBMS J ON A.EXP_SECTION = J.CODE
AND J.CODE_SEQ = 1
LEFT OUTER JOIN EKP.MES_USER@EKP.KDBMS C ON A.FIR_EMP_ID = C.USER_ID
LEFT OUTER JOIN EKP.MES_USER@EKP.KDBMS D ON A.SEC_EMP_ID = D.USER_ID
LEFT OUTER JOIN EXPERIMENT K ON A.EXPERIMENT_NO = K.EXPERIMENT_NO
WHERE (A.REQ_NO LIKE '%'||DECODE(#p_expNo#,NULL,A.REQ_NO,#p_expNo#)||'%' OR NVL(A.EXPERIMENT_NO, '0') LIKE '%'||DECODE(#p_expNo#,NULL,NVL(A.EXPERIMENT_NO, '0'),#p_expNo#)||'%')
AND A.EXP_SECTION IN ($p_section$)
AND NVL(A.CANCEL_YN,'N') = #p_cancelYn#
AND A.OPEN_YN IN ($p_customerType$)
AND DECODE(#p_customer#,'PERSON', A.REQ_NAME, 'MAKER', A.MAKER_NAME, 'PAYER', A.PAYER) LIKE '%'||#p_customer_v#||'%'
AND (DECODE(#p_tests#, 'LIST', B.NAME, 'SECTION', J.NAME) LIKE '%'||#p_tests_v#||'%'
AND DECODE(#p_person#,'FRI', NVL(C.NAME,'0'), 'SEC', NVL(D.NAME,'0')) LIKE '%'||#p_person_v#||'%')
) T
WHERE T.TOT_PRICE LIKE '%'||#p_price#||'%'
ORDER BY REQ_NO DESC