MySQL Index Classification
There are single-valued index and two kinds of the composite index, concrete can be divided into the following:
- Primary key index:
It is a special unique index, does not allow nulls. Usually at the same time create a primary key index when construction of the table - General index:
This is the most basic index, it does not have any restrictions, allow single repeat
create index idx_name on user(
name(20)
);
- Unique index:
Similar to the general index, is different: the value of the index columns must be unique, but allow nulls (note different and primary key). If it is a composite index, a combination of the column value must be unique, and create a method similar to ordinary index
CREATE UNIQUE INDEX idx_email ON user(
email
);
- Full-text index
MySQL supports full text indexing and search capabilities. MySQL full-text index of type FULLTEXT index. FULLTEXT indexes only for MyISAM tables; code as follows:
CREATE TABLE articles (
id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
title VARCHAR(200),
body TEXT,
FULLTEXT (title,body)
);
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('database');
- Composite Index:
i.e. an index containing a plurality of columns, as follows:
CREATE TABLE test (
id INT NOT NULL,
last_name CHAR(30) NOT NULL,
first_name CHAR(30) NOT NULL,
PRIMARY KEY (id),
INDEX name (last_name,first_name)
);