The Georgia
The Georgia

Reputation: 1075

MySQL indexes with multiple field

Would the following table considered to have duplicate indexes on TypeId, or is it perfectly fine to do it this way? Some of my queries perform faster using the KEY "covered', while others perform better just using the 'TypeId'. Any knowledge on the matter would be appreciated.

CREATE TABLE module(
Id INT unsigned not null auto_increment,
name VARCHAR(30) not null,
TypeId INT unsigned not null,
cSign tinyint not null,
orderId int not null,
PRIMARY KEY(Id),
KEY 'covered' ('cSign','TypeId','orderId'),
KEY 'TypeId' ('TypeId')
);

Upvotes: 0

Views: 22

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

No, the indexes are different.

MySQL documentation does a good job of explaining indexes with composite keys. What is important is that the left-most columns in the indexes are different.

As a note: you should fix your code by removing the single quotes. They are incorrect in this context.

Upvotes: 1

Related Questions