Re: Planner picks the wrong plan?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nichlas Löfdahl <crotalus(at)acc(dot)umu(dot)se>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Planner picks the wrong plan?
Date: 2004-10-06 03:29:56
Message-ID: 20687.1097033396@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Nichlas =?iso-8859-1?Q?L=F6fdahl?= <crotalus(at)acc(dot)umu(dot)se> writes:
> My question is, why doesn't the planner pick the same plan for Q1 & Q3?

I think it's mostly that after you've added and ANALYZEd the "age"
column, the planner has a pretty good idea of how many rows will pass
the "age > 17 AND age < 20" condition. It can't do very much with the
equivalent condition in the original form, though, and in fact ends up
drastically underestimating the number of matching rows (86 vs reality
of 3021). That leads directly to a bad plan choice :-(

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Alan Stange 2004-10-06 03:59:10 Re: Excessive context switching on SMP Xeons
Previous Message Max Baker 2004-10-06 03:24:46 test post