From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Craig Ringer <craig(at)2ndquadrant(dot)com> |
Cc: | "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: Interesting case of IMMUTABLE significantly hurting performance |
Date: | 2013-08-14 04:17:40 |
Message-ID: | 22812.1376453860@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Craig Ringer <craig(at)2ndquadrant(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2013-08-14 04:44:22 | Re: Interesting case of IMMUTABLE significantly hurting performance |
Previous Message | Craig Ringer | 2013-08-14 03:57:00 | Re: Interesting case of IMMUTABLE significantly hurting performance |