Re: Window Functions with identical PARTITION BY and ORDER BY clauses evaluated separately
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: "David G. Johnston" <david.g.johnston@gmail.com>
Cc: Christopher Inokuchi <cinokuchi@gmail.com>,
Greg Sabino Mullane <htamfids@gmail.com>,
pgsql-bugs@lists.postgresql.org
Date: 2025-03-08T19:50:52Z
Lists: pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, Mar 7, 2025 at 5:05 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Perhaps the wording in section 7.2.5 could be improved; I agree
>> that "evaluated in one pass" is capable of being read in more
>> than one way, and it's not clear that it's referring to sorts.
>> Do you have any suggestions for clearer wording?
> We seem to do quite a few things that we don't tell the user about. The
> attached patch describes those things and adds an example demonstrating
> their effects via an explain; which is the only way you can construct an
> example for this material.
> Considered a draft pending feedback to either throw it out in favor of a
> one-word/one-line fix or support for going into this amount of detail.
Meh. This is detail that wasn't asked for and doesn't belong in this
section anyway. (If we did want to write something like this, chapter
14 Performance Tips would be a more plausible home I think. That'd
at least remove the problem of forward-referencing EXPLAIN output.)
For a shorter fix, maybe replace the first two sentences
When multiple window functions are used, all the window functions
having syntactically equivalent PARTITION BY and ORDER BY clauses
in their window definitions are guaranteed to be evaluated in a
single pass over the data. Therefore they will see the same sort
ordering, even if the ORDER BY does not uniquely determine an
ordering.
with
When multiple window functions are used, all the window functions
having syntactically equivalent PARTITION BY and ORDER BY clauses
in their window definitions are guaranteed to see the same
ordering of the input rows, even if the ORDER BY does not uniquely
determine the ordering.
regards, tom lane
Commits
-
Doc: improve description of window function processing.
- 6841118216ef 13.21 landed
- e7d29d1fac82 14.18 landed
- 2db974e40df6 15.13 landed
- 778f9dd0d2aa 16.9 landed
- 0f27bd14e480 17.5 landed
- 9f87e2593feb 18.0 landed