I have a covering index that encompasses field a b and c, in that sequence.
ALTER TABLE table ADD INDEX covering(a, b, c)
The following query uses the covering index, more specifically just the first field in the covering index.
SELECT * FROM table
GROUP BY a
Would I observe a performance increase if I created another index that exclusively encompassed a?
ALTER TABLE table ADD INDEX a(a)
Or does the above index work exactly the same way as the covering index on the SELECT statement?
What if my query was GROUP‘ing on a a field that was not the first in sequence in the covering index?
SELECT * FROM table
GROUP BY b
And my index was
ALTER TABLE table ADD INDEX b(b)
If you have compound index on
(a, b, c)and useORDER BY a, then it will work and make use of that index. Adding index on just(a)will make it more preferable to query planner, but it will be wasteful as you have to keep more data in indexes, and also to update both indexes when table gets updated. There will be small gain from using narrower index, but it could be difficult to quantify that advantage.As for querying using
ORDER BY b, it could not use any of the indexes above, and you must create index on(b)or compound index on(b, ...)to get reasonable performance.