-
[완료]/*distribute.distr.distributeListStatusPageData*/Postgresql / PPAS/Query tuning 2022. 8. 29. 13:33
AS-IS
실행 완료. 총 쿼리 실행시간: 12 secs 226 msec.TO-BE
실행 완료. 총 쿼리 실행시간: 3 secs 774 msec.
개선효과 : 약 75% 개선* 튜닝 쿼리
SELECT * /*distribute.distr.distributeListStatusPageData*/
FROM ( SELECT COUNT(AA.ALBUM_ID) OVER() AS TOTAL_CNT,
ROW_NUMBER() OVER (ORDER BY AA.ALBUM_ID, AA.ASSET_SN, AA.ASSET_TYPE) AS RNUM,
AA.ALBUM_ID,
AA.ASSET_TYPE,
AA.ASSET_SN,
AA.ASSET_ID,
AA.MAT_NAME,
AA.GENRE_LARGE,
AA.GENRE_MID,
AA.GENRE_SMALL,
AA.CP_CON_CD,
AA.VIDEO_SIZE,
AA.IMP_DATE,
AA.RE_IMP_YN,
AA.ASSET_GB,
AA.TRANS_MODE,
AA.TCODING_YN,
AA.PRE_ENCRYPT_YN,
TO_CHAR(TO_TIMESTAMP(AA.ENCRYPT_START_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') ENCRYPT_START_TIME,
TO_CHAR(TO_TIMESTAMP(AA.ENCRYPT_END_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') ENCRYPT_END_TIME,
TO_TIMESTAMP(AA.ENCRYPT_END_TIME, 'YYYYMMDDHH24MISS') - TO_TIMESTAMP(AA.ENCRYPT_START_TIME, 'YYYYMMDDHH24MISS') AS ENCRYPT_TERM,
AA.INDEXING_YN,
TO_CHAR(TO_TIMESTAMP(AA.DISTR_DATE, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') DISTR_DATE,
AA.C_TR_YN ,
AA.C_W_NODE_CNT,
AA.C_E_NODE_CNT,
AA.C_D_NODE_CNT,
AA.C_R_NODE_CNT,
AA.C_P_NODE_CNT,
AA.Z_TR_YN ,
AA.Z_P_NODE_CNT,
AA.Z_W_NODE_CNT,
AA.Z_E_NODE_CNT,
AA.Z_D_NODE_CNT,
AA.Z_R_NODE_CNT,
AA.RETURN_DATE,
AA.DX_TYPE,
AA.SRC_FILE_NM,
AA.PROPAGATION_PRIORITY,
AA.ADI_PRODUCT_ID,
AA.CREATE_DATE,
CASE
WHEN AA.ENC_PROPAGATION_PRIORITY = '1' THEN 'Emergency'
WHEN AA.ENC_PROPAGATION_PRIORITY = '2' THEN 'High'
WHEN AA.ENC_PROPAGATION_PRIORITY = '3' THEN 'Normal'
WHEN AA.ENC_PROPAGATION_PRIORITY = '4' THEN 'Low'
ELSE 'Low'
END AS ENC_PROPAGATION_PRIORITY,
CASE
WHEN AA.IDX_PROPAGATION_PRIORITY = '1' THEN 'Emergency'
WHEN AA.IDX_PROPAGATION_PRIORITY = '2' THEN 'High'
WHEN AA.IDX_PROPAGATION_PRIORITY = '3' THEN 'Normal'
WHEN AA.IDX_PROPAGATION_PRIORITY = '4' THEN 'Low'
ELSE 'Low'
END AS IDX_PROPAGATION_PRIORITY,
CASE
WHEN AA.Z_PROPAGATION_PRIORITY = '1' THEN 'Emergency'
WHEN AA.Z_PROPAGATION_PRIORITY = '2' THEN 'High'
WHEN AA.Z_PROPAGATION_PRIORITY = '3' THEN 'Normal'
WHEN AA.Z_PROPAGATION_PRIORITY = '4' THEN 'Low'
ELSE 'Low'
END AS Z_PROPAGATION_PRIORITY,
CASE
WHEN AA.C_PROPAGATION_PRIORITY = '1' THEN 'Emergency'
WHEN AA.C_PROPAGATION_PRIORITY = '2' THEN 'High'
WHEN AA.C_PROPAGATION_PRIORITY = '3' THEN 'Normal'
WHEN AA.C_PROPAGATION_PRIORITY = '4' THEN 'Low'
ELSE 'Low'
END AS C_PROPAGATION_PRIORITY,
CASE
WHEN AA.Z_IDX_PROPAGATION_PRIORITY = '1' THEN 'Emergency'
WHEN AA.Z_IDX_PROPAGATION_PRIORITY = '2' THEN 'High'
WHEN AA.Z_IDX_PROPAGATION_PRIORITY = '3' THEN 'Normal'
WHEN AA.Z_IDX_PROPAGATION_PRIORITY = '4' THEN 'Low'
ELSE 'Low'
END AS Z_IDX_PROPAGATION_PRIORITY,
AA.Z_INDEXING_YN,
TO_CHAR(TO_TIMESTAMP(AA.C_INDEXING_START_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') C_INDEXING_START_TIME,
TO_CHAR(TO_TIMESTAMP(AA.C_INDEXING_END_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') C_INDEXING_END_TIME,
TO_TIMESTAMP(AA.C_INDEXING_END_TIME, 'YYYYMMDDHH24MISS') - TO_TIMESTAMP(AA.C_INDEXING_START_TIME, 'YYYYMMDDHH24MISS') AS C_INDEXING_TERM,
TO_CHAR(TO_TIMESTAMP(AA.Z_INDEXING_START_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') Z_INDEXING_START_TIME,
TO_CHAR(TO_TIMESTAMP(AA.Z_INDEXING_END_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') Z_INDEXING_END_TIME,
TO_TIMESTAMP(AA.Z_INDEXING_END_TIME, 'YYYYMMDDHH24MISS') - TO_TIMESTAMP(AA.Z_INDEXING_START_TIME, 'YYYYMMDDHH24MISS') AS Z_INDEXING_TERM,
TO_CHAR(TO_TIMESTAMP(AA.C_SEND_START_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') C_SEND_START_TIME,
TO_CHAR(TO_TIMESTAMP(AA.C_SEND_END_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') C_SEND_END_TIME,
TO_TIMESTAMP(AA.C_SEND_END_TIME, 'YYYYMMDDHH24MISS') - TO_TIMESTAMP(AA.C_SEND_START_TIME, 'YYYYMMDDHH24MISS') AS C_SEND_STERM,
TO_CHAR(TO_TIMESTAMP(AA.Z_SEND_START_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') Z_SEND_START_TIME,
TO_CHAR(TO_TIMESTAMP(AA.Z_SEND_END_TIME, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') Z_SEND_END_TIME,
TO_TIMESTAMP(AA.Z_SEND_END_TIME, 'YYYYMMDDHH24MISS') - TO_TIMESTAMP(AA.Z_SEND_START_TIME, 'YYYYMMDDHH24MISS') AS Z_SEND_STERM,
CASE
WHEN AA.QUICK_DISTRIBUTION_YN = 'Y' THEN 'Quick'
WHEN AA.QUICK_DISTRIBUTION_YN = 'N' THEN 'Normal'
ELSE 'Normal'
END AS QUICK_DISTRIBUTION_YN,
CASE
WHEN AA.PRE_MAPPING_YN = 'Y' THEN '사전편성'
WHEN AA.PRE_MAPPING_YN = 'N' THEN '일반편성'
ELSE '일반편성'
END AS PRE_MAPPING_YN,
AA.C_AGENT_GB,
AA.Z_AGENT_GB,
AA.SERVICE_ID,
ROUND(AA.CONTENT_FILESIZE / 1024 ) AS CONTENT_FILESIZE
FROM ( SELECT SUBSTR(A.ASSET_ID, 1, 15) AS ALBUM_ID,
SUBSTR(A.ASSET_ID, 16, 2) AS ASSET_TYPE,
CASE
WHEN SUBSTR(A.ASSET_ID, 16, 2) = 'HD' THEN '1'
WHEN SUBSTR(A.ASSET_ID, 16, 2) = 'SH' THEN '1'
WHEN SUBSTR(A.ASSET_ID, 16, 2) = 'SD' THEN '1'
WHEN SUBSTR(A.ASSET_ID, 16, 2) = 'U1' THEN '1'
WHEN SUBSTR(A.ASSET_ID, 16, 2) = 'U2' THEN '1'
WHEN SUBSTR(A.ASSET_ID, 16, 2) = 'U3' THEN '1'
ELSE '2'
END AS ASSET_SN,
A.ASSET_ID,
A.MAT_NAME,
AI.GENRE_LARGE,
AI.GENRE_MID,
AI.GENRE_SMALL,
B.CON_CD AS CP_CON_CD,
A.VIDEO_SIZE,
TO_CHAR(TO_TIMESTAMP(IMP_DATE, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD HH24:MI:SS') IMP_DATE,
A.RE_IMP_YN,
B.ASSET_GB,
CASE WHEN B.DISTRIBUTOR_NAME = 'E' THEN '긴급' ELSE '일반' END AS TRANS_MODE,
COALESCE(NULLIF(A.TCODING_YN,''), 'N') AS TCODING_YN,
COALESCE(NULLIF(A.PRE_ENCRYPT_YN,''), 'N') AS PRE_ENCRYPT_YN,
F.ENCRYPT_START_TIME,
F.ENCRYPT_END_TIME,
COALESCE(NULLIF(A.INDEXING_YN,''), 'N') AS INDEXING_YN,
D.DISTR_DATE DISTR_DATE,
CASE B.ASSET_GB
WHEN '0' THEN A.NVOD_TRANS_YN
WHEN '2' THEN A.NVOD_TRANS_YN
ELSE TO_CHAR(COALESCE(D.C_F_NODE_CNT, 0))
END C_TR_YN,
COALESCE(D.C_W_NODE_CNT, 0) C_W_NODE_CNT,
COALESCE(D.C_E_NODE_CNT, 0) C_E_NODE_CNT,
COALESCE(D.C_D_NODE_CNT, 0) C_D_NODE_CNT,
COALESCE(D.C_R_NODE_CNT, 0) C_R_NODE_CNT,
COALESCE(D.C_P_NODE_CNT, 0) C_P_NODE_CNT,
CASE B.ASSET_GB
WHEN '0' THEN A.NVOD_TRANS_YN
WHEN '2' THEN A.NVOD_TRANS_YN
ELSE TO_CHAR(COALESCE(D.Z_F_NODE_CNT, 0))
END Z_TR_YN,
COALESCE(D.Z_P_NODE_CNT, 0) Z_P_NODE_CNT,
COALESCE(D.Z_W_NODE_CNT, 0) Z_W_NODE_CNT,
COALESCE(D.Z_E_NODE_CNT, 0) Z_E_NODE_CNT,
COALESCE(D.Z_D_NODE_CNT, 0) Z_D_NODE_CNT,
COALESCE(D.Z_R_NODE_CNT, 0) Z_R_NODE_CNT,
D.RETURN_DATE RETURN_DATE,
CASE B.CATEGORY WHEN 'D' THEN '양방향' WHEN 'U' THEN 'UCC' ELSE ' ' END DX_TYPE,
B.SERIES_NAME AS SRC_FILE_NM,
B.PROPAGATION_PRIORITY,
B.ADI_PRODUCT_ID AS ADI_PRODUCT_ID,
B.CREATE_DATE AS CREATE_DATE,
F.PROPAGATION_PRIORITY AS ENC_PROPAGATION_PRIORITY,
G.PROPAGATION_PRIORITY AS IDX_PROPAGATION_PRIORITY,
I.PROPAGATION_PRIORITY AS Z_PROPAGATION_PRIORITY,
J.PROPAGATION_PRIORITY AS C_PROPAGATION_PRIORITY,
K.PROPAGATION_PRIORITY AS Z_IDX_PROPAGATION_PRIORITY,
COALESCE(NULLIF(A.ZINDEXING_YN,''), 'N') AS Z_INDEXING_YN,
G.INDEXING_START_TIME AS C_INDEXING_START_TIME,
G.INDEXING_END_TIME AS C_INDEXING_END_TIME,
K.INDEXING_START_TIME AS Z_INDEXING_START_TIME,
K.INDEXING_END_TIME AS Z_INDEXING_END_TIME,
I.SEND_START_TIME AS Z_SEND_START_TIME,
I.SEND_END_TIME AS Z_SEND_END_TIME,
J.SEND_START_TIME AS C_SEND_START_TIME,
J.SEND_END_TIME AS C_SEND_END_TIME,
COALESCE(NULLIF(B.QUICK_DISTRIBUTION_YN,''), 'N') QUICK_DISTRIBUTION_YN,
COALESCE(NULLIF(B.PRE_MAPPING_YN,''), 'N') PRE_MAPPING_YN,
G.AGENT_GB AS C_AGENT_GB,
K.AGENT_GB AS Z_AGENT_GB,
B.CONTENT_FILESIZE AS CONTENT_FILESIZE,
B.SERVICE_ID AS SERVICE_ID
FROM rsimcsuser.PT_LB_BRO_MATERIAL A
INNER JOIN imcsuser.PT_LA_ASSET_INFO B ON (SUBSTR(A.ASSET_ID, 1, 18) = B.ADI_PRODUCT_ID)
LEFT JOIN (SELECT T.ASSET_ID,
MAX(T.DISTR_DATE) DISTR_DATE,
MAX(RETURN_DATE) RETURN_DATE,
SUM(CASE WHEN T.CONTENT_STAT = 'Y' AND I.CDN_LOCAL_TYP IN ('1', '3') THEN 1 ELSE 0 END) AS C_F_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT = 'W' AND I.CDN_LOCAL_TYP IN ('1', '3') THEN 1 ELSE 0 END) AS C_W_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT = 'R' AND I.CDN_LOCAL_TYP IN ('1', '3') THEN 1 ELSE 0 END) AS C_P_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT NOT IN ('Y', 'R', 'D', 'W') AND I.CDN_LOCAL_TYP IN ('1', '3') THEN 1 ELSE 0 END) AS C_E_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT = 'D' AND I.CDN_LOCAL_TYP IN ('1', '3') THEN 1 ELSE 0 END) AS C_D_NODE_CNT,
SUM(CASE WHEN COALESCE(NULLIF(T.RETURN_YN,''), 'N') = 'Y' AND I.CDN_LOCAL_TYP IN ('1', '3') THEN 1 ELSE 0 END) AS C_R_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT = 'Y' AND I.CDN_LOCAL_TYP = '2' THEN 1 ELSE 0 END) AS Z_F_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT = 'W' AND I.CDN_LOCAL_TYP = '2' THEN 1 ELSE 0 END) AS Z_W_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT = 'R' AND I.CDN_LOCAL_TYP = '2' THEN 1 ELSE 0 END) AS Z_P_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT NOT IN ('Y', 'R', 'D', 'W') AND I.CDN_LOCAL_TYP = '2' THEN 1 ELSE 0 END) AS Z_E_NODE_CNT,
SUM(CASE WHEN T.CONTENT_STAT = 'D' AND I.CDN_LOCAL_TYP = '2' THEN 1 ELSE 0 END) AS Z_D_NODE_CNT,
SUM(CASE WHEN COALESCE(NULLIF(T.RETURN_YN,''), 'N') = 'Y' AND I.CDN_LOCAL_TYP = '2' THEN 1 ELSE 0 END) AS Z_R_NODE_CNT
FROM imcsuser.PT_LV_NODE_CONT_STAT T
, rsimcsuser.PT_LV_NODE_INFO I
WHERE T.SUB_NODE_CD = I.SUB_NODE_CD
AND T.DISTR_DATE BETWEEN '20220727000000' AND TO_CHAR(TO_TIMESTAMP('20220727235959', 'YYYYMMDDHH24MISS') + '1 day'::interval, 'YYYYMMDDHH24MISS')
GROUP BY T.ASSET_ID
) D ON (A.ASSET_ID = D.ASSET_ID)
LEFT JOIN (SELECT ASSET_ID,
ENCRYPT_START_TIME,
ENCRYPT_END_TIME,
PROPAGATION_PRIORITY
FROM imcsuser.PT_LV_ENC_LIST
WHERE ENCRYPT_START_TIME >= '20220727000000'
) F ON (A.ASSET_ID = F.ASSET_ID)
LEFT JOIN imcsuser.PT_LV_IDX_LIST G ON (A.ASSET_ID = G.ASSET_ID)
LEFT JOIN (SELECT DISTINCT(ASSET_ID) ASSET_ID,
MAX(PROPAGATION_PRIORITY) PROPAGATION_PRIORITY,
MAX(SEND_DATE) SEND_DATE,
MAX(SEND_START_TIME) SEND_START_TIME,
MAX(SEND_END_TIME) SEND_END_TIME
FROM imcsuser.PT_LV_NPLY_LIST
WHERE SEND_DATE >= TO_DATE(SUBSTR('20220727000000', 1, 8), 'YYYYMMDD')
GROUP BY ASSET_ID
) I ON (A.ASSET_ID = I.ASSET_ID)
LEFT JOIN (SELECT DISTINCT(ASSET_ID) ASSET_ID,
MAX(PROPAGATION_PRIORITY) PROPAGATION_PRIORITY,
MAX(SEND_DATE) SEND_DATE,
MAX(SEND_START_TIME) SEND_START_TIME,
MAX(SEND_END_TIME) SEND_END_TIME
FROM imcsuser.PT_LV_PLY_LIST
WHERE SEND_DATE >= TO_DATE(SUBSTR('20220727000000', 1, 8), 'YYYYMMDD')
GROUP BY ASSET_ID
) J ON (A.ASSET_ID = J.ASSET_ID)
LEFT JOIN imcsuser.PT_LV_ZIDX_LIST K ON (A.ASSET_ID = K.ASSET_ID and A.house_number = K.house_number)
// 기존 원본 쿼리에서 alias table 의 A / K join 시 house_number 로 key 조건을 추가 ( 데이터 확인 완료 )
LEFT JOIN imcsuser.PT_LW_ALBUM_INFO AI ON (SUBSTR(A.ASSET_ID, 1, 15) = AI.ALBUM_ID)
WHERE A.IMP_DATE BETWEEN '20220727000000' AND '20220727235959'
)AA
) T
WHERE RNUM BETWEEN 0 + 1 AND 0 + 10000000
ORDER BY ALBUM_ID, ASSET_SN, ASSET_TYPE'Postgresql / PPAS > Query tuning' 카테고리의 다른 글
[완료]/*album.base.deleteMultiSeriesCategoryMap*/ (0) 2022.08.29 [완료]/* categoryForm.base.getAlbumNameSearchList */ (0) 2022.08.29 [ 완료]/*new4dSchedule.distr.new4dScheduleListPageData*/ (0) 2022.08.29 [완료]/*abtest.categoryForm.base.getAlbumNameInSeriesAlbum*/ (0) 2022.08.29 [완료]/* cuesheet.base.getCueSheetItemDetailForLayer */ (0) 2022.08.29