Re: Interesting case of IMMUTABLE significantly hurting performance - Mailing list pgsql-performance

From Tom Lane
Subject Re: Interesting case of IMMUTABLE significantly hurting performance
Date
Msg-id 22812.1376453860@sss.pgh.pa.us
Whole thread Raw
In response to Interesting case of IMMUTABLE significantly hurting performance  (Craig Ringer <craig@2ndquadrant.com>)
Responses Re: Interesting case of IMMUTABLE significantly hurting performance  (Craig Ringer <craig@2ndquadrant.com>)
List pgsql-performance
Craig Ringer <craig@2ndquadrant.com> 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


pgsql-performance by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Interesting case of IMMUTABLE significantly hurting performance
Next
From: Craig Ringer
Date:
Subject: Re: Interesting case of IMMUTABLE significantly hurting performance