From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Andrew Sullivan <andrew(at)libertyrms(dot)info> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: strange estimate for number of rows |
Date: | 2003-11-13 18:56:26 |
Message-ID: | 5882.1068749786@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Andrew Sullivan <andrew(at)libertyrms(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Arthur Ward | 2003-11-13 19:19:07 | Re: Union+group by planner estimates way off? |
Previous Message | Tom Lane | 2003-11-13 18:46:51 | Re: Union+group by planner estimates way off? |