Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cu73a-0003Qz-EO for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Apr 2017 00:38:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cu73Z-00055Y-Sk for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Apr 2017 00:38:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cu72t-0003qd-Cm for pgsql-bugs@postgresql.org; Sat, 01 Apr 2017 00:37:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cu72p-0003YK-1H for pgsql-bugs@postgresql.org; Sat, 01 Apr 2017 00:37:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v310bRPG027437; Fri, 31 Mar 2017 20:37:27 -0400 From: Tom Lane To: Pavel Stehule cc: jankaraffa@gmail.com, "pgsql-bugs@postgresql.org" Subject: Re: BUG #14607: session variables are non-deterministic In-reply-to: References: <20170331123512.2688.34145@wrigleys.postgresql.org> Comments: In-reply-to Pavel Stehule message dated "Fri, 31 Mar 2017 15:03:30 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27435.1491007047.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 31 Mar 2017 20:37:27 -0400 Message-ID: <27436.1491007047@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Pavel Stehule writes: > 2017-03-31 14:35 GMT+02:00 : >> It behaves like current_setting function is non-deterministic and theref= ore >> 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 --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs