Re: [HACKERS] why is postgres estimating so badly?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Luis Alberto Amigo Navarro" <lamigo(at)atc(dot)unican(dot)es>
Cc: pgsql-sql(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] why is postgres estimating so badly?
Date: 2002-07-17 17:43:50
Message-ID: 15637.1026927830@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

"Luis Alberto Amigo Navarro" <lamigo(at)atc(dot)unican(dot)es> writes:
> -> Seq Scan on part (cost=0.00..12399.00 rows=1 width=4) (actual time=24.88..4076.81 rows=10856 loops=1)

Seems like the major misestimation is above: the LIKE clause on part is
estimated to select just one row, but it selects 10856 of 'em. Had the
planner realized the number of returned rows would be in the thousands,
it'd likely have used quite a different plan structure.

> AND part.name LIKE '%green%'

It's difficult for the planner to produce a decent estimate for the
selectivity of an unanchored LIKE clause, since there are no statistics
it can use for the purpose. We recently changed FIXED_CHAR_SEL in
src/backend/utils/adt/selfuncs.c from 0.04 to 0.20, which would make
this particular case come out better. (I believe the estimate would
work out to about 320, if part is 200K rows; that should be enough to
produce at least some change of plan.) You could try patching your
local installation likewise.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Neil Conway 2002-07-17 18:27:39 error codes
Previous Message Nathan C. Burnett 2002-07-17 17:04:04 Re: [HACKERS] why is postgres estimating so badly?

Browse pgsql-sql by date

  From Date Subject
Next Message Ligia Pimentel 2002-07-17 22:27:33 Re: How to find out if an index is unique?
Previous Message Stephan Szabo 2002-07-17 17:09:02 Re: Cascading deletions does not seem to work inside PL/PGSQL