MySQL 5.7 under InnoDB for COUNT (*) optimization

Source: Internet
Author: User
In MySQL 5.7 COUNT () selects a clustered index and makes an internal handler function call to get the total number of tables quickly

Execution plan display: Extra:select tables optimized away

In previous versions of 5.7, the count () request was usually: Scan the normal index to get this total.
6. Execution Plan display: Extra:using index

If the clustered index is large (or the size of the table data is large) and is not fully loaded into buffer pool, MySQL 5.7 query may be slower, rather than the original way (MySQL 5.6)
WORKAROUND: Force the normal index, but still need to add the where condition, or not.
Select COUNT () from Stock Force index (IDX_STOCK) where ID >0;
Extra:using where,using Index

MySQL 5.7 under InnoDB for COUNT (*) optimization

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.