Re: Nested loops overpriced

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Nested loops overpriced
Date: 2007-05-08 15:53:13
Message-ID: 1987.1178639593@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Note how spectacularly overpriced this plan is.

Hmm, I'd have expected it to discount the repeated indexscans a lot more
than it seems to be doing for you. As an example in the regression
database, note what happens to the inner indexscan cost estimate when
the number of outer tuples grows:

regression=# set enable_hashjoin TO 0;
SET
regression=# set enable_mergejoin TO 0;
SET
regression=# set enable_bitmapscan TO 0;
SET
regression=# explain select * from tenk1 a join tenk1 b using (thousand) where a.unique1 = 1;
QUERY PLAN
----------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..52.82 rows=10 width=484)
-> Index Scan using tenk1_unique1 on tenk1 a (cost=0.00..8.27 rows=1 width=244)
Index Cond: (unique1 = 1)
-> Index Scan using tenk1_thous_tenthous on tenk1 b (cost=0.00..44.42 rows=10 width=244)
Index Cond: (a.thousand = b.thousand)
(5 rows)

regression=# explain select * from tenk1 a join tenk1 b using (thousand) where a.ten = 1;
QUERY PLAN
---------------------------------------------------------------------------------------------
Nested Loop (cost=0.00..2531.08 rows=9171 width=484)
-> Seq Scan on tenk1 a (cost=0.00..483.00 rows=900 width=244)
Filter: (ten = 1)
-> Index Scan using tenk1_thous_tenthous on tenk1 b (cost=0.00..2.15 rows=10 width=244)
Index Cond: (a.thousand = b.thousand)
(5 rows)

This is with 8.2.4 but AFAICS from the CVS logs, 8.2's cost estimation
code didn't change since 8.2.1. What do you get for a comparably
simple case?

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Ron 2007-05-08 16:08:10 Re: Best OS for Postgres 8.2
Previous Message Alvaro Herrera 2007-05-08 15:34:15 Re: specific query (not all) on Pg8 MUCH slower than Pg7