Re: Is postgres able to share sorts required by common partition window functions? - Mailing list pgsql-general

From Sebastien Arod
Subject Re: Is postgres able to share sorts required by common partition window functions?
Date
Msg-id CADd42iFGCSuscEeW1yLULLMxq_sD8aVxn=gy+Z7xABC0YeXEDQ@mail.gmail.com
Whole thread Raw
In response to Re: Is postgres able to share sorts required by common partition window functions?  (Michael Lewis <mlewis@entrata.com>)
List pgsql-general
Hi Michael,

I simplified the real query before posting it here and I now realize that I oversimplified things.

Unfortunately the real query cannot be re-written with a group by.

Some of the window functions are more complex with order by clause using complex expressions involving multiple columns.

The following example would be more realistic:

select distinct
  c1,
  first_value(c2) OVER (PARTITION BY c1 order by c2, c4) AS c2,
  first_value(c3) OVER (PARTITION BY c1 order by coalesce(c4, '000'), c3) AS c3
from  
  t;



On Mon, Jul 6, 2020 at 9:55 PM Michael Lewis <mlewis@entrata.com> wrote:
Does this give the same result and do the optimization you want?

select
  c1,
  min(c2) AS c2,
  min(c3) AS c3,
  min(c4) AS c4
from  
  t
group by
  c1;

pgsql-general by date:

Previous
From: Michael Lewis
Date:
Subject: Re: Is postgres able to share sorts required by common partition window functions?
Next
From: David Rowley
Date:
Subject: Re: Apply LIMIT when computation is logically irrelevant