Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A96AF65024D for ; Wed, 13 Aug 2008 17:58:43 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 11580-02 for ; Wed, 13 Aug 2008 17:58:37 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lists.commandprompt.com (host-159.commandprompt.net [207.173.203.159]) by postgresql.org (Postfix) with ESMTP id 2CE686501F1 for ; Wed, 13 Aug 2008 17:58:39 -0300 (ADT) Received: from perhan.alvh.no-ip.org (190-95-19-36.bk17-dsl.surnet.cl [190.95.19.36]) (authenticated bits=0) by lists.commandprompt.com (8.13.8/8.13.8) with ESMTP id m7DL1Mm8021708 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 13 Aug 2008 14:01:25 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 554B647C9A; Wed, 13 Aug 2008 16:58:30 -0400 (CLT) Date: Wed, 13 Aug 2008 16:58:30 -0400 From: Alvaro Herrera To: Chris Kratz Cc: Decibel! , pgsql-performance@postgresql.org Subject: Re: Incorrect estimates on correlated filters Message-ID: <20080813205830.GC4672@alvh.no-ip.org> References: <3642025c0808121459x75c8d9baq66194b87f5053ea3@mail.gmail.com> <12707C41-48C3-4072-A152-46FAB1FEE1E2@decibel.org> <3642025c0808131145x61b9aec5l2d9cb0268d28e9ff@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3642025c0808131145x61b9aec5l2d9cb0268d28e9ff@mail.gmail.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (lists.commandprompt.com [207.173.203.159]); Wed, 13 Aug 2008 14:01:26 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200808/158 X-Sequence-Number: 31039 Chris Kratz wrote: > Unfortunately, if I don't think the sorting idea would help in the one case > I'm looking at which involves filters on two tables that are joined > together. The filters happen to be correlated such that about 95% of the > rows from each filtered table are actually returned after the join. > Unfortunately, the planner thinks we will get 1 row back. Maybe you can wrap that part of the query in a SQL function and set its estimated cost to the real values with ALTER FUNCTION ... ROWS. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support