다음은 group by clause 문제가있는 계획을 설명하는 것과 관련된 세부 설명입니다.postgresql에서 group by 절을 사용한 계획 문제 8.4
표 : 871 개
인덱스 : "web_categoryutfv1_24hr_ts_201209_idx"BTREE ("5mintime")
내가 실행하고 다음 바이트,
행을 APPID, 안타, 카테고리를 "5mintime"
열을 web_categoryutfv1_24hr_ts_201209 검색어 :
select count(*) over() as t_totalcnt,
max(hits) over() as t_maxhits,
max(bytes) over() as t_maxbytes,
*
from (
select category,
sum(hits) as hits,
sum(bytes) as bytes
from (
select "5mintime",
category,
hits,
bytes,
appid,
0 as tmpfield
from web_categoryutfv1_24hr_ts_201209
where "5mintime" >= '2012-09-12 00:00:00'
and "5mintime" < '2012-09-19 00:00:00'
) as tmp
where "5mintime" >= '2012-09-12 00:00:00'
and "5mintime" <= '2012-09-18 23:59:59'
and appid in ('')
group by category
order by hits desc
) as foo limit 10
총 행 반환 값은 t_totalcnt 변수에서 55입니다. 지금은 web_categoryutfv1_24hr_ts_201209
테이블을 분석하고
설명 다시 같은 쿼리를 실행 내가 얻을 다음 실행 계획 : 이제
-> Limit (cost=31.31..31.61 rows=10 width=580) -> WindowAgg (cost=31.31..32.03 rows=24 width=580) -> Subquery Scan foo (cost=31.31..31.61 ***rows=24*** width=580) -> Sort (cost=31.31..31.37 rows=24 width=31) Sort Key: (sum(web_categoryutfv1_24hr_ts_201209.hits)) -> HashAggregate (cost=30.39..30.75 rows=24 width=31) -> Seq Scan on web_categoryutfv1_24hr_ts_201209 (cost=0.00..27.60 rows=373 width=31) Filter: (("5mintime" >= '2012-09-12 00:00:00'::timestamp without time zone) AND ("5mintime" < '2012-09-19 00:00:00'::timestamp without time zone) AND ("5mintime" >= '2012-09-12 00:00:00'::timestamp without time zone) AND ("5mintime" <= '2012-09-18 23:59:59'::timestamp without time zone) AND ((appid)::text = ''::text))
내가 계획 넣어 HashAggregate (비용을 설명 얻었다 = 30.39..30.75 행 = 24 너비 = 31) rows = 24라고 말하면서 실제로 총 행 반환 값은 55가되어야합니다. 쿼리에서 group by 절을 제거하면 acutal 쿼리 실행뿐만 아니라 explain plan 출력에서도 373 개의 행이 있습니다.
그래서 내가 쿼리에서 설명 계획 및 그룹 by 절과 관련된 문제가 있는지 알고 싶습니까?