From: Tom Lane <tgl@sss.pgh.pa.us>
To: Steve Baldwin <steve.baldwin@gmail.com>
Cc: Michael Lewis <mlewis@entrata.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Consequence of changes to CTE's in 12
Date: Thu, 11 Feb 2021 19:45:30 -0500
Message-ID: <1511206.1613090730@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKE1AiY-qLKaZPu+xsfAKnri2SxMS3f744yWRm1rpY9obZbUWQ@mail.gmail.com>
References: <CAKE1AiYO3aWqB+_mUzaiqkRaeFZpUQbW5JoPhMNHOJ5hrUWdRw@mail.gmail.com>
<CAHOFxGqFevsCeo1pRRB3+EYsNWfiEwUHWU5HU-OktH0P-2muJQ@mail.gmail.com>
<CAKE1AiY-qLKaZPu+xsfAKnri2SxMS3f744yWRm1rpY9obZbUWQ@mail.gmail.com>
Steve Baldwin <steve.baldwin@gmail.com> writes:
> Is there a chance that the query optimiser should 'notice' the
> pg_try_advisory_xact_lock function, and not be so clever when it sees it?
The general policy with respect to volatile functions in WHERE quals is
"here be dragons". You don't have enough control over when a WHERE clause
will be evaluated to be sure about what the semantics will be; and we
don't want to tie the optimizer's hands to the extent that would be needed
to make it fully predictable.
In this particular case, you can make it fairly safe by making sure there
are optimization fences both above and below where the WHERE clause is.
You have one above from the LIMIT 1, but (with the new interpretation of
CTEs) not one below it. Adding a fence -- either OFFSET 0 or LIMIT ALL --
to the first CTE should fix it in a reasonably version-independent
fashion.
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, steve.baldwin@gmail.com, mlewis@entrata.com, david.g.johnston@gmail.com
Subject: Re: Consequence of changes to CTE's in 12
In-Reply-To: <1511206.1613090730@sss.pgh.pa.us>
References: <CAKE1AiYO3aWqB+_mUzaiqkRaeFZpUQbW5JoPhMNHOJ5hrUWdRw@mail.gmail.com> <CAHOFxGqFevsCeo1pRRB3+EYsNWfiEwUHWU5HU-OktH0P-2muJQ@mail.gmail.com> <CAKE1AiY-qLKaZPu+xsfAKnri2SxMS3f744yWRm1rpY9obZbUWQ@mail.gmail.com> <1511206.1613090730@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