Re: Why does it not use the index?

From: Doug McNaught <doug(at)mcnaught(dot)org>
To: Andrew Ayers <aayers(at)eldocomp(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why does it not use the index?
Date: 2003-07-21 19:26:28
Message-ID: m3ispvadgb.fsf@varsoon.wireboard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrew Ayers <aayers(at)eldocomp(dot)com> writes:

> Doug McNaught wrote:
> > It's not the VACUUM that's necessary; it's the ANALYZE. The query
> > planner uses table statistics to make its decisions, and ANALYZE is
> > what collects those statistics. Without an ANALYZE the planner will
> > make default assumptions that are rarely correct. :)
>
> I am not the original poster, but I am a PG newbie, so:
>
> So - are you saying that if you have a table, and you create an index on
> that table, you need to perform an ANALYZE in order for PG to use the
> index. Otherwise, the index goes unused (or used improperly)?

Actually, the time to ANALYZE is after you make significant changes in
the table (bulk load a bunch of data, delete a bunch of rows etc). If
you create an index on a table with correct statistics, the planner
should start using it without necessarily needing ANALYZE to be run.

So run it by hand after making major data changes, and run it
periodically depending on how fast your data changes in regular use.

Clear?

-Doug

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Philip Greer 2003-07-21 19:33:22 Re: Why does it not use the index?
Previous Message Andrew Ayers 2003-07-21 19:16:47 Re: Why does it not use the index?