MySQL Forums
Forum List  »  Newbie

Re: Indexes: how many, how much?
Posted by: Rick James
Date: May 08, 2010 04:26PM

select ColumnA
from TableA
where ColumnB = 5
-->
INDEX(columnB, ...) -- By that, I mean either an index with just B, or an index starting with B.

select ColumnA
from TableA
where ColumnB = 5
and ColumnC = 2
-->
INDEX(B, C, ...) _or_
INDEX(c, B, ...)
Either will work equally well.

select ColumnA
from TableA
where ColumnB = 5
and ColumnC = 2
and ColumnD = 7
-->
Any INDEX starting with all three of B,C,D in any order

For all three of those selects, only one is needed, and it is good for all of them:
INDEX(columnB, columnC, columnD)

If you have more SELECTs, or you have 'ranges', or you have GROUP BY or ORDER BY, or..., then there are many more 'rules' on creating optimal index(es).

Options: ReplyQuote


Subject
Written By
Posted
May 06, 2010 11:58PM
Re: Indexes: how many, how much?
May 08, 2010 04:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.