Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 22926632CCC for ; Mon, 15 Feb 2010 13:26:41 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 20686-09 for ; Mon, 15 Feb 2010 17:26:30 +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 9634C632B84 for ; Mon, 15 Feb 2010 13:26:30 -0400 (AST) 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 o1FHQTqF001377; Mon, 15 Feb 2010 12:26:29 -0500 (EST) To: Ben Chobot cc: "Kevin Grittner" , pgsql-performance@postgresql.org Subject: Re: 8.1 -> 8.4 regression In-reply-to: <8D572A50-01C7-464B-8D0D-FCF19C53BC9C@silentmedia.com> References: <4B791AFF020000250002F2DD@gw.wicourts.gov> <8D572A50-01C7-464B-8D0D-FCF19C53BC9C@silentmedia.com> Comments: In-reply-to Ben Chobot message dated "Mon, 15 Feb 2010 08:16:04 -0800" Date: Mon, 15 Feb 2010 12:26:28 -0500 Message-ID: <1376.1266254788@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/243 X-Sequence-Number: 37664 Ben Chobot writes: > On Feb 15, 2010, at 7:59 AM, Kevin Grittner wrote: >> Could you show the query, along with table definitions (including >> indexes)? > Oh, yeah, I suppose that would help. :) > http://wood.silentmedia.com/bench/query_and_definitions It looks like the problem is that the EXISTS sub-query is getting converted into a join; which is usually a good thing but in this case it interferes with letting the users table not be scanned completely. The long-term fix for that is to support nestloop inner indexscans where the index key comes from more than one join level up, but making that happen isn't too easy. In the meantime, I think you could defeat the "optimization" by inserting LIMIT 1 in the EXISTS sub-query. regards, tom lane