Re: Joins and DELETE FROM - Mailing list pgsql-performance

From Heikki Linnakangas
Subject Re: Joins and DELETE FROM
Date
Msg-id 47D2F625.4050700@enterprisedb.com
Whole thread Raw
In response to Re: Joins and DELETE FROM  ("Kynn Jones" <kynnjo@gmail.com>)
List 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

pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Joins and DELETE FROM
Next
From: Miguel Arroz
Date:
Subject: UPDATE 66k rows too slow