Re: Bad prepare performance

From: Cédric Villemain <cedric(dot)villemain(at)dalibo(dot)com>
To: Martin Kjeldsen <martin(at)martinkjeldsen(dot)dk>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Bad prepare performance
Date: 2008-04-01 07:53:36
Message-ID: 200804010953.42063.cedric.villemain@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi Martin, please CC the mailing-list,
then others can repply ;)

Cédric Villemain (13:59 2008-03-31):
> Le Monday 31 March 2008, Martin Kjeldsen a écrit :
> > I've done the same query on a 8.2.5 database. The first one is prepared
> > first and the other is executed directly.
> >
> > I understand why the there is such a great difference between the two ways
> > of executing the query (postgres has no way of knowing that $1 will be
> > quite big and that the result is not too big).
> >
> > I could just avoid using prepare statements, but this is done
automatically
> > with Perl's DBD::Pg. I know how to avoid using prepare statements (avoid
> > having placeholders in the statement), but that is not the prettiest of
> > work arounds.
>
> Did you saw this option :
>
> $sth = $dbh->prepare("SELECT id FROM mytable WHERE val = ?",
> { pg_server_prepare => 0 });
>
> Then, *this* query will not be prepared by the server.

This works very well. Thanks!

Still I regard this as a work around and the optimal solution would be to
allow the prepare statement to be prepared with an max(guid) is close to $1
hint or something like that.

I heard something about delayed prepare, where the prepared statements is
prepared on first use, this would solve my problem. Is this something being
work on right now?

Best regards

Martin Kjeldsen

Browse pgsql-performance by date

  From Date Subject
Next Message Sabin Coanda 2008-04-01 11:40:13 check performance parameters
Previous Message Tom Lane 2008-04-01 05:07:17 Re: POSIX file updates