Re: How check execution plan of a function

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Sabin Coanda <sabin(dot)coanda(at)deuromedia(dot)ro>, pgsql-performance(at)postgresql(dot)org
Subject: Re: How check execution plan of a function
Date: 2010-04-09 13:52:00
Message-ID: 4BBF3100.4060707@squeakycode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri Apr 9 2010 8:18 AM, Sabin Coanda wrote:
> I have just a function returning a cursor based on a single coplex query.
> When I check the execution plan of that query it takes about 3 seconds. Just
> when it is used inside the function it freezes.
>
> This is the problem, and this is the reason I cannot imagine what is happen.
> Also I tried to recreate the function as it was before when it run in 3
> seconds, but I cannot make it to run properly now.
>
>

a query, like: "select stuff from aTable where akey = 5" can be
planned/prepared differently than a function containing: "select stuff
from aTable where akey = $1". I'm guessing this is the problem you are
running into. The planner has no information about $1, so cannot make
good guesses.

I think you have two options:
1) dont use a function, just fire off the sql.
2) inside the function, create the query as a string, then execute it, like:

a := "select junk from aTable where akey = 5";
EXECUE a;

(I dont think that's the exact right syntax, but hopefully gets the idea
across)

-Andy

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Merlin Moncure 2010-04-09 15:06:07 Re: PostgreSQL with Zabbix - problem of newbe
Previous Message Sabin Coanda 2010-04-09 13:18:25 Re: How check execution plan of a function