Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0D4981546DE6 for ; Tue, 8 Nov 2011 20:25:47 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 37681-10 for ; Wed, 9 Nov 2011 00:25:41 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail.anarazel.de (mail.anarazel.de [217.115.131.40]) by mail.postgresql.org (Postfix) with ESMTP id CDA0E1546DE5 for ; Tue, 8 Nov 2011 20:25:40 -0400 (AST) Received: from intern.anarazel.de (p54B4ECF7.dip.t-dialin.net [84.180.236.247]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPA id 4929B44800C; Wed, 9 Nov 2011 01:25:39 +0100 (CET) From: Andres Freund To: pgsql-performance@postgresql.org Cc: Josh Berkus Subject: Re: STRICT SQL functions never inline Date: Wed, 09 Nov 2011 01:25:36 +0100 Message-ID: <2035036.0LnEqdmoaV@alap2> User-Agent: KMail/4.7.2 (Linux/3.1.0-rc8-andres-00060-g47ea91b; KDE/4.7.1; x86_64; ; ) In-Reply-To: <4EB9BB3F.6090504@agliodbs.com> References: <4EB9BB3F.6090504@agliodbs.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.101 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-1.201 X-Spam-Level: X-Archive-Number: 201111/119 X-Sequence-Number: 45630 On Tuesday, November 08, 2011 15:29:03 Josh Berkus wrote: > Folks, > > After having some production issues, I did some testing and it seems > that any SQL function declared STRICT will never inline. As a result, > it won't work with either indexes (on the underlying predicate) or > partitioning. > > This seems like a horrible gotcha for our users. At the very least I'd > like to document it (in CREATE FUNCTION, presumably), but it would be > better to fix it. Thoughts? I am all for documenting it somewhere. There were lots of people hit by it in the past - e.g. the postgis folks. Its not so easy to fix though. The problem is that straight inlining would change the behaviour because suddenly the expression might not return NULL anymore even though one of the parameters is NULL. Or even cause more problems because the content wasn't prepared to handle NULLs. It would be possible to inline a CASE $1 IS NULL OR $2 IS NULL .... THEN NULL ELSE orig_expression END but that would be usefull in far fewer cases because it won't help much in most cases and actually might hurt performance in some. Andres