select

name,

count(distinct ip) visitcount

from member

group by name

위와 같은 query에서 group by와 distinct가 동시에 일어난다.

이렇게 썼을 때 32초 걸리던 query가 27초 걸리도록 줄일 수 있었다.

(DB에서 1초를 넘어 섰다는 건 이미 문제가 있는 거지만 통계 페이지라 일단 통과)

select

name,

count(*) visitcount

from (

select distinct

name,

ip

from member

) a

group by name

distinct를 먼저 한 후에 group by를 했을 때 약간 더 빨랐다.

15~6% 정도...

mssql에서 index 다 태운 상황이었다. (최소한 분석기에서 index 없다는 얘기는 없을 정도)

2011/11/19 11:39 2011/11/19 11:39

Trackback Address :: https://youngsam.net/trackback/1652