I. Index introduction index definition: an index is composed of one or more columns in a database table. It improves the data query speed in the table. Similar to the directory of a book, which allows you to quickly locate the specified content, such as a 1000-page book. If there is no directory, you want to know the specified content, it must be one page and one page. Is it a waste of time? II:
I. Index introduction index definition: an index is composed of one or more columns in a database table. It improves the data query speed in the table. Similar to the directory of a book, which allows you to quickly locate the specified content, such as a 1000-page book. If there is no directory, you want to know the specified content, it must be one page and one page. Is it a waste of time? II:
Zookeeper
I. Introduction of Indexes
Index definition: an index is composed of one or more columns in a database table. It improves the query speed of data in the table.
Similar to the directory of a book, you can quickly locate the specified content, such as a 1000-page book. If there is no directory, you want to know the specified content, it must be one page and one page. Is it a waste of time?
Ii. Advantages and Disadvantages of Indexes
Advantage: improves the speed of data query.
Disadvantage: The time for creating and maintaining Indexes has increased.
Iii. Index Application
The T_teacher table contains 100000 pieces of data, which I inserted using Hibernate. You can use jdbc to plug in or use the following knowledge to create a stored procedure, if you are interested, you can preview it at Baidu first.
Mysql> Select count (*) from t_teacher;
Mysql> Select * from t_teacher where name = 'instructor 100'; # My speed is 79 milliseconds. id cannot be used here because id is the primary key.
Mysql> create index 'index _ name' ON 't_ teacher '('name'); # CREATE an index ON the name column
Mysql> Select * from t_teacher where name = 'instructor 100'; # query again. The speed is almost 0 ms. You can see how fast the index is.
Iv. Index classification
1: Common Index (common)
These indexes can be created in any data type.
2: unique index (commonly used)
You can set the UNIQUE parameter. When creating a UNIQUE index, the value of the index must be UNIQUE, and the primary key is UNIQUE by default.
3: Full-text index
You can set the FULLTEXT parameter. Full-TEXT indexes can only be created on CHAR, VARCHAR, and TEXT fields. The main function is to speed up the query of large string types. Only the MyISAM engine supports this index, which is not supported by the Mysql Default engine.
4: Single Column Index
You can create an index for a single field in a table. A single column index can be a common index, a unique index, or a full-text index.
5: Multi-column Index
A multi-column index creates an index on multiple fields in the table.
6: spatial index
You can use the SPATIAL parameter to set the SPATIAL index. The spatial index can only be created on the spatial data type, which can improve the efficiency of the system to obtain spatial data. Only the MyISAM engine supports this index, which is not supported by the Mysql Default engine.
5. Create an index
5.1 create an index when creating a table
Create table Name (attribute name data type [integrity constraints],
Attribute name data type [integrity constraints],
....
Attribute name Data Type
[UNIQUE | FULLTEXT | SPATIAL] INDEX | KEY
[Alias] (attribute name 1 [(length)] [ASC | DESC])
);
The index name is not specified here. Use the default index name of mysql.
5.2 create an index on an existing table
CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX name
ON Table Name (attribute name [(length)] [ASC | DESC]);
Mysql> create table 't_ test2 '(
Id int primary key AUTO_INCREMENT,
Username VARCHAR (30 ),
Password varchar (10)
);
Mysql> create index 'index _ username' ON 't_ test2' ('username ');
5.3 use the alter table statement to create an index
Alter table name ADD [UNIQUE | FULLTEXT | SPATIAL] INDEX
Index name (attribute name [(length)] [ASC | DESC]);
Mysql> alter table 't_ test2'
Add unique index 'index _ password' ('Password ');
6. delete an index
Drop index name ON table name;
Mysql> drop index 'index _ username' ON 't_ test2 ';
VII. Summary
Today, we have introduced the index-related content for everyone. Let's take a good look at it. Next we will provide you with the view-related content. Thank you!