MySQL Index Overview and analysis of the advantages and disadvantages

What indexes are?

Index (Index) to help MySQL efficiently get the data structure of the data, you can get the essence of the index: the index is a data structure

The purpose of the index is to improve query efficiency, can be compared dictionary, if you want to check the "mysql" word, we definitely need to locate the letters m, then down to find the letters y, and then find the rest of sql. Without an index, you might need a-z like this to find the.

It can be simply understood as " index is a row of data structure to quickly find a good sequence "

In addition to data, the database system further maintainer meet specific search algorithm of the data structure, the data structure references (points to) the data in some way. This can be achieved advanced search algorithm on the basis of these data structure, this data structure is indexed.

Here Insert Picture Description

The leftmost corresponding physical address is usually hard disk file.

To accelerate the lookup Col2, can maintain a binary number to find the right as shown, respectively, each node includes an index key and a pointer pointing to the corresponding physical address recorded data uncover, so that you can use a binary search to a certain complexity the acquired data corresponding to quickly retrieve the matching records.

Why it is frequently used logic to delete it? Because cloud computing will analyze the data, you do not someone else may also be used; there is to index

Why fast query deletions slow? In a database, you need to modify the data when not just modify the data will also revise the index.

In general the index itself is large, not all stored in memory, so the index is often in the form of index files stored on disk.

We usually say the index, if not specified, refer to the B-tree index structure of the organization (multiple search tree, not a binary). Wherein the aggregation index, secondary index, a composite index, prefix index, the default is to use a unique index B + tree index, the index collectively. Of course, in addition to the B + tree index of this type, as well as hash indexes (hash index) and the like.

The index is usually used where the conditions and order by sorting, indexing and retrieval is mainly used for sorting

Index strengths and weaknesses

Advantages :

Similar university library was built bibliographic index, improve data retrieval efficiency, reduce the cost of database IO

By index column to sort the data, cost data sorting, reducing the CPU usage

Disadvantages :

In fact, the index is also a table that holds the primary key and index fields, and points to record a solid table, so the index column is to take up space.

Although the index greatly improve query efficiency, but it will reduce the speed of updating the table, such as table INSERT / UPDATE and DELETE.

Because the updated time table, MySQL is not only to save the data, but also save about index file is updated each time adding a field index column will adjust because the index information of the key changes brought about by the update.

Index only increases the efficiency of a factor, if there is a large amount of data mysql table, we need to take the time to study the establishment of good index or query optimization.

Published 116 original articles · won praise 23 · views 80000 +

Guess you like

Origin blog.csdn.net/zyxwvuuvwxyz/article/details/104595417
Recommended