MySQL Note 6_ index

Source: Internet
Author: User

What is an index?

An object in the database.

The query that is used in the database to speed up the table.

The disk's I/O is reduced by locating the data by using the fast path access method.

Separate from the table, but cannot exist independently, and must belong to a table.

Automatically maintained by the database and the indexes on the table are automatically deleted when the table is deleted.

The index works like a book's directory, with almost no book without a table of contents, so there are few tables without indexes.

How to create an index:

Create index index name on table name (field name);

Use index:

The where is followed by an indexed field.

Index 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 the fields and locate the location of the disk where the data resides.

2. Scan by index: Locate data by index page.

3, share the statement.

Attention:

Build indexes on fields that are frequently queried.

If the table has very few columns, it is not appropriate to build an index.

Index fragmentation (like disk fragmentation, garbage files, and so on) can affect query speed after multiple inserts, deletes, and update, so we should reorganize the index. That is, delete the index and rebuild the index.

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.