Another important point to consider is the following: a composite index (consisting of several columns) will be used only if the n leftmost columns are referenced (for example, in the WHERE ).
So, if you have one composite index on
(UserID, UserName, UserEmail)
then this index can be used in the following scenarios:
- when you search for only
UserID (using only one left column - UserID ) - when you look for
UserID and UserName (using 2 columns on the left) - when searching for all three columns
But this single connection index will never be used to search by
- just
UserName is the second column in the index, and thus this index cannot ever be used - just
UserEmail is the third column in the index, and thus this index cannot ever be used
Just remember this - simply because the column is part of the index, does not necessarily mean that searching in only one column will be supported and accelerated by that index!
So, if your usage patterns and your application really should search only for UserName and / or UserEmail (without providing other search values), you should create separate indexes in these columns - only one composite does not have any benefit.
source share