Re: BUG #14607: session variables are non-deterministic

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: jankaraffa(at)gmail(dot)com, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14607: session variables are non-deterministic
Date: 2017-04-01 00:37:27
Message-ID: 27436.1491007047@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> 2017-03-31 14:35 GMT+02:00 <jankaraffa(at)gmail(dot)com>:
>> It behaves like current_setting function is non-deterministic and therefore
>> sql optimalizator is not considered output as constant. For me it looks like
>> bug as session variable can not change during parsing/execution.

> session variable is volatile - so it is not bug.

> There is a workaround - you can wrap a access to this variable to STABLE
> function

current_setting() already is stable according to the pg_proc catalog.
This is not a bug because the OP is wrong: GUC values *can* change between
planning and execution. It's very easy for that to happen when dealing
with cached plans.

(Really, they could change even during execution of a query, but we choose
to avert our eyes from that fact rather than mark the function volatile
and thereby make it even less optimizable.)

You could force it by using a wrapper function marked IMMUTABLE, but that
really seems like carrying around a loaded gun aimed at your foot.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Noah Misch 2017-04-01 02:41:38 Re: could not fork autovacuum worker process: No error
Previous Message Yasuo Ohgaki 2017-03-31 23:03:03 Money type does not detect over/underflow unlike int/int8