Index overview

1. Clustered Index

Determines the physical order of data rows in a table on disk. A table has only one clustered index, usually the primary key.

Second, the non-clustered index

The physical order is not determined, the index only contains the indexed data, and a row locator through which row data can be found.

Third, the joint index

Build indexes on multiple fields in a table to speed up review queries.

The joint index meets the requirements of the leftmost query. For example, three columns (a,b,c) form a joint index. The queries that can use the index are a|(a,b)|(a,b,c).

Note: Use the joint index to query data, the order of the fields after the where condition does not affect whether to use the index.

Fourth, the unique index

To avoid data duplication, build an index on one or more fields.

Note: There can be multiple unique indexes in a table, but the column value must be unique. To create a unique index, use the keyword unique, and the unique index column value is allowed to be empty.

5. B-Tree

The btree index is the most commonly used index algorithm in mysql. It can not only be used in comparison operators such as =, >, >=, <, <= and between, but also in the like operator, as long as its query condition is a Constants that do not start with wildcards, for example: 

select * from table where col like ‘test%’; 

But not supported: select * from table where col like '%est%'; 

 

MySQL data is associated with the data in the database through the btree method. When querying, it is only necessary to traverse the data range according to the tree traversal method. The following figure shows the data index relationship between the binary tree and the ternary tree. The traversal method is traversed in the order of "left-right-root", and the data range can be quickly located during query.

 

 6. Hash index

Hash index is to store data in the form of hash key value, and find the corresponding value value by locating the key key when querying the data. Therefore, the hash index does not support range queries, and only satisfies the filtering of equal values ​​(equal, not equal).

For use in the database, please refer to: http://blog.csdn.net/u012992688/article/details/48416539

The principle of hash index algorithm can be referred to: http://blog.csdn.net/tanggao1314/article/details/51457585

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326174056&siteId=291194637