Re: Query planner refuses to use index

From: Kilian Hagemann <hagemann1(at)egs(dot)uct(dot)ac(dot)za>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Query planner refuses to use index
Date: 2005-07-27 09:25:07
Message-ID: 200507271125.08009.hagemann1@egs.uct.ac.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday 22 July 2005 16:17, Tom Lane pondered:
> Pre-8.0 tends to underestimate the correlation of a multicolumn index.
> (8.0 may too, but not as much.)

I actually upgraded to 8.0.3 now and 2 things have changed. Firstly, I don't
need to do the annoying casts anymore as the query planner now recognises
which literals are compatible with which indexes. Secondly, and you're right
here, 8.0 has decreased the gap between index and sequential scan cost
estimate significantly, but not nearly sufficiently to detect that the index
scan is indeed superior.

> > Also, note that set_id is strictly increasing (hence correlation of 1)
> > and rec_time is strictly increasing within records with same set_id.
>
> So the reason the indexscan is so good is that the ordering correlation
> is perfect. This isn't the planner's default assumption, and
> unfortunately we haven't got statistics available that would allow
> correlation of a multicolumn index to be estimated well.

Hmm, what's wrong with using the 'correlation' column of pg_stats? It told us
straight away that the correlation on set_id was perfect. Even when leaving
out the condition on the second index column (rec_time) the query planner
thinks a sequential scan is more appropriate (please refer to the text file
in my other most recent post for more details).

May I file a bug report for this? I really think that this points to a
deficiency in the query planner.

--
Kilian Hagemann

Climate Systems Analysis Group
University of Cape Town
Republic of South Africa
Tel(w): ++27 21 650 2748

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roman Neuhauser 2005-07-27 09:31:09 Re: Postgresql with max_connections=4096
Previous Message Kilian Hagemann 2005-07-27 09:10:02 Re: Query planner refuses to use index