Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B77B46325A2 for ; Thu, 29 Jul 2010 04:29:38 -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 45251-07 for ; Thu, 29 Jul 2010 07:29:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-px0-f174.google.com (mail-px0-f174.google.com [209.85.212.174]) by mail.postgresql.org (Postfix) with ESMTP id 1AC30633112 for ; Thu, 29 Jul 2010 04:29:30 -0300 (ADT) Received: by pxi14 with SMTP id 14so12714pxi.19 for ; Thu, 29 Jul 2010 00:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=8GpXQiy/2oLZA4P7Rfsh5bWys3LcZWq6L/Ma+uC1UoU=; b=FwQHROQwwZiLIFv+bAW8fxizWV96VB5HkCGXbQcCkpy72111MyfuuX6yUS0qmpnFnG sIRKZ0HY6yMo2XbXPk6B4hnPoFHYTRobqKlvyt/wuCTtTrCHL7PO1aZdEhZCIT5zZRL9 fQ7FdQT66EziXznN9QJoFI2nV9sT02gznQBHo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=ZqI7aBjcFCi3GxAtU4fzpmW8Q4vr0vw4+rnpGIYG9onlWWp3dy1TRddn3JVMdS8hGX psxsyRsK3qdEXkfEGQoZSBoFXgRR4dAywD8shzhIpJfDSizbyfYryY/XaVCxqhZhRq8b ti6ZcF5PJzJ93kodEA/Ik5FLOhi1VCTm+MGYQ= Received: by 10.114.127.18 with SMTP id z18mr16847467wac.171.1280388569545; Thu, 29 Jul 2010 00:29:29 -0700 (PDT) Received: from [192.168.2.65] (ppp234-39.static.internode.on.net [59.167.234.39]) by mx.google.com with ESMTPS id d39sm940360wam.16.2010.07.29.00.29.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 29 Jul 2010 00:29:28 -0700 (PDT) Message-ID: <4C512DD3.9030201@gmail.com> Date: Thu, 29 Jul 2010 17:29:23 +1000 From: Chris User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: Tom Lane CC: PostgreSQL Performance Subject: Re: planner index choice References: <4C50D07D.4040004@gmail.com> <628.1280375626@sss.pgh.pa.us> In-Reply-To: <628.1280375626@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201007/444 X-Sequence-Number: 39833 Hi, > Hrm ... are you *certain* that's an 8.4 server? Yep. # psql -U postgres -d db psql (8.4.4) db=# select version(); version ------------------------------------------------------------------------------------------------------------------ PostgreSQL 8.4.4 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48), 64-bit (1 row) > 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... I just recreated the index and re-ran the explain analyze and it doesn't give the "outer" bit any more - not sure how I got that before. db=# begin; BEGIN db=# create index attr_val_contextid on sq_ast_attr_val(contextid); CREATE INDEX db=# analyze sq_ast_attr_val; ANALYZE db=# explain analyze SELECT db-# assetid, custom_val db-# FROM db-# sq_ast_attr_val db-# WHERE db-# attrid IN (SELECT attrid FROM sq_ast_attr WHERE name = db(# 'is_contextable' AND (type_code = 'metadata_field_select' OR db(# owning_type_code = 'metadata_field')) db-# AND contextid = 0 db-# INTERSECT db-# SELECT db-# assetid, custom_val db-# FROM db-# sq_ast_attr_val db-# WHERE db-# assetid = '62321' db-# AND contextid = 0; http://explain.depesz.com/s/br9 Without that index (again with an analyze after doing a rollback): http://explain.depesz.com/s/gxH -- Postgresql & php tutorials http://www.designmagick.com/