On Sun, 2015-02-22 at 03:14 +0100, Tomas Vondra wrote:
> >> SELECT COUNT(x) FROM (
> >> SELECT a, array_agg(i) AS x FRM test GROUP BY 1
> >> ) foo;
> >
> > That's actually a bogus test -- array_agg is never executed.
>
> Really? How could that happen when the result of array_agg() is passed
> to the COUNT()? Also, how could that allocate huge amounts of memory and
> get killed by OOM, which happens easily with this query?
Oops, I misread that as "COUNT(*)". Count(x) will force array_agg() to
be executed.
Regards,Jeff Davis