pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mario Splivalo <mario.splivalo@megafon.hr>
Cc: pgsql-performance@postgresql.org
Subject: Re: Query much slower when run from postgres function
Date: Mon, 09 Mar 2009 15:51:58 -0400
Message-ID: <14317.1236628318@sss.pgh.pa.us> (raw)
In-Reply-To: <49B56A3D.8000100@megafon.hr>
References: <49B51B60.6030600@megafon.hr>
	<27649.1236616294@sss.pgh.pa.us>
	<49B56A3D.8000100@megafon.hr>

Mario Splivalo <mario.splivalo@megafon.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



view thread (26+ messages)  latest in thread

Message-ID: <14317.1236628318@sss.pgh.pa.us>
Permalink:  ../14317.1236628318@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/14317.1236628318@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, mario.splivalo@megafon.hr
  Subject: Re: Query much slower when run from postgres function
  In-Reply-To: <14317.1236628318@sss.pgh.pa.us>

* 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