Re: When IMMUTABLE is not.

From: Yura Sokolov <y(dot)sokolov(at)postgrespro(dot)ru>
To: chap(at)anastigmatix(dot)net, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: When IMMUTABLE is not.
Date: 2023-06-15 14:06:44
Message-ID: 46a455f6-16f8-1c98-955f-140449004d72@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


15.06.2023 16:58, chap(at)anastigmatix(dot)net пишет:
> On 2023-06-15 09:21, Tom Lane wrote:
>> Yura Sokolov <y(dot)sokolov(at)postgrespro(dot)ru> writes:
>>> not enough to be sure function doesn't manipulate data.
>>
>> Of course not.  It is the user's responsibility to mark functions
>> properly.
>
> And also, isn't it the case that IMMUTABLE should mark a function,
> not merely that "doesn't manipulate data", but whose return value
> doesn't depend in any way on data (outside its own arguments)?
>
> The practice among PLs of choosing an SPI readonly flag based on
> the IMMUTABLE/STABLE/VOLATILE declaration seems to be a sort of
> peculiar heuristic, not something inherent in what that declaration
> means to the optimizer. (And also influences what snapshot the
> function is looking at, and therefore what it can see, which has
> also struck me more as a tacked-on effect than something inherent
> in the declaration's meaning.)

Documentation disagrees:

https://www.postgresql.org/docs/current/sql-createfunction.html#:~:text=IMMUTABLE%0ASTABLE%0AVOLATILE

> |IMMUTABLE|indicates that the function cannot modify the database and
always returns the same result when given the same argument values

> |STABLE|indicates that the function cannot modify the database, and
that within a single table scan it will consistently return the same
result for the same argument values, but that its result could change
across SQL statements.

> |VOLATILE|indicates that the function value can change even within a
single table scan, so no optimizations can be made... But note that any
function that has side-effects must be classified volatile, even if its
result is quite predictable, to prevent calls from being optimized away

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-06-15 14:10:03 Re: When IMMUTABLE is not.
Previous Message chap 2023-06-15 13:58:39 Re: When IMMUTABLE is not.