Re: prepared query performs much worse than regular query - Mailing list pgsql-performance

From Rosser Schwarz
Subject Re: prepared query performs much worse than regular query
Date
Msg-id AANLkTinxV_VP49IhTDOx3UThC7m_dqpUkqyXkNoPGZHB@mail.gmail.com
Whole thread Raw
In response to prepared query performs much worse than regular query  (Richard Yen <dba@richyen.com>)
List pgsql-performance
On Fri, May 21, 2010 at 4:53 PM, Richard Yen <dba@richyen.com> wrote:
> Any ideas why the query planner chooses a different query plan when using prepared statements?

A prepared plan is the best one the planner can come up with *in
general* for the query in question.  If the distribution of the values
you're querying against -- in your case, "owner" and "assignment" --
aren't relatively uniform, that plan is going to be suboptimal, if not
downright pathological, for the more outlying-ly distributed values.

Looking at your prepared plan, it seems that, on average, there are
177 rows for every "assignment", and 184 per "owner".  As it turns
out, though, nearly a quarter of your table has an "owner" of -1.
It's not terribly surprising, with a table that big and a distribution
skew of that magnitude, that this query plan, with these arguments,
ends up pretty firmly in the "pathological" category.

rls

--
:wq

pgsql-performance by date:

Previous
From: Richard Yen
Date:
Subject: prepared query performs much worse than regular query
Next
From: Matthew Wakeling
Date:
Subject: Re: prepared query performs much worse than regular query