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

From David G. Johnston
Subject Re: Is postgres able to share sorts required by common partition window functions?
Date
Msg-id CAKFQuwYWuVZYnX9RCrv__L_0G_WJfGg6R9iPO9d39DK8FHOuWg@mail.gmail.com
Whole thread Raw
In response to Is postgres able to share sorts required by common partition window functions?  (Sebastien Arod <sebastien.arod@gmail.com>)
Responses Re: Is postgres able to share sorts required by common partition window functions?
List pgsql-general
On Monday, July 6, 2020, Sebastien Arod <sebastien.arod@gmail.com> wrote:
I would have expected postgresql to "share" a preliminary sort on c1 that would then be useful to reduce the work on all window functions but it doesn't. 

The plan shown does share - the output of one sort goes into another.  Subsequent sorts still have to happen but they should be faster as the first field is already grouped.  Doesn’t change the plan though.
 
I even created an index on c1 hoping that postgresql would be able to use it in order to minimize the cost of the sorts but I couldn't make it use it.

Use it how?  You are still evaluating 250k groups so doing anything piece-wise seems like an expected loss compared to sequential scan.

David J.
 

pgsql-general by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Is postgres able to share sorts required by common partition window functions?
Next
From: Paul McGarry
Date:
Subject: Efficiently advancing a sequence without risking it going backwards.