From: | "Dave Dutcher" <dave(at)tridecap(dot)com> |
---|---|
To: | "'Ow Mun Heng'" <Ow(dot)Mun(dot)Heng(at)wdc(dot)com> |
Cc: | <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: PostgreSQL vs MySQL, and FreeBSD |
Date: | 2007-11-16 15:56:28 |
Message-ID: | 01c601c82869$3ffb2580$8e00a8c0@tridecap.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
> -----Original Message-----
> From: Ow Mun Heng
> Subject: Re: [PERFORM] PostgreSQL vs MySQL, and FreeBSD
>
> Even for Postgresql, nested loops are still evil and hampers
> performance.
I don't know about that. There are times when it is the right plan:
explain analyze select * from table1 t1 inner join table2 t2 on t1.f_id =
t2.id where t1.id = 'xyzzy';
QUERY PLAN
----------------------------------------------------------------------------
----------------------------------------------------------------
Nested Loop (cost=0.00..17.65 rows=1 width=344) (actual time=0.080..0.096
rows=1 loops=1)
-> Index Scan using table1_pkey on table1 t (cost=0.00..9.18 rows=1
width=238) (actual time=0.044..0.048 rows=1 loops=1)
Index Cond: ((id)::text = 'xyzzy'::text)
-> Index Scan using table2_pkey on table2 i (cost=0.00..8.46 rows=1
width=106) (actual time=0.019..0.023 rows=1 loops=1)
Index Cond: (t.f_id = i.id)
Total runtime: 0.224 ms
set enable_nestloop=off;
SET
explain analyze select * from table1 t1 inner join table2 t2 on t1.f_id =
t2.id where t1.id = 'xyzzy';
QUERY PLAN
----------------------------------------------------------------------------
------------------------------------------------------------
Hash Join (cost=9.18..72250.79 rows=1 width=344) (actual
time=13493.572..15583.049 rows=1 loops=1)
Hash Cond: (i.id = t.f_id)
-> Seq Scan on table2 i (cost=0.00..61297.40 rows=2188840 width=106)
(actual time=0.015..8278.347 rows=2188840 loops=1)
-> Hash (cost=9.18..9.18 rows=1 width=238) (actual time=0.056..0.056
rows=1 loops=1)
-> Index Scan using table1_pkey on table1 t (cost=0.00..9.18
rows=1 width=238) (actual time=0.040..0.045 rows=1 loops=1)
Index Cond: ((id)::text = 'xyzzy'::text)
Total runtime: 15583.212 ms
(I changed the table names, but everything else is real.)
From | Date | Subject | |
---|---|---|---|
Next Message | Brad Nicholson | 2007-11-16 15:56:48 | Re: Curious about dead rows. |
Previous Message | tv | 2007-11-16 13:38:23 | Re: autovacuum: recommended? |