Whether MySQL uses an indexed instance

Source: Internet
Author: User

① using a composite index (UserName, userage) ② using a composite index (USERAGE,USERNAME)

1.select * from T_user where userName in (' DD ', ' GG ') will use the index under ② without indexing under ①;

2.select * from T_user where userage=3 will not use indexes under ② under ①;

3.select * from T_user where userName like ' saa% ' will use the index under ①

4.select * from T_user where userName like '%saa% ' will not use the index in ①

5.select * from T_user where userage>3 (or between and) will not be indexed under ② using the index under ①②;

6. Use the union ALL operator instead of union because the union all operation simply merges two results and returns. The Union filters out duplicate records, so the resulting set of results is sorted after the table is connected, the duplicate records are deleted, and the results are returned.

7. Replacing > with >=

Whether MySQL uses an indexed instance

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.