Re: estimates for nested loop very wrong?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: joostje(at)komputilo(dot)org
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: estimates for nested loop very wrong?
Date: 2003-04-10 14:17:09
Message-ID: 3742.1049984229@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

joostje(at)komputilo(dot)org writes:
> When JOINing two tabels (one with 23 entries, one with 2.5e6 entries),
> psql estimates the cost of the nested loop method way to high, causing
> it to use Hash Join, even though Hash Join actually takes 30 seconds,
> agianst 0.020 seconds for Nested Loop.

Have you done an ANALYZE or VACUUM ANALYZE recently?

> Nested Loop (cost=0.00..208256.60 rows=61140 width=38) (actual time=0.92..18.49 rows=756 loops=1)
> -> Seq Scan on tmp1 (cost=0.00..1.23 rows=23 width=7) (actual time=0.24..0.39 rows=23 loops=1)
> -> Index Scan using db_id_idx on db (cost=0.00..9021.35 rows=2658 width=31) (actual time=0.32..0.69 rows=33 loops=23)
> Total runtime: 19.20 msec

The planner is evidently estimating that each row of tmp1 will match 2600+
rows of db, whereas in reality there is only one match. Rather than
mess with enable_hashjoin, you need to find out why that estimate is so
badly off. Are the entries in tmp1 specially selected to correspond to
unique rows of db?

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ian Barwick 2003-04-10 14:27:43 INSERT INTO ... SELECT (PostgreSQL vs. MySQL)
Previous Message Stephan Szabo 2003-04-10 14:17:03 Re: estimates for nested loop very wrong?