Re: Query much slower when run from postgres function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query much slower when run from postgres function
Date: 2009-03-09 19:51:58
Message-ID: 14317.1236628318@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc pgsql-performance

Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr> writes:
> Is this difference normal?

It's hard to tell, because you aren't comparing apples to apples.
Try a prepared statement, like

prepare foo(int) as
SELECT
COUNT(*)::int4
FROM
_v1
WHERE
service_id = $1
;

execute foo(504);

which should produce results similar to the function. You could
then use "explain analyze execute" to probe further into what's
happening.

regards, tom lane

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2009-03-09 19:56:53 Re: [PERFORM] Query much slower when run from postgres function
Previous Message Mario Splivalo 2009-03-09 19:26:05 Re: [PERFORM] Query much slower when run from postgres function

Browse pgsql-performance by date

  From Date Subject
Next Message Dave Cramer 2009-03-09 19:56:53 Re: [PERFORM] Query much slower when run from postgres function
Previous Message Mario Splivalo 2009-03-09 19:26:05 Re: [PERFORM] Query much slower when run from postgres function