The optimization method is limit optimization. the ID corresponding to the page is extracted first, and then the code is attached to the myisam engine based on the value of the Field & amp; lt; ID, and then the limit index: total number of data queried: is the ID corresponding to the query page: is the query result: --------------- 2016.7.617: 47 more...
Optimization method used:
-
Limit optimization: first retrieve the ID corresponding to the page, and then according to the field < strong> Value, and then limit <>
-
Index
-
Myisam engine
Code attached:
Total number of queried data:
Is the ID of the query page:
Is the query result:
--------------- 2016.7.6 update --------------------
Like this place really shouldn't have to be, it has already been processed, and it shouldn't have to be.The code diagram is also updated.. Now the response can be kept in2.5 sBelow
The execution plan is as follows: this is the first statement,Total data query
SELECT `r`.`id` FROM (`samplerecord` as r) LEFT JOIN `statementsample` as s ON `r`.`sample_id`=`s`.`id` LEFT JOIN `breed` as b ON `s`.`food_id`=`b`.`id` LEFT JOIN `user` as u ON `r`.`user_id`=`u`.`id` WHERE `s`.`code` != ''
Second statementID of the first field in the query page
SELECT `r`.`id` as id FROM (`samplerecord` as r) LEFT JOIN `statementsample` as s ON `r`.`sample_id`=`s`.`id` LEFT JOIN `breed` as b ON `s`.`food_id`=`b`.`id` LEFT JOIN `user` as u ON `r`.`user_id`=`u`.`id` WHERE `s`.`code` != '' ORDER BY `id` DESC LIMIT 1 OFFSET 5988
Statement 3:Query data result sets
SELECT `r`.`id` as id, `s`.`code` as code, `b`.`breed_name`, `r`.`state`, `u`.`username`, `r`.`recordtime`, `r`.`remark` FROM (`samplerecord` as r) LEFT JOIN `statementsample` as s ON `r`.`sample_id`=`s`.`id` LEFT JOIN `breed` as b ON `s`.`food_id`=`b`.`id` LEFT JOIN `user` as u ON `r`.`user_id`=`u`.`id` WHERE `s`.`code` != '' AND `r`.`id` < '109541' ORDER BY `id` DESC LIMIT 12
Please help me analyze...
Reply content:
Optimization method used:
-
Limit optimization: first retrieve the ID corresponding to the page, and then according to the field < strong> Value, and then limit <>
-
Index
-
Myisam engine
Code attached:
Total number of queried data:
Is the ID of the query page:
Is the query result:
--------------- 2016.7.6 update --------------------
Like this place really shouldn't have to be, it has already been processed, and it shouldn't have to be.The code diagram is also updated.. Now the response can be kept in2.5 sBelow
The execution plan is as follows: this is the first statement,Total data query
SELECT `r`.`id` FROM (`samplerecord` as r) LEFT JOIN `statementsample` as s ON `r`.`sample_id`=`s`.`id` LEFT JOIN `breed` as b ON `s`.`food_id`=`b`.`id` LEFT JOIN `user` as u ON `r`.`user_id`=`u`.`id` WHERE `s`.`code` != ''
Second statementID of the first field in the query page
SELECT `r`.`id` as id FROM (`samplerecord` as r) LEFT JOIN `statementsample` as s ON `r`.`sample_id`=`s`.`id` LEFT JOIN `breed` as b ON `s`.`food_id`=`b`.`id` LEFT JOIN `user` as u ON `r`.`user_id`=`u`.`id` WHERE `s`.`code` != '' ORDER BY `id` DESC LIMIT 1 OFFSET 5988
Statement 3:Query data result sets
SELECT `r`.`id` as id, `s`.`code` as code, `b`.`breed_name`, `r`.`state`, `u`.`username`, `r`.`recordtime`, `r`.`remark` FROM (`samplerecord` as r) LEFT JOIN `statementsample` as s ON `r`.`sample_id`=`s`.`id` LEFT JOIN `breed` as b ON `s`.`food_id`=`b`.`id` LEFT JOIN `user` as u ON `r`.`user_id`=`u`.`id` WHERE `s`.`code` != '' AND `r`.`id` < '109541' ORDER BY `id` DESC LIMIT 12
Please help me analyze...
Can I post the SQL statement and execution plan?
Execution in the transaction will improve the efficiency
1. split the table connection query into a simple query.
2. is like necessary?
Three SQL statements:
1. The total amount of SQL, samplerecord does not take any index, full table scan, will inevitably be slower
2. query id SQL, sorting + full table, estimated slow
3. the last one should be okay.
Therefore, full table scan is avoided. if full table data is required, the limit will not be slow.
Final guess, code! = ''The filtering condition is high, that is, there are many such conditions, resulting in slow Filtering. try to add an index.