_대문 | 방명록 | 최근글 | 홈피소개 | 주인놈
FrontPage › 집계후조인이안된사례

다음과 같이 집계 후 조인 시켰다. 처리범위는 두 테이블 모두 약 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을 처만들고 있었다. 다음과 같은 실행계획. 실행해보면 언제 날지 몰라서 그냥 실행 취소.
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

2.png
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:54

우리 시대에 가장 암울한 말이 있다면 "남 하는 대로" "나 하나쯤이야" "세상이 그런데". 우리 시대에 남은 희망이 있다면 "나 하나만이라도" "내가 있음으로 " "내가 먼저". (박노해)