Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id F11641337B67 for ; Tue, 9 Nov 2010 20:08:08 -0400 (AST) 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 22376-02 for ; Wed, 10 Nov 2010 00:08:01 +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 C9C361337BA1 for ; Tue, 9 Nov 2010 20:08:00 -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 oAA080Uq020962; Tue, 9 Nov 2010 19:08:00 -0500 (EST) To: "Kevin Grittner" cc: pgsql-performance@postgresql.org Subject: Re: anti-join chosen even when slower than old plan In-reply-to: <4CD9663502000025000374B1@gw.wicourts.gov> References: <4CD9663502000025000374B1@gw.wicourts.gov> Comments: In-reply-to "Kevin Grittner" message dated "Tue, 09 Nov 2010 15:18:13 -0600" Date: Tue, 09 Nov 2010 19:08:00 -0500 Message-ID: <20961.1289347680@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: 201011/128 X-Sequence-Number: 41152 "Kevin Grittner" writes: > The semi-join and anti-join have helped us quite a bit, but we have > seen a situation where anti-join is chosen even though it is slower > than the "old fashioned" plan. I know there have been other reports > of this, but I just wanted to go on record with my details. In principle, the old-style plan ought to be equivalent to a nestloop antijoin with a seqscan of DbTranLogRecord on the outside and an indexscan of DbTranRepository on the inside. Can you force it to choose such a plan by setting enable_mergejoin off (and maybe enable_hashjoin too)? If so, it'd be interesting to see the estimated costs and actual runtime on 9.0 for that plan. It would also be interesting to check estimated and actual costs for the SELECT COUNT(*) versions of these queries, ie, no actual delete. I'm suspicious that the cost differential has nothing to do with antijoin vs. subplan, and everything to do with whether the targeted tuples are being deleted in physical order (thus improving locality of access for the deletions). If it's the latter, see previous discussions about possibly sorting update/delete targets by CTID before applying the actions. regards, tom lane