Mysql-index Learning (1)

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.