Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 5C2829FBCB6 for ; Wed, 9 May 2007 11:29:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 96782-02-6 for ; Wed, 9 May 2007 11:29:23 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id 290DC9FC066 for ; Wed, 9 May 2007 11:29:22 -0300 (ADT) Received: from perhan.alvh.no-ip.org (201-221-217-243.bk12-dsl.surnet.cl [201.221.217.243]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l49ETHMN031229; Wed, 9 May 2007 07:29:18 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id AEDFC32A0F; Wed, 9 May 2007 10:29:14 -0400 (CLT) Date: Wed, 9 May 2007 10:29:14 -0400 From: Alvaro Herrera To: Peter Eisentraut Cc: pgsql-performance@postgresql.org Subject: Re: Apparently useless bitmap scans Message-ID: <20070509142914.GD4504@alvh.no-ip.org> References: <200705091410.57312.peter_e@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200705091410.57312.peter_e@gmx.net> User-Agent: Mutt/1.5.13 (2006-08-11) X-Virus-Scanned: ClamAV version 0.88.5, clamav-milter version 0.88.5 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Wed, 09 May 2007 07:29:20 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/192 X-Sequence-Number: 24582 Peter Eisentraut wrote: > There's another odd thing about this plan from yesterday. Is this still 8.2.1? The logic to choose bitmap indexes was rewritten just before 8.2.4, 2007-04-17 16:03 tgl * src/backend/optimizer/path/indxpath.c: Rewrite choose_bitmap_and() to make it more robust in the presence of competing alternatives for indexes to use in a bitmap scan. The former coding took estimated selectivity as an overriding factor, causing it to sometimes choose indexes that were much slower to scan than ones with a slightly worse selectivity. It was also too narrow-minded about which combinations of indexes to consider ANDing. The rewrite makes it pay more attention to index scan cost than selectivity; this seems sane since it's impossible to have very bad selectivity with low cost, whereas the reverse isn't true. Also, we now consider each index alone, as well as adding each index to an AND-group led by each prior index, for a total of about O(N^2) rather than O(N) combinations considered. This makes the results much less dependent on the exact order in which the indexes are considered. It's still a lot cheaper than an O(2^N) exhaustive search. A prefilter step eliminates all but the cheapest of those indexes using the same set of WHERE conditions, to keep the effective value of N down in scenarios where the DBA has created lots of partially-redundant indexes. -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.