pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Interesting case of IMMUTABLE significantly hurting performance
Date: Wed, 14 Aug 2013 12:44:22 +0800
Message-ID: <520B0B26.70204@2ndquadrant.com> (raw)
In-Reply-To: <22812.1376453860@sss.pgh.pa.us>
References: <520AD240.9060508@2ndquadrant.com>
	<22812.1376453860@sss.pgh.pa.us>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

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



view thread (7+ messages)  latest in thread

Message-ID: <520B0B26.70204@2ndquadrant.com>
Permalink:  ../520B0B26.70204@2ndquadrant.com/
Also on:    postgresql.org/message-id/520B0B26.70204@2ndquadrant.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: craig@2ndquadrant.com, tgl@sss.pgh.pa.us
  Subject: Re: Interesting case of IMMUTABLE significantly hurting performance
  In-Reply-To: <520B0B26.70204@2ndquadrant.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox