From: Dave Dutcher <dave@tridecap.com>
To: 'Ow Mun Heng' <Ow.Mun.Heng@wdc.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: PostgreSQL vs MySQL, and FreeBSD
Date: Fri, 16 Nov 2007 09:56:28 -0600
Message-ID: <01c601c82869$3ffb2580$8e00a8c0@tridecap.com> (raw)
In-Reply-To: <1195206185.29253.56.camel@neuromancer.home.net>
References: <47344D43.5090506@geri.cc.fer.hr>
<47347F9F.1070309@laliluna.de>
<1195206185.29253.56.camel@neuromancer.home.net>
> -----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.)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: dave@tridecap.com, Ow.Mun.Heng@wdc.com
Subject: Re: PostgreSQL vs MySQL, and FreeBSD
In-Reply-To: <01c601c82869$3ffb2580$8e00a8c0@tridecap.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox