pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sven Willenberger <sven@dmv.com>
Cc: pgsql-performance@postgresql.org
Cc: andrew@catalyst.net.nz
Subject: Re: Using LIMIT changes index used by planner
Date: Tue, 14 Dec 2004 14:35:17 -0500
Message-ID: <16696.1103052917@sss.pgh.pa.us> (raw)
In-Reply-To: <1103048932.5534.22.camel@lanshark.dmv.com>
References: <41BD3317.9090507@dmv.com>
	<1102931789.11712.9.camel@lamb.mcmillan.net.nz>
	<41BE1270.7060908@dmv.com>
	<28820.1102977787@sss.pgh.pa.us>
	<1103048932.5534.22.camel@lanshark.dmv.com>

Sven Willenberger <sven@dmv.com> writes:
> On a related note, is there a way (other than set enable_seqscan=off) to
> give a hint to the planner that it is cheaper to use and index scan
> versus seq scan?

There are basically two things you can do.  One: if the planner's
rowcount estimates are badly off, you can try increasing the stats
targets for relevant columns in hopes of making the estimates better.
A too-large rowcount estimate will improperly bias the decision towards
seqscan.  Two: if the rowcounts are in the right ballpark but the
estimated costs have nothing to do with reality, you can try tuning
the planner's cost parameters to make the model match local reality
a bit better.  random_page_cost is the grossest knob here;
effective_cache_size is also worth looking at.  See the
pgsql-performance archives for more discussion.

>                ->  Index Scan using orderdate_idx on custacct
> (cost=0.00..2657990.68 rows=43297 width=41) (actual
> time=4.432..28145.212 rows=44333 loops=1)

In this case there's already a pretty good match between actual and
estimated rowcount, so increasing the stats targets isn't likely to
improve the plan choice; especially since a more accurate estimate would
shift the costs in the "wrong" direction anyway.  Look to the cost
parameters, instead.

Standard disclaimer: don't twiddle the cost parameters on the basis
of only one test case.

			regards, tom lane



view thread (7+ messages)  latest in thread

Message-ID: <16696.1103052917@sss.pgh.pa.us>
Permalink:  ../16696.1103052917@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16696.1103052917@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, sven@dmv.com, andrew@catalyst.net.nz
  Subject: Re: Using LIMIT changes index used by planner
  In-Reply-To: <16696.1103052917@sss.pgh.pa.us>

* 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