Skip site navigation (1) Skip section navigation (2)

Re: Joins and DELETE FROM

From: "Heikki Linnakangas" <heikki(at)enterprisedb(dot)com>
To: "Kynn Jones" <kynnjo(at)gmail(dot)com>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Joins and DELETE FROM
Date: 2008-03-08 20:25:09
Message-ID: 47D2F625.4050700@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-performance
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

In response to

pgsql-performance by date

Next:From: ChrisDate: 2008-03-09 23:42:33
Subject: Re: join query performance
Previous:From: Tom LaneDate: 2008-03-08 20:08:46
Subject: Re: Joins and DELETE FROM

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group