I saw the documentation describing covering index:
covering index
An index that includes all the columns retrieved by a query.
Does it mean that the covering index is a specific index?
I think covering index is a phenomenon.
If i follow the description of the document, then please see the following sql statement:
create index idx_name_age on table(id, name)
select id, name from table where id = 1
select id, name, age from table where id = 1
idx_name_age
is a covering index in first statement, the second one is not.
So I think instead: the covering index is a phenomenon rather than an index.
Let's say that "covering" is "an attribute of an INDEX relative to a particular
SELECT
.Some examples:
As already pointed out, if this is InnoDB and the table has
PRIMARY KEY(id)
, then none of these secondary indexes are worth having.Bigger matters in small ways. When doing
SELECT COUNT(*) FROM ...
, InnoDB will (usually) pick the 'smallest' index to do the counting.Another 'rule' is to avoid redundant indexes.