From: Tom Lane <tgl@sss.pgh.pa.us>
To: Guillaume Smet <guillaume.smet@gmail.com>
Cc: Kevin McArthur <Kevin@stormtide.ca>
Cc: pgsql-performance@postgresql.org
Subject: Re: Bad Planner Statistics for Uneven distribution.
Date: Sat, 22 Jul 2006 13:03:58 -0400
Message-ID: <27058.1153587838@sss.pgh.pa.us> (raw)
In-Reply-To: <1d4e0c10607211500t62be09f2v8284ceb5176b01bc@mail.gmail.com>
References: <003b01c6acf1$a66d8910$0701a8c0@kdesktop>
<8073.1153517393@sss.pgh.pa.us>
<1d4e0c10607211500t62be09f2v8284ceb5176b01bc@mail.gmail.com>
"Guillaume Smet" <guillaume.smet@gmail.com> writes:
> Isn't there any way to make PostgreSQL have a better estimation here:
> -> Index Scan using models_brands_brand on models_brands
> (cost=0.00..216410.97 rows=92372 width=0) (actual time=0.008..0.008
> rows=0 loops=303)
> Index Cond: (brand = $0)
Note that the above plan extract is pretty misleading, because it
doesn't account for the implicit "LIMIT 1" of an EXISTS() clause.
What the planner is *actually* imputing to this plan is 216410.97/92372
cost units, or about 2.34. However that applies to the seqscan variant
as well.
I think the real issue with Kevin's example is that when doing an
EXISTS() on a brand_id that doesn't actually exist in the table, the
seqscan plan has worst-case behavior (ie, scan the whole table) while
the indexscan plan still manages to be cheap. Because his brands table
has so many brand_ids that aren't in the table, that case dominates the
results. Not sure how we could factor that risk into the cost
estimates. The EXISTS code could probably special-case it reasonably
well for the simplest seqscan and indexscan subplans, but I don't see
what to do with more general subqueries (like joins).
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, guillaume.smet@gmail.com, Kevin@stormtide.ca
Subject: Re: Bad Planner Statistics for Uneven distribution.
In-Reply-To: <27058.1153587838@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox