Re: Reusing cached prepared statement slow after 5 executions

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Rob Gansevles <rgansevles(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Reusing cached prepared statement slow after 5 executions
Date: 2011-06-27 08:10:31
Message-ID: BANLkTik6OnWhKaxHVKb=DBHNLajD2uEd-Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 27 June 2011 07:50, Rob Gansevles <rgansevles(at)gmail(dot)com> wrote:
> I can confirm, when I call ps.setPrepareThreshold(1) the query is slow
> immediately, so the plan must be different with the server prepared
> statements.
>

You can confirm that from psql by doing

EXPLAIN ANALYSE SELECT ... ;

and then

PREPARE ps( ... ) AS SELECT ... ;
EXPLAIN ANALYSE EXECUTE ps ( ... ) ;

using your query and the parameters in question.

It is entirely possible that the plan chosen for the prepared
statement will be worse than the one used when the parameters are
known at planning time. The prepared statement doesn't know what
parameters are going to be used, so it can't always come up with the
best plan. See the notes in the PREPARE manual page:
http://www.postgresql.org/docs/9.0/static/sql-prepare.html

Regards,
Dean

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message mephysto 2011-06-27 09:33:27 Custom types as parameter in stored function
Previous Message Guillaume Lelarge 2011-06-27 07:24:30 Re: Anyone using silent_mode?