Re: Searching for the cause of a bad plan

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Csaba Nagy <nagy(at)ecircle-ag(dot)com>, postgres performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Searching for the cause of a bad plan
Date: 2007-09-21 18:37:59
Message-ID: 1190399879.4202.127.camel@ebony.site
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Fri, 2007-09-21 at 13:53 -0400, Tom Lane wrote:
> Simon Riggs <simon(at)2ndquadrant(dot)com> writes:
> > On Fri, 2007-09-21 at 12:08 -0400, Tom Lane wrote:
> >> The reason you get a bad plan is that this rowcount estimate is so far
> >> off:
>
> > That's true, but its not relevant,
>
> Yes it is --- the reason it wants to use a hashjoin instead of a
> nestloop is exactly that it thinks the loop would iterate too many
> times. (Ten is already too many in this case --- if it had estimated
> five rows out of the join, it'd have gone with the nestloop, since
> the cost estimate difference at the top level is less than 2x.)

That's not my perspective. If the LIMIT had been applied accurately to
the cost then the hashjoin would never even have been close to the
nested join in the first place. It's just chance that the frequency
distribution is favourable to us and thus amenable to using the hint of
improving stats_target. The improved knowledge of the distribution just
hides the fact that the cost model is still wrong: a cost of 45000 per
row shows this.

--
Simon Riggs
2ndQuadrant http://www.2ndQuadrant.com

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message brauagustin-susc 2007-09-21 19:01:34 Re: Low CPU Usage
Previous Message Bill Moran 2007-09-21 18:33:54 Re: Low CPU Usage