MySql index classification and related syntax for creating indexes

1. Index classification

insert image description here

1.1 Classification of indexes in InnoDB

insert image description here
The structure of the B+ tree between the clustered index and the secondary index
insert image description here
explains the execution process of the SQL statement index.
insert image description here
The efficiency of the clustered index query based on the id is higher than that of the secondary index, so the execution efficiency of the first SQL is higher than that of the second SQL.
insert image description here
insert image description here

2. Index syntax

If an index is only associated with one field, this type of index is called a single-column index, and if an index is associated with multiple fields, this type of index is called a joint index or a composite index.
insert image description here

2.1 Create an index

insert image description here
The index structure is not specified when creating the index, but the table defaults to the table of the InnoDB engine, so the index structure defaults to a B+ tree.

Requirement 1, create an index for the name field, the operation is as follows
insert image description here
Requirement 2, create a unique index for the phone field, the operation is as follows
insert image description here
Requirement 3, create a joint index for profession, age, status.
insert image description here
Requirement 4, create an index for the email field
insert image description here

2.2 Delete index

insert image description here

3. Summary of index syntax

insert image description here

Guess you like

Origin blog.csdn.net/weixin_44860226/article/details/131650389