Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DD94063350C for ; Mon, 22 Mar 2010 09:40:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 66092-09 for ; Mon, 22 Mar 2010 12:40:11 +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 3EC636324E2 for ; Mon, 22 Mar 2010 09:40:19 -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 o2MCeDIV016238; Mon, 22 Mar 2010 08:40:13 -0400 (EDT) To: Matthew Wakeling cc: Stephen Frost , Corin , pgsql-performance@postgresql.org Subject: Re: too complex query plan for not exists query and multicolumn indexes In-reply-to: References: <4BA36D7B.6010506@gmail.com> <20100319182750.GQ21875@tamriel.snowman.net> Comments: In-reply-to Matthew Wakeling message dated "Mon, 22 Mar 2010 11:48:44 -0000" Date: Mon, 22 Mar 2010 08:40:12 -0400 Message-ID: <16237.1269261612@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.461 tagged_above=-10 required=5 tests=AWL=0.138, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/270 X-Sequence-Number: 38095 Matthew Wakeling writes: > On Fri, 19 Mar 2010, Stephen Frost wrote: >> ...it has to go to an external on-disk sort (see later on, and how to >> fix that). > This was covered on this list a few months ago, in > http://archives.postgresql.org/pgsql-performance/2009-08/msg00184.php and > http://archives.postgresql.org/pgsql-performance/2009-08/msg00189.php > There seemed to be some consensus that allowing a materialise in front of > an index scan might have been a good change. Was there any movement on > this front? Yes, 9.0 will consider plans like Merge Join (cost=0.00..14328.70 rows=1000000 width=488) Merge Cond: (a.four = b.hundred) -> Index Scan using fouri on tenk1 a (cost=0.00..1635.62 rows=10000 width=244) -> Materialize (cost=0.00..1727.16 rows=10000 width=244) -> Index Scan using tenk1_hundred on tenk1 b (cost=0.00..1702.16 rows =10000 width=244) Some experimentation shows that it won't insert the materialize unless quite a bit of re-fetching is predicted (ie neither side of the join is unique). We might need to tweak the cost parameters once we get some field experience with it. regards, tom lane