Introduction to Indexes in MySQL

First, the advantages of index
Why create an index? This is because creating an index can significantly improve query performance.
First, by creating a unique index, can guarantee the uniqueness of each row of data in a database table.
Second, you can greatly accelerate the speed of data retrieval, which is the main reason for creating the index.
Third, can accelerate the connection between the table and the table, especially in reference to particular interest for data integrity aspects.
Fourth, when using the packet data retrieval and sorting clause, can also significantly reduce the query time grouping and sorting.
Fifth, through the use of an index, you can process the query using the query optimizer to improve system performance.


Second, the shortcomings of the index
maybe someone will ask: increase the index has so many advantages, why not create a table in a column for each index it? This idea certainly has its rationality, but also has its one-sidedness. Although the index has many advantages, however, for each of the columns in the table have increased the index, it is very unwise. This is because the increase in the index have a lot of negative aspects:
first, to create indexes and index maintenance takes time, this time with the increase in the amount of data increases.
Second, the index needs to occupy physical space, in addition to the data table representing the data outside of the space, each index also occupy some physical space. If you want to build a clustered index, the space needs will be greater.
Third, when the data in the table to add, delete and modify, the index should be dynamic maintenance, thus reducing the speed of data maintenance.

Third, what kind of field to create an index for
the index is based on a database table above some columns. Therefore, when creating an index, you should carefully consider which can create an index on the column, you can not create an index on which columns. Generally, should create an index on column includes the following characteristics:
first, in a column often need to search, the search can speed;
second, in a column as the primary key, unique and forces the column organizational structure of the data arrangement table;
third, often used in the column in the connection, which mainly some foreign key column, the connection can speed;
fourth, creating indexes on often need to search for a column according to the scope, because the index is already sorted, its specified range is continuous;
fifth, often need to create an index on the sort columns, because the index has been sorted, so that the query can use the index to sort, query speed up the sorting time;
sixth, used often create an index above the columns in the WHERE clause, accelerate speed to determine the conditions.
Indexing, generally in accordance with the conditions where select to build, such as: condition select is where f1 and f2, so if we create an index on a field f1 and field f2 is of no use, only the index at the same time on the field f1 and f2 to be useful and so on.

Fourth, what kind of fields are not suitable for creating indexes:
Again, for some column should not create the index. In general, we should not create an index of these columns has the following characteristics:
First, for those columns that are rarely used or referenced in the query should not create the index. This is because, since these columns rarely used, so there is no index or index does not improve query speed. On the contrary, due to the increase in the index, but reduces maintenance and increases the speed of the system space requirements.
Second, for those few data values in a column index should not be increased. This is because the values of these columns is small, such as gender column personnel table, in the results of the query, the result set of data rows in a large proportion of rows of data tables that need to search for data in the table a large proportion of the line. Increase in the index, did not significantly speed up the retrieval speed.
Third, for those defined as text, image and bit data types of columns should not increase the index. This is because the amount of data in those columns either a large or small value.
Fourth, when modifying performance is far greater than the retrieval performance, should not create the index. This is because, retrieval performance and performance modifications are conflicting. When the increase in the index will increase the retrieval performance, but reduces performance modifications. When the reduction of the index will be modified to improve performance and reduce retrieval performance. Therefore, when modifying the performance is far greater than the retrieval performance, should not create the index.

Guess you like

Origin www.cnblogs.com/yucongblog/p/11125453.html