Re: Why hash join instead of nested loop?

From: Rhett Garber <rhettg(at)gmail(dot)com>
To: Havasvölgyi Ottó <h(dot)otto(at)freemail(dot)hu>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Why hash join instead of nested loop?
Date: 2005-08-05 23:16:51
Message-ID: 41b0fe8905080516164464e04f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 8/5/05, Havasvölgyi Ottó <h(dot)otto(at)freemail(dot)hu> wrote:

> Please post the explain analyze for both queries. From that we can see the
> predicted and the actual costs of them.

> select rtmessagestate.* from rtmessagestate, connection where
> connection_registry_id = 40105 and obj1 = 73582 and obj2 =
> rtmessagestate.id;

Hash Join (cost=5.96..7.04 rows=1 width=14) (actual
time=10.591..10.609 rows=1 loops=1)
Hash Cond: ("outer".id = "inner".obj2)
-> Seq Scan on rtmessagestate (cost=0.00..1.05 rows=5 width=14)
(actual time=0.011..0.022 rows=5 loops=1)
-> Hash (cost=5.96..5.96 rows=1 width=4) (actual
time=0.109..0.109 rows=0 loops=1)
-> Index Scan using connection_regid_obj1_index on
connection (cost=0.00..5.96 rows=1 width=4) (actual time=0.070..0.076
rows=1 loops=1)
Index Cond: ((connection_registry_id = 40105) AND (obj1
= 73582)) Total runtime: 11.536 ms
(7 rows)

> select rtmessage.id, subject from rtmessage, connection where
> connection_registry_id = 40003 and obj1 = 4666 and obj2 =
> rtmessage.id;

Nested Loop (cost=0.00..11.62 rows=2 width=38) (actual
time=0.186..0.970 rows=12 loops=1)
-> Index Scan using connection_regid_obj1_index on connection
(cost=0.00..5.96 rows=1 width=4) (actual time=0.109..0.308 rows=12
loops=1)
Index Cond: ((connection_registry_id = 40003) AND (obj1 = 4666))
-> Index Scan using rtmessage_pkey on rtmessage (cost=0.00..5.65
rows=1 width=38) (actual time=0.032..0.039 rows=1 loops=12)
Index Cond: ("outer".obj2 = rtmessage.id)
Total runtime: 1.183 ms
(6 rows)

Rhett

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2005-08-06 05:03:51 Re: Why hash join instead of nested loop?
Previous Message Havasvölgyi Ottó 2005-08-05 22:13:49 Re: Why hash join instead of nested loop?