X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id EC188D1B522 for ; Thu, 13 Nov 2003 18:56:58 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 05355-09 for ; Thu, 13 Nov 2003 14:56:28 -0400 (AST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id E78D4D1B50E for ; Thu, 13 Nov 2003 14:56:26 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id hADIuR19005883; Thu, 13 Nov 2003 13:56:27 -0500 (EST) To: Andrew Sullivan Cc: pgsql-performance@postgresql.org Subject: Re: strange estimate for number of rows In-reply-to: <20031113181415.GB25546@libertyrms.info> References: <20031113181415.GB25546@libertyrms.info> Comments: In-reply-to Andrew Sullivan message dated "Thu, 13 Nov 2003 13:14:15 -0500" Date: Thu, 13 Nov 2003 13:56:26 -0500 Message-ID: <5882.1068749786@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/96 X-Sequence-Number: 4656 Andrew Sullivan 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