Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 830F71337BC4 for ; Wed, 10 Nov 2010 11:36:03 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 81772-01 for ; Wed, 10 Nov 2010 15:35:58 +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 4B2C51337C59 for ; Wed, 10 Nov 2010 11:33:22 -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 oAAFXMns004062; Wed, 10 Nov 2010 10:33:22 -0500 (EST) To: "Kevin Grittner" cc: pgsql-performance@postgresql.org Subject: Re: anti-join chosen even when slower than old plan In-reply-to: <4CDA62C60200002500037512@gw.wicourts.gov> References: <4CD9663502000025000374B1@gw.wicourts.gov><4CD9663502000025000374B1@gw.wicourts.gov> <20961.1289347680@sss.pgh.pa.us> <4CDA62C60200002500037512@gw.wicourts.gov> Comments: In-reply-to "Kevin Grittner" message dated "Wed, 10 Nov 2010 09:15:50 -0600" Date: Wed, 10 Nov 2010 10:33:22 -0500 Message-ID: <4061.1289403202@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/137 X-Sequence-Number: 41161 "Kevin Grittner" writes: > Tom Lane wrote: >> 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)? > Well, I got what I think is the equivalent plan by adding OFFSET 0 > to the subquery: No, that *is* the old-style plan (plus a useless Limit node, which will surely make it marginally slower). My point was that a nestloop antijoin plan should have the same access pattern and hence very similar performance, maybe even a little better due to not having the SubPlan machinery in there. > But wait -- it turns out that this pain was self-inflicted. Based > on heavy testing of the interactive queries which users run against > this database we tuned the database for "fully-cached" settings, > with both random_page_cost and _seq_page_cost at 0.1. Ah. So it was underestimating the cost of the full-table indexscans, and my guess about nonsequential application of the delete actions wasn't the right guess. The merge antijoin does seem like it should be the fastest way of doing such a large join, so I think the problem is solved. regards, tom lane