10월, 2018의 게시물 표시

not in, not exists 사용시 쿼리속도가 느릴때

not in, not exists 사용시 쿼리 속도가 느릴때. 특정 항목을 제외 시키기 위해 not in, not exists를 이용합니다. 단건 몇개의 경우 not in으로 처리하고 다건일 경우에는 not exists를 사용합니다. 속도가 너무 느릴경우엔. left join을 이용하여 붙이고 null인 항목을 가져오면 제외된 항목을 가져옵니다. 예) -- not exists 로 조회 explain extended select count ( a . user_id ) as cnt , c . chnl_id , c . use_intt_id from user_ldgr a left join use_intt_per_user c on a . user_id = c . user_id where a . ATHZ_DT < '20160101' and not exists ( select b . user_id from lgn_prhs b where b . lgn_dt between '20150101' and '20151231' and b . user_id = a . user_id group by b . user_id ) group by chnl_id ; -- left join 로 조회 explain select count ( a . user_id ) as cnt , c . chnl_id , c . use_intt_id from user_ldgr a left join use_intt_per_user c on a . user_id = c . user_id left join ( select b . user_id from lgn_prhs b where b . lgn_dt between '20150101' and