Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-12-22 Thread Vik Fearing
On 12/23/22 00:47, David Rowley wrote: On Wed, 26 Oct 2022 at 14:38, David Rowley wrote: I've now pushed the final result. Thank you to everyone who provided input on this. This is a very good improvement. Thank you for working on it. -- Vik Fearing

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-12-22 Thread David Rowley
On Wed, 26 Oct 2022 at 14:38, David Rowley wrote: > > On Sun, 23 Oct 2022 at 03:03, Vik Fearing wrote: > > Shouldn't it be able to detect that these two windows are the same and > > only do one WindowAgg pass? > > > > > > explain (verbose, costs off) > > select row_number() over w1, > >

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-25 Thread David Rowley
On Sun, 23 Oct 2022 at 03:03, Vik Fearing wrote: > Shouldn't it be able to detect that these two windows are the same and > only do one WindowAgg pass? > > > explain (verbose, costs off) > select row_number() over w1, > lag(amname) over w2 > from pg_am > window w1 as (order by amname), >

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-22 Thread Vik Fearing
On 10/20/22 22:02, David Rowley wrote: On Thu, 13 Oct 2022 at 13:34, David Rowley wrote: So it looks like the same can be done for rank() and dense_rank() too. I've added support for those in the attached. The attached adds support for percent_rank(), cume_dist() and ntile(). Shouldn't it

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-20 Thread David Rowley
On Thu, 13 Oct 2022 at 13:34, David Rowley wrote: > So it looks like the same can be done for rank() and dense_rank() too. > I've added support for those in the attached. The attached adds support for percent_rank(), cume_dist() and ntile(). David diff --git

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-17 Thread David Rowley
Thanks for having a look at this. On Fri, 14 Oct 2022 at 10:52, Zhihong Yu wrote: > + req->frameOptions = (FRAMEOPTION_ROWS | > +FRAMEOPTION_START_UNBOUNDED_PRECEDING | > +FRAMEOPTION_END_CURRENT_ROW); > > The bit combination appears

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-17 Thread David Rowley
On Tue, 18 Oct 2022 at 12:18, Tom Lane wrote: > > Erwin Brandstetter writes: > > I am thinking of building a test case to run > > - all existing window functions > > - with all basic variants of frame definitions > > - once with ROWS, once with RANGE > > - on basic table that has duplicate and

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-17 Thread Tom Lane
Erwin Brandstetter writes: > I am thinking of building a test case to run > - all existing window functions > - with all basic variants of frame definitions > - once with ROWS, once with RANGE > - on basic table that has duplicate and NULL values in partition and > ordering columns > - in all

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-17 Thread Erwin Brandstetter
On Thu, 13 Oct 2022 at 02:34, David Rowley wrote: > On Wed, 12 Oct 2022 at 16:33, Vik Fearing wrote: > > Per spec, the ROW_NUMBER() window function is not even allowed to have a > > frame specified. > > > > b) The window framing clause of WDX shall not be present. > > > > Also, the

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-13 Thread Zhihong Yu
On Wed, Oct 12, 2022 at 5:35 PM David Rowley wrote: > On Wed, 12 Oct 2022 at 16:33, Vik Fearing wrote: > > Per spec, the ROW_NUMBER() window function is not even allowed to have a > > frame specified. > > > > b) The window framing clause of WDX shall not be present. > > > > Also, the

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-12 Thread David Rowley
On Wed, 12 Oct 2022 at 16:33, Vik Fearing wrote: > Per spec, the ROW_NUMBER() window function is not even allowed to have a > frame specified. > > b) The window framing clause of WDX shall not be present. > > Also, the specification for ROW_NUMBER() is: > > f) ROW_NUMBER() OVER WNS is

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-11 Thread Erwin Brandstetter
On Wed, 12 Oct 2022 at 05:33, Vik Fearing wrote: > On 10/12/22 04:40, David Rowley wrote: > > I've not really done any analysis into which other window functions > > can use this optimisation. The attached only adds support to > > row_number()'s support function and only converts exactly "RANGE

Re: Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-11 Thread Vik Fearing
On 10/12/22 04:40, David Rowley wrote: I've not really done any analysis into which other window functions can use this optimisation. The attached only adds support to row_number()'s support function and only converts exactly "RANGE UNBOUNDED PRECEDING AND CURRENT ROW" into "ROW UNBOUNDED

Allow WindowFuncs prosupport function to use more optimal WindowClause options

2022-10-11 Thread David Rowley
Over on [1], Erwin mentions that row_number() over (ORDER BY ... ROWS UNBOUNDED PRECEDING) is substantially faster than the default RANGE UNBOUNDED PRECEDING WindowClause options. The difference between these options are that nodeWindowAgg.c checks for peer rows for RANGE but not for ROWS. That