I would like to know when i have to put multiple index should i make them under the same “index” or on a different index?
INDEX `field1` (`field1`)
INDEX `field2` (`field2`)
or
INDEX `field1` (`field1`,`field2`)
Are there any differneces?
thanks
There is a difference. An index made out of two columns (or more) is built according to the order of columns you specified. It can be used only when you are searching for the first X fields. Let’s say you have an index
It will be used when running queries like:
It will NOT be used when running queries like:
On queries of the first type, having the 3 field index will be quicker than having separate indexes, so deciding how to build the indexes depends on which types of queries you are going to need.