pg.ddx.io pgsql-performance@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Gavin M. Roy <gmr@myyearbook.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: SQL Function Slowness, 8.3.0
Date: Wed, 16 Apr 2008 16:24:32 -0400
Message-ID: <18099.1208377472@sss.pgh.pa.us> (raw)
In-Reply-To: <af1bce590804161144q1b78be6cy69c9a44cc4b9b7bf@mail.gmail.com>
References: <af1bce590804160806t58f7da1g50fc697dd9e6ab08@mail.gmail.com>
<8328.1208358587@sss.pgh.pa.us>
<af1bce590804161144q1b78be6cy69c9a44cc4b9b7bf@mail.gmail.com>
"Gavin M. Roy" <gmr@myyearbook.com> writes:
> After detailed examination of pg_stat_user_indexes usage, it's clear that
> the functions don't use the same indexes. I've casted everything to match
> the indexes in the SQL function, to no success. Any suggestions on next
> steps? Maybe for 8.4 we could find a way to explain analyze function
> internals ;-)
Yeah, this could be easier, but it's certainly possible to examine the
plan generated for a function's parameterized statement. For instance,
say you're wondering about the plan for
create function foo(int, text) ... as
$$ select * from bar where f1 = $1 and f2 = $2 $$
language sql
What you do is
prepare p(int, text) as select * from bar where f1 = $1 and f2 = $2 ;
explain analyze execute p(42, 'hello world');
It works exactly the same for statements in plpgsql functions,
remembering that both parameters and local variables of the function
have to become $n placeholders. Remember to make the parameters
of the prepared statement have the same declared types as the
function's parameters and variables.
regards, tom lane
view thread (17+ messages) latest in thread
Message-ID: <18099.1208377472@sss.pgh.pa.us> Permalink: ../18099.1208377472@sss.pgh.pa.us/ Also on: postgresql.org/message-id/18099.1208377472@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, gmr@myyearbook.com Subject: Re: SQL Function Slowness, 8.3.0 In-Reply-To: <18099.1208377472@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