Re: VACUUM kills Index Scans ?!

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Gerald Gutierrez <gutz(at)kalador(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org, gutz(at)colo(dot)kalador(dot)com
Subject: Re: VACUUM kills Index Scans ?!
Date: 2001-03-15 20:30:34
Message-ID: Pine.BSF.4.21.0103151223530.10526-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


On Thu, 15 Mar 2001, Gerald Gutierrez wrote:

> 1) When I create a empty table, and then immediate create an index on a
> column, I can get /index scans/ when searching on that column. But when I
> then run VACUUM, the same search becomes a /sequential scan/. Shouldn't it
> still be an index scan? What's going on here?

> ---------------------------------------------
>
> 2) If I already have some data in a table and I create an index on a
> column, why doesn't subsequent searches then change from sequential scans
> to index scans?

With a small number of rows, a sequence scan will require less
reads/seeks from the filesystem. It's not always correct for the
optimizer to choose to use an index even if it's there.

If you put in lots of rows with distinct values and vacuum analyze (you
want to do that rather than just vacuum) and do a comparison it should
use the index, with only a few rows, the seq scan is probably better.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2001-03-15 20:33:29 Re: RE: Help with UPDATE syntax
Previous Message Tom Lane 2001-03-15 20:21:23 Re: VACUUM kills Index Scans ?!