No idea, ask on -hackers... I only know the concepts of how it works, I have no idea about the code itself. Have a nice day, On Tue, Dec 19, 2006 at 08:39:12AM -0300, Felipe Rondon Rocha wrote: > Hi Martijn, > > my problem is that our group of study made a modification to always use the > index on a "select explain ..." statement. But as a matter of fact we found > some bugs that have to be fixed. I know how the choice of an index > happens. What I need to find is the moment that PostgreSQL compares the > costs of all trees (paths) and decide to use the index or not. Do you have > any tips? > > Thank you, very much. > > Regards, > Felipe > > ----- Original Message ----- > From: "Martijn van Oosterhout" > To: "Felipe Rondon Rocha" > Cc: > Sent: Thursday, December 14, 2006 9:56 AM > Subject: Re: [HACKERS] choosing use an index or not > > 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 http://svana.org/kleptog/ > >From each according to his ability. To each according to his ability to > >litigate. -- Martijn van Oosterhout http://svana.org/kleptog/ > From each according to his ability. To each according to his ability to litigate.