Using indexes can improve the query efficiency. Here is an example.
SQL code:
Create table 'person '(
'Id' int (11) not null AUTO_INCREMENT,
'Name' varchar (20) default null,
'Birthday' datetime default null,
'Isman' int (11) default null,
'Salary' double default null,
'Test' int (11) default null,
Primary key ('id ')
)
Create table 'person '(
'Id' int (11) not null AUTO_INCREMENT,
'Name' varchar (20) default null,
'Birthday' datetime default null,
'Isman' int (11) default null,
'Salary' double default null,
'Test' int (11) default null,
Primary key ('id ')
)
Insert some data. For example:
Run:
EXPLAIN select name from person where name = 'linjia4'
Observed results:
Row = 23 because this table has a total of 23 records, that is, a full table scan is performed.
Add an index to the search "name:
Create index testtest on person (name)
Then execute EXPLAIN select name from person where name = 'linjia4'
Observed results:
Rows = 1, that is, when the query statement is executed, the index of name is used to locate the data directly without full table scan.
The index effect is obvious, greatly improving the query speed. However, indexes cannot be abused. Adding indexes requires a price.
The next article will introduce more in-depth indexing knowledge. I hope to explain it in a simple and easy-to-understand way.
From: The technical warehouse of the neighboring house