Re: Count of records in a row - Mailing list pgsql-general

From Rémi Cura
Subject Re: Count of records in a row
Date
Msg-id CAJvUf_vOhvn9y44OVmWEDhfVhBx5N3e2D_WLQkFMZRTat5W-dg@mail.gmail.com
Whole thread Raw
In response to Re: Count of records in a row  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: Count of records in a row
Re: Count of records in a row
List pgsql-general
OK,
just out of pure curiosity,
is it always the case or is it due to this particular aggregate?

Cheers,
Rémi-C


2013/10/22 Merlin Moncure <mmoncure@gmail.com>
On Tue, Oct 22, 2013 at 9:43 AM, Rémi Cura <remi.cura@gmail.com> wrote:
> Thanks again for the precision !
>
> I still don't understand perfectly. We call the aggregate n times, and each
> time we compute the aggregate, using (potentially) n rows, thus becoming (at
> most) O(n*n).
>
> With a standard loop, I loop n times, and each times I only need the current
> row plus the previous row which I put in memory, thus O(n).

For posterity, the above is incorrect.  Since the aggregate is ordered
through the window function, it gets executed exactly once per output
row.  It behaves exactly like a loop.  You know this because there is
no array in the aggregate state.

merlin

pgsql-general by date:

Previous
From: Merlin Moncure
Date:
Subject: Re: Count of records in a row
Next
From: Steve Crawford
Date:
Subject: Re: pg_dumpall from a script