MySQL indexes

1. Introduction to Index

   An index is a structure that sorts the values ​​of one or more columns in a data table. Using an index can improve the speed of querying specific data in the database. Book-like directory.

   Indexes are implemented in the storage engine, so each storage engine does not necessarily have the same index, and each storage engine does not necessarily support all index types. Define the maximum number of indexes and maximum index length per table according to the storage engine. All storage engines support at least 16 indexes per table, with a total index length of at least 256 bytes. Most storage engines have higher limits. There are two storage types of indexes in MySQL; BTREE and HASH, which are related to the storage engine of the table; MyISAM and InnoDB only support BTREE indexes; the MEMORY storage engine can support HASH and BTREE indexes.

Advantages of indexing:

  • By creating a unique index, the uniqueness of each row of data in a database table can be guaranteed.
  • It can greatly speed up the query speed of data, which is also the main purpose of creating an index.
  • In terms of achieving referential integrity of data, table-to-table joins can be accelerated.
  • Can also significantly reduce query grouping and sorting time when querying data using grouping and sorting clauses

Disadvantages of increasing the index:

  • Creating and maintaining indexes takes time and increases as the amount of data increases.
  • Indexes take up disk time. In addition to the data space for the data table, each index also takes up a certain amount of physical space. If there are a large number of indexes, the index file may reach the maximum file size faster than the data file.
  • When adding, deleting and modifying the data in the table, the index is also dynamically maintained, which reduces the data maintenance speed.

2. Index classification

1. Common index and unique index

Normal index is the basic index type in MySQL, allowing the insertion of duplicate values ​​and null values ​​in the column that defines the index.

Unique index, the value of the indexed column must be unique, but null values ​​are allowed. If the index is combined, the combination of column values ​​must be unique. The primary key index is a special unique index in China, and no null values ​​are allowed.

2. Single column index and composite index

A single-column index means that an index contains only a single column, and a table can have multiple single-column indexes.

A composite index refers to an index created on a combination of multiple fields in a table. The index will only be used when the left field of these fields is used in the query conditions. When using a composite index, the leftmost prefix set is followed.

3. Full-text index

 

 

 

 

Guess you like

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