Received: from localhost (uranus.hub.org [200.46.204.60]) by postgresql.org (Postfix) with ESMTP id 6D6A89FB2FD for ; Fri, 10 Nov 2006 02:50:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.60]) (amavisd-new, port 10024) with ESMTP id 91197-01-5 for ; Fri, 10 Nov 2006 02:50:55 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 9343E9FB31F for ; Fri, 10 Nov 2006 02:15:28 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kAA6FO97016548; Fri, 10 Nov 2006 01:15:24 -0500 (EST) To: Abhijit Menon-Sen cc: pgsql-performance@postgresql.org, arnt@oryx.com Subject: Re: 10x rowcount mis-estimation favouring merge over nestloop In-reply-to: <20061110051245.GA1928@penne.toroid.org> References: <20061110051245.GA1928@penne.toroid.org> Comments: In-reply-to Abhijit Menon-Sen message dated "Fri, 10 Nov 2006 10:42:45 +0530" Date: Fri, 10 Nov 2006 01:15:24 -0500 Message-ID: <16547.1163139324@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200611/93 X-Sequence-Number: 21863 Abhijit Menon-Sen writes: > The header_fields table contains 13.5M rows, of which only ~250K match > the where condition. I created an index like this: > create index hffpv on header_fields(field) > where field<=12 and (part!='' or value ilike '%,%') > Note the 2M estimated rowcount in the bitmap index scan on header_fields > vs. the actual number (264180). I think this is basically a lack-of-column-correlation-stats problem. The planner is estimating this on the basis of the overall selectivity of the "field<=12" condition, but it seems that "field<=12" is true for a much smaller fraction of the rows satisfying (part!='' or value ilike '%,%') than for the general population of rows in the header_fields table. There's been some speculation about obtaining stats on partial indexes as a substitute for solving the general problem of correlation stats, but I for one don't have a very clear understanding of how it'd work. regards, tom lane