If there are several fields in the User table that can be requested (say, DepartmentId, GroupId, RoleId), will there be a difference in speed if I create an index for each combination of these fields?
By “queryable,” I mean a query screen where the end user can select entries based on a section, group, or role, choosing from a drop-down list.
At the moment I have an index on DepartmentId, GroupId and RoleId. This is the only non-unique index for each field.
If the end user selects “anyone in group B,” SQL looks like this:
select * from User where GroupId = 2
Having an index on GroupId should speed it up.
But if the end user chooses “anyone in group B and role C,” SQL will look like this:
select * from User where GroupId = 2 and RoleId = 3
Having indices for GroupId and RoleId individually can not make any difference, can it?
The best index for this search would be if I had one index covering both GroupId and RoleId.
But if this happens, it will mean that I will need to have an index for each combination of requested fields. Therefore, I need all of these indexes:
- DepartmentID
- Groupid
- Role id
- DepartmentId and GroupId
- DepartmentId and RoleId
- GroupId and RoleId
- Department ID, GroupId and RoleId
Can anyone shed some light on this? I use MySQL if that matters.
sohtimsso1970
source share