Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9SWr-0001Bl-Ji for pgsql-performance@arkaria.postgresql.org; Wed, 14 Aug 2013 04:17:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V9SWq-0004Yp-TN for pgsql-performance@arkaria.postgresql.org; Wed, 14 Aug 2013 04:17:48 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9SWq-0004Yj-2p for pgsql-performance@postgresql.org; Wed, 14 Aug 2013 04:17:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V9SWn-0004H1-2D for pgsql-performance@postgresql.org; Wed, 14 Aug 2013 04:17:47 +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 r7E4Hejk022813; Wed, 14 Aug 2013 00:17:40 -0400 From: Tom Lane To: Craig Ringer cc: "pgsql-performance@postgresql.org" Subject: Re: Interesting case of IMMUTABLE significantly hurting performance In-reply-to: <520AD240.9060508@2ndquadrant.com> References: <520AD240.9060508@2ndquadrant.com> Comments: In-reply-to Craig Ringer message dated "Wed, 14 Aug 2013 08:41:36 +0800" Date: Wed, 14 Aug 2013 00:17:40 -0400 Message-ID: <22812.1376453860@sss.pgh.pa.us> X-Pg-Spam-Score: -4.7 (----) 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've run into an interesting Stack Overflow post where the user shows > that marking a particular function as IMMUTABLE significantly hurts the > performance of a query. > http://stackoverflow.com/q/18220761/398670 > CREATE OR REPLACE FUNCTION > to_datestamp_immutable(time_int double precision) RETURNS date AS $$ > SELECT date_trunc('day', to_timestamp($1))::date; > $$ LANGUAGE SQL IMMUTABLE; [ 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. 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