[HACKERS] Strange query plan with redundant aggregate nodes

2009-04-09 Thread Gregory Stark
This query surprised me. I expected us to do the Aggregate once for all the aggregate functions in the select target which is what normally happens. If I simplify the query further it actually does so. I don't really understand what's going on here. It can't be the volatile random() because in

Re: [HACKERS] Strange query plan with redundant aggregate nodes

2009-04-09 Thread Tom Lane
Gregory Stark st...@enterprisedb.com writes: I don't really understand what's going on here. It's flattening the sub-select, converting select sum(n),sum(n) from (select (select count(*) as n from a ) as n from (select random() as s) as xyzzy) as xyzzy ; to select sum((select