MySQL's loose index scan

Source: Internet
Author: User

As we all know, InnoDB uses IoT (Index organization table), the so-called Index organization table, and leaf nodes store all the data, which means that data is always stored in some order. So the question is, if it is such a statement, how should it be executed? The statements are as follows:

Select Count (distinct from table1;

There is an index on column A, so how do you scan it according to the simple idea? Very simple, one scan, so that, in fact, did an index full scan, the efficiency is very poor. This scanning method scans a lot of duplicate indexes, so the optimization is easy to think of: Skip the duplicate index. So the Internet can search for such an optimization method:

Select Count (* from (selectdistinct from table1) t;

From the data that has been searched, the extra in such an execution plan becomes the using index for group-by from the using index.

But, however, fortunately we are not using the 5.1 version now, we are basically more than 5.5, these modern versions, have implemented the loose index scan:

Good and good, there is no need to use this artifice to optimize SQL.

There is a bit of meaning in the document about group by, saying that the most popular way is to do a full table scan and create a temporary table, so that the execution plan will be ugly, there must be all and using temporary table.

Deep feeling this one wrote a lot of writing, weekend more, I want to go to bed early.

MySQL's loose index scan

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.