I’ve be told and read it everywhere (but no one dared to explain why) that when composing an index on multiple columns I should put the most selective column first, for performance reasons.
Why is that?
Is it a myth?
I’ve be told and read it everywhere (but no one dared to explain why)
Share
According to Tom, column selectivity has no performance impact for queries that use all the columns in the index (it does affect Oracle’s ability to compress the index).
However, these considerations should come second when deciding on index column order. More importantly is to ensure that the index can be useful to many queries, so the column order has to reflect the use of those columns (or the lack thereof) in the where clauses of your queries (for the reason illustrated by AndreKR).
All other things being equal, I would still put the most selective column first. It just feels right…
Update: Another quote from Tom (thanks to milan for finding it).