On Wed, 26 Oct 2022 at 14:38, David Rowley <dgrowle...@gmail.com> wrote: > > On Sun, 23 Oct 2022 at 03:03, Vik Fearing <v...@postgresfriends.org> 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), > > w2 as (w1 rows unbounded preceding) > > ; > > Good thinking. I think the patch should also optimise that case. It > requires re-doing a similar de-duplication phase the same as what's > done in transformWindowFuncCall(). I've added code to do that in the > attached version.
I've spent a bit more time on this now and added a few extra regression tests. The previous version had nothing to test to ensure that an aggregate function being used as a window function does not have its frame options changed when it's sharing the same WindowClause as a WindowFunc which can have the frame options changed. I've now pushed the final result. Thank you to everyone who provided input on this. David