Skip site navigation (1) Skip section navigation (2)

Re: Query timing increased from 3s to 55s when used as function instead of select

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Tyler Hildebrandt <tyler(at)campbell-lange(dot)net>
Cc: pgsql-performance(at)postgresql(dot)org, Sebastian Ritter <sebastian(at)campbell-lange(dot)net>, rory <rory(at)campbell-lange(dot)net>
Subject: Re: Query timing increased from 3s to 55s when used as function instead of select
Date: 2010-05-27 15:55:13
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
On 27/05/2010 11:33 PM, Craig Ringer wrote:
> On 21/05/2010 9:54 PM, Tyler Hildebrandt wrote:
>> We're using a function that when run as a select statement outside of the
>> function takes roughly 1.5s to complete whereas running an identical
>> query within a function is taking around 55s to complete.
>> We are lost as to why placing this query within a function as opposed to
>> substituting the variables in a select statement is so drastically
>> different.
> This is a frequently asked question. It's the same issue as with
> prepared queries, where the planner has to pick a more general plan when
> it doesn't know the value of a parameter. The short answer is "work
> around it by using EXECUTE ... USING to invoke your query dynamically".
> ( Oddly, this FAQ doesn't seem to be on the FAQ list at
> )

Added as:

and the subsequent entry too.

Comments, edits, clarification appreciated. I know it's not as well 
written as it could be, could use archive links, etc; it's just pass 1.

Craig Ringer

In response to

pgsql-performance by date

Next:From: David JarvisDate: 2010-05-27 15:55:55
Subject: Re: Random Page Cost and Planner
Previous:From: Konrad GarusDate: 2010-05-27 15:51:43
Subject: Re: shared_buffers advice

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group