The reasons why mysql index is fast are: 1. Reduce the amount of data scan and sort the data according to specific rules; 2. Speed up the sorting and grouping operations. When the query contains sorting, grouping or aggregate functions, the index can Greatly reduce the time complexity of sorting and grouping operations; 3. Avoid repeated data reading, store the same data together, and reduce the number of reading repeated records; 4. Accelerate connection operations, when performing table connection operations, the index Can speed up connection operations.
Operating system for this tutorial: Windows 10 system, MySQL 8 version, Dell G3 computer.
The main reasons why MySQL index can improve query speed are as follows:
Reduce the amount of data scanning:
Indexes can sort data according to specific rules, thereby reducing the amount of data that needs to be scanned. By establishing data structures such as B-tree on index columns, MySQL can quickly locate data blocks that meet query conditions, avoiding full table scans and improving query efficiency.
Accelerate sorting and grouping operations:
When the query contains sorting, grouping, or aggregate functions, indexes can greatly reduce the time of sorting and grouping operations. time complexity. By using appropriate indexes, MySQL can directly exploit the orderliness of the index and avoid additional sorting operations.
Avoid duplicate data reading:
Indices can store the same data together, reducing the number of reads of duplicate records. For example, when there is an index, when the query condition contains multiple columns, MySQL can directly use the index to cover the query. It only needs to read the data in the index without reading the corresponding data rows, which improves the query efficiency. efficiency.
Accelerate connection operations:
When performing table connection operations, indexes can speed up the connection operation. By building an index on the join column, MySQL can find matching rows faster and reduce the number of comparisons during the join process.
It should be noted that the more indexes, the better. Improper use of indexes may cause additional overhead. When designing and using indexes, reasonable selection and optimization need to be made based on specific business scenarios and query needs.
The above is the detailed content of Why is mysql index fast?. For more information, please follow other related articles on the PHP Chinese website!
if($res){
return json_encode(array('code'=>1,'msg'=>'成功'));
}else{
return json_encode(array('code'=>0,'msg'=>'失败'));
}
}
public function
}
if($res){
return json_encode(array('code'=>1,'msg'=>'成功'));
}else{
return json_encode(array('code'=>0,'msg'=>'失败'));
}
}
public function
}