#title 집계 후 조인이 안된 사례 다음과 같이 집계 후 조인 시켰다. 처리범위는 두 테이블 모두 약 6백 만 건. {{{ select a.std_dt , a.hh , a.uu , b.up from ( select convert(date, InTime) std_dt , datepart(hh, InTime) hh , count(distinct no) uu from stg.svc.T_GameLogin where 1=1 and InTime >= '20120905' and InTime < convert(char(8), dateadd(dd,1, '20120912'), 112) group by convert(date, InTime) , datepart(hh, InTime) ) a inner join ( select std_dt , datepart(hh, p_end_dt) hh , count(distinct acnt_key) up from ods.moma.play_end where 1=1 and Std_dt between '20120905' and '20120912' group by std_dt , datepart(hh, p_end_dt) ) b on a.std_dt = b.std_dt and a.hh = b.hh }}} 그런데, 븅신같은 SQL Server가 star join처럼 bitmap을 처만들고 있었다. 다음과 같은 실행계획. 실행해보면 언제 끝날지 몰라서 그냥 실행 취소. attachment:집계후조인이안된사례/1.png 그래서 다음과 같이 join hint를 줘서 처음에 의도했던 대로 두 개의 중간결과 집합을 만든 후 merge join 처리하게 끔 유도했다. 약 3초에 처리. {{{ select a.std_dt , a.hh , a.uu , b.up from ( select convert(date, InTime) std_dt , datepart(hh, InTime) hh , count(distinct no) uu from stg.svc.T_GameLogin where 1=1 and InTime >= '20120905' and InTime < convert(char(8), dateadd(dd,1, '20120912'), 112) group by convert(date, InTime) , datepart(hh, InTime) ) a inner merge join ( --여기를 바꿨다. select std_dt , datepart(hh, p_end_dt) hh , count(distinct acnt_key) up from ods.moma.play_end where 1=1 and Std_dt between '20120905' and '20120912' group by std_dt , datepart(hh, p_end_dt) ) b on a.std_dt = b.std_dt and a.hh = b.hh }}} attachment:집계후조인이안된사례/2.png