-
[완료]/*VoteRelation.base.selectAlbumList*/Postgresql / PPAS/Query tuning 2022. 8. 29. 14:27
AS-IS
20 sec
TO-BE
17 ms
개선 효과 : 99.91%* 원본 쿼리
SELECT /*VoteRelation.base.selectAlbumList*/
A.TOTAL_CNT
, A.RNUM
, A.ALBUM_ID
, A.ALBUM_NAME
, TO_CHAR(TO_TIMESTAMP(A.ALBUM_DATE, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD') ALBUM_DATE
FROM (
SELECT /*+ LEADING(AI) INDEX(AI PK_PT_LA_ALBUM_INFO) USE_NL(AI S)*/
AI.ALBUM_ID
, AI.ALBUM_NAME
, AI.ALBUM_DATE
, COUNT(AI.ALBUM_ID) OVER() AS TOTAL_CNT
, ROW_NUMBER() OVER (ORDER BY AI.ALBUM_ID ASC) AS RNUM
FROM imcsuser.PT_LA_ALBUM_INFO AI
, imcsuser.PT_LA_ALBUM_SUB S
WHERE AI.ALBUM_ID = S.ALBUM_ID
AND AI.ALBUM_ID LIKE 'M%'
AND AI.ALBUM_ID NOT IN (SELECT ALBUM_ID FROM imcsuser.PT_LB_CUESHEET_MST WHERE NULLIF(ALBUM_ID,'') IS NOT NULL
UNION ALL
SELECT ALBUM_ID FROM imcsuser.PT_LB_CUESHEET_ITEM WHERE NULLIF(ALBUM_ID,'') IS NOT NULL
UNION ALL
SELECT ALBUM_ID FROM imcsuser.PT_LB_CUESHEET_ITEM_DETAIL WHERE NULLIF(ALBUM_ID,'') IS NOT NULL)
AND AI.VOD_TYPE IN ('M', 'O')
AND S.MUSIC_CONT_TYPE IN ('B', 'C', 'D', 'T')
AND AI.ALBUM_ID NOT IN (SELECT ALBUM_ID FROM imcsuser.PT_LA_ALBUM_RELATION WHERE GROUP_TYPE = 'V' AND ALBUM_GROUP_ID = '304')
AND AI.ALBUM_DATE >= '20220811000000'
AND AI.ALBUM_DATE <= '20220818235959'
) A
WHERE A.RNUM BETWEEN 0 + 1 AND 0 + 10* 튜닝 쿼리 ( AND AI.ALBUM_ID NOT IN 부분을 EXISTS로 변경하고 UNION 부분의 Data 건수를 줄임 )
SELECT /*VoteRelation.base.selectAlbumList*/
A.TOTAL_CNT
, A.RNUM
, A.ALBUM_ID
, A.ALBUM_NAME
, TO_CHAR(TO_TIMESTAMP(A.ALBUM_DATE, 'YYYYMMDDHH24MISS'), 'YYYY-MM-DD') ALBUM_DATE
FROM (
SELECT /*+ LEADING(AI) INDEX(AI PK_PT_LA_ALBUM_INFO) USE_NL(AI S)*/
AI.ALBUM_ID
, AI.ALBUM_NAME
, AI.ALBUM_DATE
, COUNT(AI.ALBUM_ID) OVER() AS TOTAL_CNT
, ROW_NUMBER() OVER (ORDER BY AI.ALBUM_ID ASC) AS RNUM
FROM imcsuser.PT_LA_ALBUM_INFO AI
, imcsuser.PT_LA_ALBUM_SUB S
WHERE AI.ALBUM_ID = S.ALBUM_ID
AND AI.ALBUM_ID LIKE 'M%'
AND exists (SELECT 1 FROM imcsuser.PT_LB_CUESHEET_MST WHERE NULLIF(ALBUM_ID,'') IS NOT null and ALBUM_ID <> AI.ALBUM_ID
UNION ALL
SELECT 1 FROM imcsuser.PT_LB_CUESHEET_ITEM WHERE NULLIF(ALBUM_ID,'') IS NOT null and ALBUM_ID <> AI.ALBUM_ID
UNION ALL
SELECT 1 FROM imcsuser.PT_LB_CUESHEET_ITEM_DETAIL WHERE NULLIF(ALBUM_ID,'') IS NOT null and ALBUM_ID <> AI.ALBUM_ID)
AND AI.VOD_TYPE IN ('M', 'O')
AND S.MUSIC_CONT_TYPE IN ('B', 'C', 'D', 'T')
AND AI.ALBUM_ID NOT IN (SELECT ALBUM_ID FROM imcsuser.PT_LA_ALBUM_RELATION WHERE GROUP_TYPE = 'V' AND ALBUM_GROUP_ID = '304')
AND AI.ALBUM_DATE >= '20220811000000'
AND AI.ALBUM_DATE <= '20220818235959'
) A
WHERE A.RNUM BETWEEN 0 + 1 AND 0 + 10'Postgresql / PPAS > Query tuning' 카테고리의 다른 글
[완료] /*modifySchedule.base.selectContentList */ (0) 2022.08.29 [완료] /* index.base.getNewRegIndexAlbumList */ (0) 2022.08.29 [완료]/*contentExpand.distr.selectExposureNewScheduleList*/ (0) 2022.08.29 [완료]/*album.base.deleteMultiSeriesCategoryMap*/ (0) 2022.08.29 [완료]/* categoryForm.base.getAlbumNameSearchList */ (0) 2022.08.29