Skip site navigation (1) Skip section navigation (2)

Index correlation versus multi-column indexes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Cc: Maxim Boguk <mboguk(at)masterhost(dot)ru>
Subject: Index correlation versus multi-column indexes
Date: 2009-02-27 18:25:51
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
I looked into Maxim Boguk's complaint here:
in which the planner preferred to use an index despite the column
being searched on being a lower-order column in that index.

It turns out that the reason the planner is preferring the "wrong" index
is that that index has a very high indexCorrelation score, evidently
because its first column is well correlated with the table ordering.
This causes cost_index to compute very low estimated heap access costs,
outweighing the increased index access costs due to the index's
relatively poor match to the query.

Now we already knew that btcostestimate's estimate of index correlation
was pretty bogus for multicolumn indexes.  However, I now realize that
there's another issue here as well, which would apply even if the index
ordering correlation estimate were perfect.  If you look closely at what
cost_index is doing with the number, you'll realize that it is
effectively assuming that high index correlation means that an indexscan
returns TIDs that are adjacent or nearly so in the heap.  Even given
a perfect match of index and heap order, this fails to hold when the
indexscan quals contain constraints on lower-order index columns,
because we'll be skipping sections of the index in such cases.

So apparently we need to rethink this, and derate the correlation effect
somehow when there are constraints on non-first columns.  I'm not
entirely sure what the model ought to be.  Thoughts?

			regards, tom lane


pgsql-hackers by date

Next:From: Tom LaneDate: 2009-02-27 19:43:26
Subject: Re: BUG #4680: Server crashed if using wrong (mismatch) conversion functions
Previous:From: Heikki LinnakangasDate: 2009-02-27 16:57:27
Subject: Re: BUG #4680: Server crashed if using wrong (mismatch) conversion functions

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group