Mysql8000 + paging click any page to control the response between 3-4 S. How can I continue optimization?

Source: Internet
Author: User
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:

  1. Limit optimization: first retrieve the ID corresponding to the page, and then according to the field < strong> Value, and then limit <>

  2. Index

  3. 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:

  1. Limit optimization: first retrieve the ID corresponding to the page, and then according to the field < strong> Value, and then limit <>

  2. Index

  3. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.