From: Jim C. Nasby <jim@nasby.net>
To: Matthew Peters <matthew@haydrian.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: Stored procedure slower than sql?
Date: Thu, 26 Oct 2006 14:19:18 -0500
Message-ID: <20061026191918.GE26892@nasby.net> (raw)
In-Reply-To: <775F825B46B551499DC75DC4E92F80AB564D05@jupiter.ad.haydrian.com>
References: <21413.1161879278@sss.pgh.pa.us>
<775F825B46B551499DC75DC4E92F80AB564D05@jupiter.ad.haydrian.com>
The planner has no idea what $1 and $2 are when it plans the query, so
that could easily explain why the performance is different. You can
prepare statements in psql (at least in 8.1), which would be a good way
to verify that theory (compare EXPLAIN for prepared vs. non).
On Thu, Oct 26, 2006 at 09:21:37AM -0700, Matthew Peters wrote:
> Parameterized.
>
> IE (very simplified)
>
> CREATE OR REPLACE FUNCTION my_function(IN param1 BIGINT, IN param2
> INTEGER)
> RETURNS my_type
> SECURITY DEFINER
> AS
> $$
> /* my_type = (a,b,c) */
> Select a,b,c
> FROM my_table
> WHERE indexed_column = $1
> AND partition_constraint_column = $2;
> $$
> LANGUAGE SQL;
>
>
>
>
> Matthew A. Peters
> Sr. Software Engineer, Haydrian Corp.
> matthew@haydrian.com
> (mobile) 425-941-6566
> Haydrian Corp.
> -----Original Message-----
> From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
> Sent: Thursday, October 26, 2006 9:15 AM
> To: Matthew Peters
> Cc: pgsql-performance@postgresql.org
> Subject: Re: [PERFORM] Stored procedure slower than sql?
> Importance: High
>
> "Matthew Peters" <matthew@haydrian.com> writes:
> > How can a stored procedure containing a single query not implement the
> > same execution plan (assumption based on the dramatic performance
> > difference) that an identical ad-hoc query generates?
>
> Parameterized vs non parameterized query?
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>
--
Jim Nasby jim@nasby.net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)
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: jim@nasby.net, matthew@haydrian.com, tgl@sss.pgh.pa.us
Subject: Re: Stored procedure slower than sql?
In-Reply-To: <20061026191918.GE26892@nasby.net>
* 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