When creating a compound database index, what should influence the ordering of the fields?
For example suppose I am creating a compound index based on DATE, PRICE, VOLUME what should influence whether I create
DATE, PRICE, VOLUME VOLUME, DATE, PRICE . . .
Presumably one will be more suited to particular types of queries but I don’t know which queries.
First one will be used if you filter(or search) records by
DATE, or byDATE and PRICE, or byDATE,PRICE,VOLUME. It won’t be used if you filter records, for instance, byVOLUME. The second one will be used for queries where you search condition includesVOLUME, orVOLUME and DATE, orVOLUME,DATE,and PRICE.To be more precise, indexes can also be used when you use indexed columns in
GROUP BYandORDER BY.Some examples:
Index 1 (
DATE,PRICE,VOLUME)Index 2 (
VOLUME,DATE,PRICE)