Skip site navigation (1) Skip section navigation (2)

Re: tweaking costs to favor nestloop

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Vincent van Leeuwen <pgsql(dot)spam(at)vinz(dot)nl>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: tweaking costs to favor nestloop
Date: 2003-06-13 14:07:42
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
Vincent van Leeuwen <pgsql(dot)spam(at)vinz(dot)nl> writes:
> How did you calculate the value of 3?

Estimated cost of an indexscan is approximately proportional to
random_page_cost, but cost of a seqscan isn't affected by it.
You had a hash join plan that used two seqscans (so its estimated
cost is unaffected by random_page_cost) plus a merge join plan
that had one indexscan input.  I just extrapolated the change in
the indexscan cost needed to make the ratio of total costs agree with
reality.  This is a pretty rough calculation of course, but I don't
believe small values of random_page_cost except for situations where all
your data is buffered in RAM.  It's real easy to get led down the garden
path by small test cases that get fully buffered (especially when you
repeat them over and over), and pick cost values that will not reflect
reality in a production environment.  I can't say whether that actually
happened to you, but it's something to be on your guard about.

> Another problem we've noticed is that on an idle database certain queries are
> better off using an indexscan than a seqscan, something which the planner
> already wanted to do. But when the load on the database gets a lot higher,
> indexscans are consistently slower than seqscans (same query, same
> parameters).

See above.  Increasing load reduces the chances that any one query will
find its data already buffered, since there's more competition for the
available buffer space.

> Does 7.4 already have changes in this area that will affect this query?


			regards, tom lane

In response to

pgsql-performance by date

Next:From: Ryszard LachDate: 2003-06-13 18:45:06
Subject: 7.3 vs 7.2 - different query plan, bad performance
Previous:From: Vincent van LeeuwenDate: 2003-06-13 12:39:22
Subject: Re: tweaking costs to favor nestloop

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group