下面给出了详细的解释,这与用分组问题的解释计划有关。
表:web_categoryutfv1_24hr_ts_201209
列:“5mintime”,类别,命中,字节,appid
行:871
索引:“web_categoryutfv1_24hr_ts_201209_idx”btree(“5mintime”)
我正在运行以下查询:
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
了表并再次使用说明运行相同的查询
我得到以下执行计划:
-> 限制(成本=31.31..31.61 行=10 宽度=580) -> WindowAgg(成本=31.31..32.03行=24宽度=580) -> 子查询扫描 foo (cost=31.31..31.61 ***rows=24*** width=580) -> 排序(成本=31.31..31.37行=24宽度=31) 排序键:(sum(web_categoryutfv1_24hr_ts_201209.hits)) -> HashAggregate(成本=30.39..30.75行=24宽度=31) -> web_categoryutfv1_24hr_ts_201209 上的 Seq 扫描(成本=0.00..27.60 行=373 宽度=31) 过滤器: (("5mintime" >= '2012-09-12 00:00:00'::timestamp without time zone) AND ("5mintime" < '2012-09-19 00:00:00'::timestamp without时区) AND ("5mintime" >= '2012-09-12 00:00:00'::timestamp without time zone) AND ("5mintime" <= '2012-09-18 23:59:59'::没有时区的时间戳) AND ((appid)::text = ''::text))
现在我得到了解释计划输出 HashAggregate (cost=30.39..30.75 rows=24 width=31) 它说 rows=24 而实际上总行返回应该是 55。当我从查询中删除 group by 子句时,我得到了 373 行解释计划输出以及实际查询执行。
所以我想知道查询中的解释计划和分组子句是否存在问题?