From: | Rosser Schwarz <rosser(dot)schwarz(at)gmail(dot)com> |
---|---|
To: | Richard Yen <dba(at)richyen(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: prepared query performs much worse than regular query |
Date: | 2010-05-22 00:30:23 |
Message-ID: | AANLkTinxV_VP49IhTDOx3UThC7m_dqpUkqyXkNoPGZHB@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Fri, May 21, 2010 at 4:53 PM, Richard Yen <dba(at)richyen(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Matthew Wakeling | 2010-05-22 03:26:50 | Re: prepared query performs much worse than regular query |
Previous Message | Richard Yen | 2010-05-21 22:53:41 | prepared query performs much worse than regular query |