Mysql note 6_index

Source: Internet
Author: User

What is an index?

An object in the database.

It is used in the database to accelerate table queries.

Using quick path access to locate data reduces disk I/o.

It is stored independently of a table, but cannot exist independently. It must belong to a table.

Automatically maintained by the database. When a table is deleted, its indexes are automatically deleted.

The index function is similar to the book directory. There is almost no book without a directory, so there is almost no table without an index.

How to create an index:

Create index name on table name (field name );

Use index:

Add the index field after the where clause.

Indexing principle:

Index page table

Index_name | loc | <--------------------------------------------- |

Name | c:/xxx/xx | id | name (index) | sex | age |

... |

Database query method:

1. Full table scan: scan all fields to locate the location of the data on the disk.

2. Index scan: locates data on the index page.

3. Shared statement.

Note:

Index fields that are frequently queried.

If there are few columns in the table, it is not suitable for creating indexes.

After multiple insert, delete, and update operations are performed, index fragments (such as disk fragments and junk files) may occur, affecting the query speed. Therefore, we should reorganize the indexes. That is, the index is deleted and then re-created.

 

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.