pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Curt Sampson <cjs@cynic.net>
To: Donny Drummonds <donny@cypresstg.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Indexes on Large Tables
Date: Fri, 7 Feb 2003 14:13:15 +0900 (JST)
Message-ID: <Pine.NEB.4.51.0302071408260.369@angelic.cynic.net> (raw)
In-Reply-To: <EMENJECABIPCHFHEFBJFEEEICAAA.donny@cypresstg.com>
References: <EMENJECABIPCHFHEFBJFEEEICAAA.donny@cypresstg.com>

On Mon, 3 Feb 2003, Donny Drummonds wrote:

> If I do not index the column from the where clause the query returns
> the 150,000 rows in 4 and a half minutes. If in do index the column
> from the where clause using a btree the 150,000 rows return in 11 and
> a half minutes.
>
> Any insight would be greatly appreciated.

Well, I'm not sure if this is the insight you're looking for, but....

The reason it takes longer if you use an index is that you change
from sequential I/O (which is relatively fast) to random I/O (which
is relatively slow). With the table scan (reading the entire table in
whatever order it's in on the disk) you're reading several times as much
data, but you're not doing head seeks all over the place to move the
head to the place where the next bit of data to be read is.

Obviously, in this case, even though an index was available, the planner
was wrong to chose to use it rather than just read the entire table.
That is, as someone else mentioned, likely due to bad statistics: the
planner thought you were going to select a very small part of the table,
rather than ten percent of it (which is a pretty large fraction, for
these purposes). Try doing an ANALYZE.

cjs
-- 
Curt Sampson  <cjs@cynic.net>   +81 90 7737 2974   http://www.netbsd.org
    Don't you know, in this new Dark Age, we're all light.  --XTC



view thread (4+ messages)  latest in thread

Message-ID: <Pine.NEB.4.51.0302071408260.369@angelic.cynic.net>
Permalink:  ../Pine.NEB.4.51.0302071408260.369@angelic.cynic.net/
Also on:    postgresql.org/message-id/Pine.NEB.4.51.0302071408260.369@angelic.cynic.net

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: cjs@cynic.net, donny@cypresstg.com
  Subject: Re: Indexes on Large Tables
  In-Reply-To: <Pine.NEB.4.51.0302071408260.369@angelic.cynic.net>
  References: <EMENJECABIPCHFHEFBJFEEEICAAA.donny@cypresstg.com> <Pine.NEB.4.51.0302071408260.369@angelic.cynic.net>

* 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