Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 187AC2E0152 for ; Sat, 8 Mar 2008 16:26:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 39807-04 for ; Sat, 8 Mar 2008 16:26:20 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mail01.enterprisedb.com (mail01.enterprisedb.com [63.246.7.168]) by postgresql.org (Postfix) with ESMTP id C055D2E0105 for ; Sat, 8 Mar 2008 16:26:19 -0400 (AST) thread-index: AciBWr+n01qcxCo8Q6WzgRPW+pFF6w== Received: from [192.168.2.10] ([86.0.104.222]) by mail01.enterprisedb.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Sat, 8 Mar 2008 15:26:53 -0500 Content-Class: urn:content-classes:message Importance: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133 Message-ID: <47D2F625.4050700@enterprisedb.com> Date: Sat, 08 Mar 2008 20:25:09 +0000 From: "Heikki Linnakangas" Organization: EnterpriseDB User-Agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080110) MIME-Version: 1.0 To: "Kynn Jones" Cc: Subject: Re: Joins and DELETE FROM References: <47D2D485.9040103@enterprisedb.com> In-Reply-To: Content-Type: text/plain; format=flowed; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 08 Mar 2008 20:26:54.0203 (UTC) FILETIME=[BF9FF4B0:01C8815A] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/186 X-Sequence-Number: 29140 Kynn Jones wrote: > my_db=> SET ENABLE_SEQSCAN TO OFF; > my_db=> EXPLAIN ANALYZE SELECT * FROM T NATURAL JOIN B; > QUERY PLAN > --------------------------------------------------------------------------------------------------------------------------------------- > Merge Join (cost=0.00..423589.69 rows=219784 width=13) (actual time= > 0.114..5449.808 rows=219784 loops=1) > Merge Cond: (t.k = b.k) > -> Index Scan using idx__t on t (cost=0.00..386463.71 rows=10509456 > width=13) (actual time=0.059..3083.182 rows=10509414 loops=1) > -> Index Scan using idx__b on b (cost=0.00..8105.04 rows=219784 > width=12) (actual time=0.044..69.659 rows=219784 loops=1) > Total runtime: 5473.812 ms > (5 rows) That's more like 2% of the rows, not 0.1%. Note that this still isn't the plan you were asking for, it's still scanning the whole index for t, not just looking up the keys from b. What you wanted is a nested loop join. You could try to turn enable_mergejoin=off as well if you want to coerce the planner even more... -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com