From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Sullivan <andrew@libertyrms.info>
Cc: pgsql-performance@postgresql.org
Subject: Re: strange estimate for number of rows
Date: Thu, 13 Nov 2003 13:56:26 -0500
Message-ID: <5882.1068749786@sss.pgh.pa.us> (raw)
In-Reply-To: <20031113181415.GB25546@libertyrms.info>
References: <20031113181415.GB25546@libertyrms.info>
Andrew Sullivan <andrew@libertyrms.info> writes:
> The statistics on transaction_date and product_id are set to 1000.
> Everything is all analysed nicely. But I'm getting a poor plan,
> because of an estimate that the number of rows to be returned is
> about double how many actually are:
> explain analyse select * from transactions_posted where
> transaction_date >= '2003-9-1' and transaction_date < '2003-10-1' and
> product_id = 2;
Are the estimates accurate for queries on the two columns individually,
ie
... where transaction_date >= '2003-9-1' and transaction_date < '2003-10-1'
... where product_id = 2
If so, the problem is that there's a correlation between
transaction_date and product_id, which the system cannot model because
it has no multi-column statistics.
However, given that the estimate is only off by about a factor of 2,
you'd still be getting the wrong plan even if the estimate were perfect,
because the estimated costs differ by nearly a factor of 3.
Given the actual runtimes, I'm thinking maybe you want to reduce
random_page_cost. What are you using for that now?
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, andrew@libertyrms.info
Subject: Re: strange estimate for number of rows
In-Reply-To: <5882.1068749786@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