Re: When IMMUTABLE is not. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: When IMMUTABLE is not.
Date
Msg-id 2131668.1686840541@sss.pgh.pa.us
Whole thread Raw
In response to Re: When IMMUTABLE is not.  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: When IMMUTABLE is not.
Re: When IMMUTABLE is not.
List pgsql-hackers
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> The failure to find and execute the function code itself is not a failure
> mode that these markers need be concerned with.  Assuming one can execute
> the function an immutable function will give the same answer for the same
> input for all time.

The viewpoint taken in the docs I mentioned is that an IMMUTABLE
marker is a promise from the user to the system about the behavior
of a function.  While the system does provide a few simple tools
to catch obvious errors and to make it easier to write functions
that obey such promises, it's mostly on the user to get it right.

In particular, we've never enforced that an immutable function can't
call non-immutable functions.  While that would seem like a good idea
in the abstract, we've intentionally not tried to do it.  (I'm pretty
sure there is more than one round of previous discussions of the point
in the archives, although locating relevant threads seems hard.)
One reason not to is that polymorphic functions have to be marked
with worst-case volatility labels.  There are plenty of examples of
functions that are stable for some input types and immutable for
others (array_to_string, for instance); but the marking system can't
represent that so we have to label them stable.  Enforcing that a
user-defined immutable function can't use such a function might
just break things for no gain.

            regards, tom lane



pgsql-hackers by date:

Previous
From: chap@anastigmatix.net
Date:
Subject: Re: When IMMUTABLE is not.
Next
From: Isaac Morland
Date:
Subject: Re: When IMMUTABLE is not.