MySQL use indexes and index fail advantages and disadvantages

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:
1
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.
111

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
11

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
1

like queries fail

When using fuzzy query,% only in the most right time to take effect

To set up a separate title index

111

Queries containing the index or not equal to or does not take effect

111

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

11

String type without the quotes will also fail

1

is null和 is not null

Create a separate index for the title field
11

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

 

Guess you like

Origin www.cnblogs.com/zhixiang-org-cn/p/10941761.html