Re: choosing use an index or not

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Felipe Rondon Rocha <frondon(at)globo(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: choosing use an index or not
Date: 2006-12-14 12:56:14
Message-ID: 20061214125614.GB24370@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Dec 14, 2006 at 10:06:45AM -0300, Felipe Rondon Rocha wrote:
> Hi everyone,
>
> Do you know in which part of the file analyze.c, PostgreSQL decides
> to use or not an index? I´m making a test and I can´t trace the
> moment that he makes the choice.

It doesn't explicitly make the choice anywhere. The planner makes a set
of "paths" that can be used. So for each table a "path" is made for a
sequential scan and one or more "paths" for each index. For each a cost
is calcualted and whichever has the lowest cost is the one chosen.

It's quite dynamic, the choice also depends on what happens to the
result. There's no point using an index if the result is in the wrong
order for the join, for example.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Felipe Rondon Rocha 2006-12-14 13:06:45 choosing use an index or not
Previous Message Peter Eisentraut 2006-12-14 12:52:05 Re: recovery.conf parsing problems