Re: Idea: PostgreSQL equivalent to Oracle's KEEP clause - Mailing list pgsql-general

From David Rowley
Subject Re: Idea: PostgreSQL equivalent to Oracle's KEEP clause
Date
Msg-id CAApHDvp9Qg=8awydCwdhrKDjdn9sKv7NBupuayUwjTRxcLgb0A@mail.gmail.com
Whole thread Raw
In response to Re: Idea: PostgreSQL equivalent to Oracle's KEEP clause  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-general
On Tue, 7 Mar 2023 at 16:11, David G. Johnston
<david.g.johnston@gmail.com> wrote:
>
> On Mon, Mar 6, 2023 at 7:51 PM David Rowley <dgrowleyml@gmail.com> wrote:
>> the transfn for bottom() would need to remember the city and the
>> population for the highest yet seen value of the 2nd arg.
>
>
> BOTTOM() remembers the highest value?

I was thinking in terms of a window with all values sorted in
ascending order. Maybe your mental modal differs from mine.  If Ben
wants to implement some new aggregate functions in an extension, then
he might think of better names.

> SELECT country, city,
>   rank() over (partition by country order by population desc),
>   count() OVER (partition by country)
> FROM cities
> WINDOW_HAVING count > 0 AND rank = 1;
>
> That would be, IMO, the idiomatic query form to perform ranking - not abusing GROUP BY.  To add this encourages
abusingGROUP BY. 
>
> Though I suppose if there is a sufficient performance gain to be had under GROUP BY the effort might make sense if
furtherimprovements to window function processing cannot be found. 

Ideally, we'd be able to just sort the top-1 value and not the entire
window by population desc.  Maybe SupportRequestWFuncMonotonic could
be extended to instruct WindowAgg to do that for certain functions.
Greg was talking about something like this in [1]. Likely that would
be easier for row_number() since any number of rows could have
rank==1.

David

[1] https://postgr.es/m/CAM-w4HN7D1wgTnKqUEnjie=E_6kJRC08CuGTLQgSirFPo3kY6A@mail.gmail.com



pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Idea: PostgreSQL equivalent to Oracle's KEEP clause
Next
From: M Tarkeshwar Rao
Date:
Subject: Multiple core dump errors are thrown by initdb when Huge pages are enabled in OS and huge_pages is set to “off” in postgresql.conf.sample in Kubernetes.