SQL and Multiple Indexes

indexselect

Consider the following table:

i | a | b | c
--------------
0 | 1 | 2 | 3
1 | 4 | 5 | 6
2 | 7 | 8 | 9
3 | x | y | z

The table, in the end, will have several thousand rows, and even more columns then described here (20+). I plan on adding indexes to the table, but cannot figure out which indexes to make. In the end, I'll be doing SELECT statements with different combinations of these, and sometimes only on 1 column. Is the most efficient way to make the indexes:

(A) Index each column separately, eg. aIndex(a), bIndex(b), cIndex(c), etc..

(B) An Index for each type of select statement, eg. aIndex(a), abIndex(a,b), acIndex(a,c), etc..

(C) Just index them all together into one, eg. tIndex(a,b,c).

Indexes are one of those things I'm still getting a grasp on, so I apologize if this seems like a silly or simplistic question. What I'm trying to avoid is unnecessary indexes as they will increase disk-space and INSERT times dramatically.

Best Answer

It is best to use any combination of the techniques, but match them to your actual queries. Some queries may only need a single column index, while other queries may need a mutli-column index. That is a great thing about indexes, is you can add them as you need them, and remove ones that no longer serve a purpose, so you have exactly what you need for your queries.