Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1X1nbx-0003yu-Hy for pgsql-performance@arkaria.postgresql.org; Tue, 01 Jul 2014 02:15:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1X1nbw-0008NW-UB for pgsql-performance@arkaria.postgresql.org; Tue, 01 Jul 2014 02:15:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X1nbv-0008N3-NL for pgsql-performance@postgresql.org; Tue, 01 Jul 2014 02:15:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1X1nbt-0007Dj-0J for pgsql-performance@postgresql.org; Tue, 01 Jul 2014 02:15:54 +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 s612FlR1029153; Mon, 30 Jun 2014 22:15:47 -0400 From: Tom Lane To: Craig Ringer cc: "pgsql-performance@postgresql.org" , Pavel Stehule Subject: Re: Volatility - docs vs behaviour? In-reply-to: <53B20AC4.50901@2ndquadrant.com> References: <53B12CE7.5090506@2ndquadrant.com> <10762.1404143363@sss.pgh.pa.us> <53B20AC4.50901@2ndquadrant.com> Comments: In-reply-to Craig Ringer message dated "Tue, 01 Jul 2014 09:11:32 +0800" Date: Mon, 30 Jun 2014 22:15:47 -0400 Message-ID: <29152.1404180947@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-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Craig Ringer writes: > I was unaware that the planner made any attempt to catch users' errors > in marking the strictness of functions. I thought it pretty much trusted > the user not to lie about the mutability of functions invoked > indirectly. I'm not really sure where in the inlining code to look to > figure that out. It's in optimizer/util/clauses.c: /* * Additional validity checks on the expression. It mustn't return a set, * and it mustn't be more volatile than the surrounding function (this is * to avoid breaking hacks that involve pretending a function is immutable * when it really ain't). If the surrounding function is declared strict, * then the expression must contain only strict constructs and must use * all of the function parameters (this is overkill, but an exact analysis * is hard). */ if (expression_returns_set(newexpr)) goto fail; if (funcform->provolatile == PROVOLATILE_IMMUTABLE && contain_mutable_functions(newexpr)) goto fail; else if (funcform->provolatile == PROVOLATILE_STABLE && contain_volatile_functions(newexpr)) goto fail; As the comment says, this wasn't really coded with an eye towards "catching user error". Rather, there are known use-cases where people intentionally use SQL wrapper functions to lie about the mutability of some underlying function; inlining would expose the truth of the matter and thus defeat such hacks. Now I'd be the first to agree that this isn't a terribly high-performance way of doing that, but the point here was to not change the behavior that existed before SQL inlining did. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance