Re: PATCH: decreasing memory needlessly consumed by array_agg

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: PATCH: decreasing memory needlessly consumed by array_agg
Date: 2015-02-22 07:05:01
Message-ID: 1424588701.12308.242.camel@jeff-desktop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2015-02-22 07:21:06 Re: Variable renaming in AllocSetContextCreate (will commit soon, no functional impact)
Previous Message Tom Lane 2015-02-22 05:07:17 Re: Variable renaming in AllocSetContextCreate (will commit soon, no functional impact)