Always thought that MySQL is valid in order condition index, found no effect.

Source: Internet
Author: User
EXPLAIN SELECT *
From ' Order2 '
WHERE 1
ORDER by ' Create_time ' DESC

Full table Scan ...


Reply to discussion (solution)

The index in order doesn't work that way.

Your condition is the full table, no matter what index will be the whole table to come again

I understand that the order index should be used in two places.
1. When there is limit
2.order field in the Select return value, this is more complex, that is, only the Order field in the return, or return several fields, the index must be a combination of these fields in the order of the index

The index in order doesn't work that way.

Your condition is the full table, no matter what index will be the whole table to come again

I understand that the order index should be used in two places.
1. When there is limit
2.order field in the Select return value, this is more complex, that is, only the Order field in the return, or return several fields, the index must be a combination of these fields in the order of the index



I just used the order index as if it worked, strange, is there garbage data that affects the index of the entire table? (different libraries, different tables)

Add an index condition such as EXPLAIN SELECT *
From ' Order2 '
WHERE 1 and Create_time>0
ORDER by ' Create_time ' DESC

Remember, if your table data cardinality is too small, or the distribution is not large, the MySQL query optimizer will remove the index, perform a full table scan.
This automatic optimization behavior is not predictable, so when the amount of data is small, sometimes the index does not

Remember, if your table data cardinality is too small, or the distribution is not large, the MySQL query optimizer will remove the index, perform a full table scan.
This automatic optimization behavior is not predictable, so when the amount of data is small, sometimes the index does not


Yes, I found this problem.
And there's too much data on the search condition to scan the whole table.
  • 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.