public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Romain Carl <[email protected]>
Cc: [email protected]
Subject: Re: Window functions: frame-adhering aggregate without ORDER BY clause
Date: Mon, 26 Jun 2023 09:54:23 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>

Romain Carl <[email protected]> writes:
> among the window tests (src/test/regress/expected/window.out), I noticed 
> the presence of tests that rely upon the order of rows not determined by 
> any ORDER BY clause, such as:

Yeah ...

> The current row's frame and, consequently, the result of the sum 
> aggregate depend on the order produced by the sequential scan of table 
> tenk1. Since such order is, in general, not part of PG's defined 
> behavior, what purpose do the tests that rely upon it serve?

The tests are perfectly entitled to test PG's actual behavior.
I don't see much difference between this particular case and the
fact that we have any tests at all that lack ORDER BY, because
formally speaking the engine could choose to emit the rows in
some other order.  In practice, if we ever did make the engine
behave differently, it'd be on us to fix affected test cases.

> Following up to that, how is an EXCLUDE GROUP defined to behave in 
> absence of any ORDER BY clause?

I see in the docs

    <literal>EXCLUDE GROUP</literal> excludes the current row and its
    ordering peers from the frame.

and a bit later

    Without <literal>ORDER BY</literal>,
    ... all rows become peers of the current row.

so excluding the whole frame seems like the right behavior.

			regards, tom lane





view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Window functions: frame-adhering aggregate without ORDER BY clause
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox