Mysql:mysql between date index problem-date index use

Source: Internet
Author: User

Mysql:mysql between date index problem-date index use

Table structure:

Dep_date

Dep

Arr

Federated indexes: Ind_coll_date_route (dep_date, Dep,arr)

These two days found that the original query efficiency is slow, using explain view, incredibly did not use the index,
My index is a date type, the first thought is MySQL on the date type index processing mechanism is not different, in the Where condition to try a few, found the effect is similar,

where Dep_date >= ' 20161121 '
where Dep_date >= ' 2016-11-21 '
where dep_date between ' 2016-11-01 ' and ' 2016-11-21 '

There are various functions, and finally found that the conclusion is the same, in Baidu Query also has no valuable content.

Finally, some laws were found, but it was not known whether there was universality, namely:

The index can be used when the number of query data is approximately one-fifth of the total number of bars, but when more than one-fifth is used, the full table is scanned.

Tried a number of tables, are this conclusion, so think this one-fifth should be set in a certain place, or the system default in the query optimization of an empirical value, in the future of the processing of learning to attract attention.

Workaround:

Forced Walk Index

SELECT * FROM  
Dep_datebetween ' 2017-12-01 ' and ' 2017-12-30 '

  

Mysql:mysql between date index problem-date index use

Related Article

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.