안녕하세요
쿼리 튜닝을 하다가 좋은 방법이 떠오르지 않아서요
일단 테이블들은 100만건 이상의 레코드라고 생각하시면 됩니다.
쿼리는 해당 승인(DEAL_GB='1')만 존재하는 경우만을 출력하는 쿼리로서
승인취소((DEAL_GB='2')인 승인번호(apvl_no)를 MINUS 연산으로 제외한 경우입니다.
--------------------------------------
(SELECT
A.APVL_YMD AS DEAL_DT,
A.SEUNGIN_SIGAN AS DEAL_TM,
CONCAT(A.APVL_YMD,A.SEUNGIN_SIGAN) AS APVL_YMDT,
A.APVL_NO AS APVL_NO,
FN_SECURE_CARDNO(A.CARD_NO) AS CARD_NO_S,
A.DEAL_YYMM AS DEAL_YYMM,
A.LOCAL_CD AS LOCAL_CD,
FN_LOCAL_NM(A.LOCAL_CD,'Y') AS LOCAL_NM,
A.BID AS BID,
REPLACE(B.COMP_NM,' ','') AS COMP_NM,
A.CAR_NO AS CAR_NO,
A.CAR_DIV_CD AS CAR_DIV_CD,
A.OIL_DIV_CD AS OIL_DIV_CD,
A.DEAL_TYP_CD AS DEAL_TYP_CD,
A.SELF_TYP_CD AS SELF_TYP_CD,
A.CHAIN_NM AS CHAIN_NM,
A.STORE_SAEOP_NO AS STORE_SAEOP_NO,
A.APVL_AMT AS APVL_AMT,
TO_CHAR(A.RITEO) AS RITEO,
A.SUBSIDY_MNY AS SUBSIDY_MNY,
A.REQ_CONFIRM_YN AS REQ_CONFIRM_YN,
A.DEAL_GB AS DEAL_GB,
A.END_DT AS END_DT,
A.END_LOCAL_CD AS END_LOCAL_CD,
FN_LOCAL_NM(A.END_LOCAL_CD,'Y') AS END_LOCAL_NM,
'' AS INPUT_ID,
'' AS INPUT_DT,
'' AS UPDATE_ID,
'' AS UPDATE_DT
FROM T_BS_DEAL A
LEFT OUTER JOIN T_BS_BIZ_M B ON A.BID = B.BID
LEFT OUTER JOIN T_BS_CAR_M C ON A.BID = C.BID
AND A.CAR_NO = C.CAR_NO
WHERE A.BID = 'xxxxx'
AND A.DEAL_YYMM = '201301'
AND A.LOCAL_CD = 'xxxxx'
AND A.DEAL_GB = '1'
)
MINUS
(
SELECT
A.APVL_YMD AS DEAL_DT,
A.SEUNGIN_SIGAN AS DEAL_TM,
CONCAT(A.APVL_YMD,A.SEUNGIN_SIGAN) AS APVL_YMDT,
A.APVL_NO AS APVL_NO,
FN_SECURE_CARDNO(A.CARD_NO) AS CARD_NO_S,
A.DEAL_YYMM AS DEAL_YYMM,
A.LOCAL_CD AS LOCAL_CD,
FN_LOCAL_NM(A.LOCAL_CD,'Y') AS LOCAL_NM,
A.BID AS BID,
REPLACE(B.COMP_NM,' ','') AS COMP_NM,
A.CAR_NO AS CAR_NO,
A.CAR_DIV_CD AS CAR_DIV_CD,
A.OIL_DIV_CD AS OIL_DIV_CD,
A.DEAL_TYP_CD AS DEAL_TYP_CD,
A.SELF_TYP_CD AS SELF_TYP_CD,
A.CHAIN_NM AS CHAIN_NM,
A.STORE_SAEOP_NO AS STORE_SAEOP_NO,
A.APVL_AMT AS APVL_AMT,
TO_CHAR(A.RITEO) AS RITEO,
A.SUBSIDY_MNY AS SUBSIDY_MNY,
A.REQ_CONFIRM_YN AS REQ_CONFIRM_YN,
'1' AS DEAL_GB,
A.END_DT AS END_DT,
A.END_LOCAL_CD AS END_LOCAL_CD,
FN_LOCAL_NM(A.END_LOCAL_CD,'Y') AS END_LOCAL_NM,
'' AS INPUT_ID,
'' AS INPUT_DT,
'' AS UPDATE_ID,
'' AS UPDATE_DT
FROM T_BS_DEAL A
LEFT OUTER JOIN T_BS_BIZ_M B ON A.BID = B.BID
LEFT OUTER JOIN T_BS_CAR_M C ON A.BID = C.BID
AND A.CAR_NO = C.CAR_NO
WHERE A.BID = 'xxxxx'
AND A.DEAL_YYMM = '201301'
AND A.LOCAL_CD = 'xxxxx'
AND A.DEAL_GB = '2'
)
ORDER BY DEAL_DT, DEAL_TM
결과셋이 작을 경우는 문제가 없었는데 테이블이 100만건이상이 되면서 쿼리시간이 점차 길어지는 현상이 발생하였습니다.
마이너스 연산을 대신하여 left outer 조인으로 바꾸기는 하였지만
하나의 테이블에서 조인없이 같은 결과를 낼수 있는 방법이 있을까요?