Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id DB3356322E8 for ; Thu, 29 Jul 2010 00:53:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 21935-05 for ; Thu, 29 Jul 2010 03:53:49 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 002A36322DA for ; Thu, 29 Jul 2010 00:53:48 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o6T3rkGi000629; Wed, 28 Jul 2010 23:53:46 -0400 (EDT) To: Chris cc: PostgreSQL Performance Subject: Re: planner index choice In-reply-to: <4C50D07D.4040004@gmail.com> References: <4C50D07D.4040004@gmail.com> Comments: In-reply-to Chris message dated "Thu, 29 Jul 2010 10:51:09 +1000" Date: Wed, 28 Jul 2010 23:53:46 -0400 Message-ID: <628.1280375626@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/443 X-Sequence-Number: 39832 Chris writes: > The query: > SELECT > assetid, custom_val > FROM > sq_ast_attr_val > WHERE > attrid IN (SELECT attrid FROM sq_ast_attr WHERE name = > 'is_contextable' AND (type_code = 'metadata_field_select' OR > owning_type_code = 'metadata_field')) > AND contextid = 0 > INTERSECT > SELECT > assetid, custom_val > FROM > sq_ast_attr_val > WHERE > assetid = '62321' > AND contextid = 0; > The explain analyze plan: > http://explain.depesz.com/s/nWs Hrm ... are you *certain* that's an 8.4 server? Because the bit with Index Cond: (sq_ast_attr_val.attrid = "outer".attrid) is a locution that EXPLAIN hasn't used since 8.1, according to a quick check. More recent versions don't say "outer". The actual problem seems to be that choose_bitmap_and() is choosing to add an indexscan on sq_ast_attr_val_contextid, even though this index is a lot less selective than the sq_ast_attr_val_attrid scan it had already picked. I've seen that behavior before, and there were a series of patches back in 2006-2007 that seem to have pretty much fixed it. So that's another reason for suspecting you've got an old server version there... regards, tom lane