From: Matthew Wakeling <matthew@flymine.org>
To: pgsql-performance@postgresql.org
Subject: Re: prepared query performs much worse than regular query
Date: Fri, 21 May 2010 23:26:50 -0400 (EDT)
Message-ID: <alpine.DEB.2.00.1005212324070.2887@aragorn.flymine.org> (raw)
In-Reply-To: <0E6DA13D-D053-4CB8-A301-DC3607BBF146@richyen.com>
References: <0E6DA13D-D053-4CB8-A301-DC3607BBF146@richyen.com>
On Fri, 21 May 2010, Richard Yen wrote:
> Any ideas why the query planner chooses a different query plan when using prepared statements?
This is a FAQ. Preparing a statement makes Postgres create a plan, without
knowing the values that you will plug in, so it will not be as optimal as
if the values were available. The whole idea is to avoid the planning cost
each time the query is executed, but if your data is unusual it can
result in worse plans.
Matthew
--
Existence is a convenient concept to designate all of the files that an
executable program can potentially process. -- Fortran77 standard
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: matthew@flymine.org
Subject: Re: prepared query performs much worse than regular query
In-Reply-To: <alpine.DEB.2.00.1005212324070.2887@aragorn.flymine.org>
References: <0E6DA13D-D053-4CB8-A301-DC3607BBF146@richyen.com> <alpine.DEB.2.00.1005212324070.2887@aragorn.flymine.org>
* 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