All experimental paper-based MySQL5.7.21, the experiment will be used Explain tool, you do not understand the students can refer to this article: MySQL Performance Tuning artifact Explain Detailed
Failure joint index
To create a joint index comprises three fields, an index in the following order:
the three figures in the following fields key_len we can conclude that the length of the three indices, respectively: title length 303, author length 122, price 5 long.
Follow the leftmost match joint index using the principle, if not from the leftmost column, the entire index fail, if the most match left turn to the right to use the index until after the match before the encounter places that do not match the entry into force of the index
Range queries can cause failure of the index
Joint replacement index less than the order of the fields title, price, author. If the range of the scope of the appended contains query query failure Field
like queries fail
When using fuzzy query,% only in the most right time to take effect
To set up a separate title index
Queries containing the index or not equal to or does not take effect
Do the calculation function or lead to failure in the index column
Delete joint index just created, create a separate index for the price field
String type without the quotes will also fail
is null和 is not null
Create a separate index for the title field
Precautions
When using the index tests, test data may be because too few would think so MySQL queries go scan the entire table is more effective than taking the index, so the index will automatically be removed, in order to avoid misleading test results can be used to force MySQL to use an index as follows
1 |
EXPLAIN SELECT * from Book the FORCE index (Index Name) WHERE. price = 1+ . 1; |
The advantage of using an index
- Unique primary key index or index can guarantee the uniqueness of database tables
- You can improve query performance and efficiency
- Acceleration speedometer connected
- Enhance the efficiency of sorting
The disadvantage of using an index
- Each update requires maintenance amended to delete the index, consuming performance
- Index files take up physical space