From: Tom Lane <tgl@sss.pgh.pa.us>
To: Davide Jensen <d.jensen@tecnoteca.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Different result behavior when using ANY(ARRAY(SELECT)) and IN (SELECT)
Date: Mon, 09 Nov 2020 10:10:30 -0500
Message-ID: <1974195.1604934630@sss.pgh.pa.us> (raw)
In-Reply-To: <CAM+X8W-rz4z4VLGfDe0zeMeRxBkrpdcKRZYNzsjjR3TtcLjNwA@mail.gmail.com>
References: <CAM+X8W-rz4z4VLGfDe0zeMeRxBkrpdcKRZYNzsjjR3TtcLjNwA@mail.gmail.com>
Davide Jensen <d.jensen@tecnoteca.com> writes:
> I'm encountering some problems in understanding the behavior of a query
> that uses an IN operator, the query i'm executing is the following:
> SELECT * FROM (
> SELECT _id,
> ROW_NUMBER() OVER () AS _rownumber
I think your problem is in the above, not anything later in the query.
ROW_NUMBER without any ordering specification is indeterminate.
If the query gets parallelized, it's no surprise that the selected rows
will be processed in varying order from one try to the next. Your
second phrasing of the query seems to be non-parallelizable, but the
row_number() result is still pretty indeterminate; it just doesn't
happen to have changed within your test run.
What is it you are expecting to get out of including a fictional
row number in the query result, anyway?
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, d.jensen@tecnoteca.com
Subject: Re: Different result behavior when using ANY(ARRAY(SELECT)) and IN (SELECT)
In-Reply-To: <1974195.1604934630@sss.pgh.pa.us>
References: <CAM+X8W-rz4z4VLGfDe0zeMeRxBkrpdcKRZYNzsjjR3TtcLjNwA@mail.gmail.com> <1974195.1604934630@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox