Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9Swq-0002Ey-Dp for pgsql-performance@arkaria.postgresql.org; Wed, 14 Aug 2013 04:44:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V9Swp-0007KN-Rd for pgsql-performance@arkaria.postgresql.org; Wed, 14 Aug 2013 04:44:39 +0000 Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9Swo-0007J9-Ge for pgsql-performance@postgresql.org; Wed, 14 Aug 2013 04:44:38 +0000 Received: from outmail149077.authsmtp.com ([62.13.149.77]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9Swl-0003KB-Kg for pgsql-performance@postgresql.org; Wed, 14 Aug 2013 04:44:38 +0000 Received: from mail-c226.authsmtp.com (mail-c226.authsmtp.com [62.13.128.226]) by punt7.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id r7E4iTY6081918; Wed, 14 Aug 2013 05:44:29 +0100 (BST) Received: from ayaki.localdomain (124-169-245-108.dyn.iinet.net.au [124.169.245.108]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id r7E4iMAe063419 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Wed, 14 Aug 2013 05:44:25 +0100 (BST) Message-ID: <520B0B26.70204@2ndquadrant.com> Date: Wed, 14 Aug 2013 12:44:22 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: Tom Lane CC: "pgsql-performance@postgresql.org" Subject: Re: Interesting case of IMMUTABLE significantly hurting performance References: <520AD240.9060508@2ndquadrant.com> <22812.1376453860@sss.pgh.pa.us> In-Reply-To: <22812.1376453860@sss.pgh.pa.us> X-Enigmail-Version: 1.5.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Server-Quench: 32e9839b-049c-11e3-98a9-0025907ec6c5 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZeVg0b BQteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaQFbbExW HGQLWldEUFh7XWd/ aQwfbAdZfEtIVhto VE1XQ1JaCwdtAxke B1BcVWx2Lng3LX52 ZkJjVz5eWE16O0V/ F0dcFmRUeGdkYTMC UUENdB5deFJDYx9F aFV2VHRYMmNUYzQC El17DAgcBxt4EgFg CiALMV8ITF0XHzgz DxsLBjhnGkNNZgAW EiAPAHoxVF0QPUMz P1oqUFQENw5aChBE A0BLD00RP1QbSS0x CApcVkN2 X-Authentic-SMTP: 61633235383639.1020:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 124.169.245.108/2525 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Pg-Spam-Score: -2.6 (--) 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 On 08/14/2013 12:17 PM, Tom Lane wrote: > [ shrug... ] Using IMMUTABLE to lie about the mutability of a function > (in this case, date_trunc) is a bad idea. It's likely to lead to wrong > answers, never mind performance issues. In this particular case, I > imagine the performance problem comes from having suppressed the option > to inline the function body ... but you should be more worried about > whether you aren't getting flat-out bogus answers in other cases. Oh, I totally agree, and I'd never do this myself. I was just curious about the behaviour. It's interesting that this variant doesn't seem to be slow: create or replace function to_datestamp_immutable( time_int double precision ) returns date as $$ select date_trunc('day', timestamp 'epoch' + $1 * interval '1 second')::date; $$ language sql immutable; and there's no sign it's parsed each time. So it's not just the IMMUTABLE flag. If nothing else this strongly suggests that the docs don't cover this area particularly comprehensively. -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance