Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 0FAAB632559 for ; Wed, 21 Jan 2009 10:31:44 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 30001-05-2 for ; Wed, 21 Jan 2009 10:31:32 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from lists.commandprompt.com (host-159.commandprompt.net [207.173.203.159]) by mail.postgresql.org (Postfix) with ESMTP id DD00F63256F for ; Wed, 21 Jan 2009 10:30:07 -0400 (AST) Received: from perhan.alvh.no-ip.org (200-85-214-61.bk4-dsl.surnet.cl [200.85.214.61]) (authenticated bits=0) by lists.commandprompt.com (8.13.8/8.13.8) with ESMTP id n0LEYHp3000982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 21 Jan 2009 06:34:21 -0800 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 6A86947CD9; Wed, 21 Jan 2009 11:28:29 -0300 (CLST) Date: Wed, 21 Jan 2009 11:28:29 -0300 From: Alvaro Herrera To: Michael Monnerie Cc: pgsql-admin@postgresql.org Subject: Re: Question on Index usage Message-ID: <20090121142829.GE4038@alvh.no-ip.org> References: <200901210854.28091@zmi.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200901210854.28091@zmi.at> 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, 21 Jan 2009 06:34:21 -0800 (PST) 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: 200901/84 X-Sequence-Number: 31131 Michael Monnerie wrote: > EXPLAIN ANALYZE SELECT 1 FROM dbmail_messages msg JOIN > dbmail_physmessage pm ON ( pm.id = msg.physmessage_id ) WHERE > message_idnr BETWEEN 3178782 AND 3616157 AND mailbox_idnr = 3236 AND > status IN (0,1,2) ORDER BY message_idnr ASC; [...] > -> Bitmap Heap Scan on dbmail_messages msg > (cost=145.12..3330.99 rows=4650 width=16) (actual time=50.689..60.132 > rows=5228 loops=1) > Recheck Cond: (mailbox_idnr = 3236) > Filter: ((message_idnr >= 3178782) AND (message_idnr <= > 3616157) AND (status = ANY ('{0,1,2}'::integer[]))) > -> Bitmap Index Scan on dbmail_messages_7 > (cost=0.00..143.96 rows=5288 width=0) (actual time=50.628..50.628 > rows=15759 loops=1) > Index Cond: (mailbox_idnr = 3236) > -> Hash (cost=4008.37..4008.37 rows=230637 width=8) (actual > time=669.219..669.219 rows=229809 loops=1) [...] > So while with the _1 index an "Index Scan" is used, with the _7 it needs > a "Bitmap Index Scan" plus a "Bitmap Heap Scan". Can somebody explain > why the _1 index cannot be deleted without loosing performance? The > plain "Index Scan" could be used with _7 or _8 anyway. Seems like the problem is that it is not pushing the "status IN" condition as part of the index condition for some reason, and instead using it as a filter. Maybe something to do with the selectivity of that clause? -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support