public inbox for [email protected]  
help / color / mirror / Atom feed
From: Richard Guo <[email protected]>
To: David Rowley <[email protected]>
Cc: Daniel Farkaš <[email protected]>
Cc: Magnus Hagander <[email protected]>
Cc: PostgreSQL mailing lists <[email protected]>
Subject: Re: BUG #17502: View based on window functions returns wrong results when queried
Date: Mon, 30 May 2022 17:18:44 +0800
Message-ID: <CAMbWs48yS=f8tj6zstiMd6yfV3U4YpssyB55PXqjcLUyUA5bww@mail.gmail.com> (raw)
In-Reply-To: <CAApHDvqKO00nNQtchBs65VTfjEMUsYiB5r2P4VUreTdXE9RY1g@mail.gmail.com>
References: <[email protected]>
	<CABUevEz7t3OWxaSSVSHOxa5KcYioOk=yRwoL3iMViyZQ8m2wAw@mail.gmail.com>
	<CAGckUK2GLF=d9J5ErEWgK5x8ECqCw4equnq3jEzrqtfJw+iHYw@mail.gmail.com>
	<CAApHDvoR4BXm7oxSrYhpEAFOZ-qMPkkYnn14y6sxtPf=5w5OOw@mail.gmail.com>
	<CAApHDvqKO00nNQtchBs65VTfjEMUsYiB5r2P4VUreTdXE9RY1g@mail.gmail.com>

On Mon, May 30, 2022 at 9:12 AM David Rowley <[email protected]> wrote:

> The following is also pretty strange. Why should adding the SRF column
> to the ORDER BY change the number of output rows?
>
> postgres=# select distinct on (a) a,b, generate_Series(1,2) from ab
> order by a,b,3 desc;
>  a | b | generate_series
> ---+---+-----------------
>  1 | 1 |               2
>  2 | 1 |               2
> (2 rows)
>
>
> postgres=# select distinct on (a) a,b, generate_Series(1,2) from ab
> order by a,b;
>  a | b | generate_series
> ---+---+-----------------
>  1 | 1 |               1
>  1 | 1 |               2
>  2 | 1 |               1
>  2 | 1 |               2
> (4 rows)
>

This is indeed weird. This seems depends on at which plan level we add
ProjectSetPath. For the first query we insert ProjectSetPath at the
scan/join level, because the SRF is included in the ORDER BY, which
makes the SRF appear in the scan/join target. For the second query the
SRF is postponed to after the Sort.

Is this a bug we should fix?

Thanks
Richard


view thread (18+ 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], [email protected], [email protected]
  Subject: Re: BUG #17502: View based on window functions returns wrong results when queried
  In-Reply-To: <CAMbWs48yS=f8tj6zstiMd6yfV3U4YpssyB55PXqjcLUyUA5bww@mail.gmail.com>

* 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