pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Wrong results from function that selects from vier after "created or replace"
Date: Mon, 12 Oct 2020 21:46:04 -0400
Message-ID: <3403768.1602553564@sss.pgh.pa.us> (raw)
In-Reply-To: <EF124763-B98B-4456-A499-64E0613D3EA6@yugabyte.com>
References: <4DE6C9D8-77A5-4858-82CB-18728F59D715@yugabyte.com>
	<3401031.1602549490@sss.pgh.pa.us>
	<EF124763-B98B-4456-A499-64E0613D3EA6@yugabyte.com>

Bryn Llewellyn <bryn@yugabyte.com> writes:
> Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> No.  You marked the functions as "immutable", and then you broke that
>> promise by changing what they'd need to output.

> Thank you for the very quick response. This is what the Version 12 doc says on “immutable”:

>> An IMMUTABLE function cannot modify the database and is guaranteed to return the same results given the same arguments forever.

Indeed.  f1() has no arguments, therefore an immutable marking is a
promise --- made by you to the database, NOT vice versa --- that its
output will never change at all.  (f2 likewise, although in this
particular example that's not what matters.)  Optimizations made on
the strength of such a promise are not bugs.

As a general rule, immutable functions that inspect the database's
contents are probably wrongly marked.  We don't forbid such coding,
because there are narrow use-cases for it, but I tend to believe
that it's a red flag for misdesign.

> I couldn’t find an “all bets are off” caveat for the case where
> either an “immutable” function itself or any of its dependency
> parents is recompiled.

We do not attempt to document what might go wrong when you lie
about the volatility classification of a function.  There are
a lot of possibilities, many of them worse than what you have
here, and there's no reason to think that the implications will
be stable enough to be worth documenting.

> I had read “forever” to mean “forever until the function, or any of
> its dependency parents, is semantically changed”.

That's a curious reading of "forever".

> And this is the caveated meaning that Oracle database implements for
> its moral equivalent “deterministic”.

Nowhere do we claim to do exactly what Oracle does, especially when
it's not even the same syntax.  "immutable" is NOT the same thing
as "deterministic".

			regards, tom lane





view thread (15+ messages)  latest in thread

Message-ID: <3403768.1602553564@sss.pgh.pa.us>
Permalink:  ../3403768.1602553564@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3403768.1602553564@sss.pgh.pa.us

 · 

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: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bryn@yugabyte.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: Wrong results from function that selects from vier after "created or replace"
  In-Reply-To: <3403768.1602553564@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