MySQL Query index

Source: Internet
Author: User
Tags mysql query

Can MySQL use the index in a like query? Where do you use the index?

When using like, if you use ' percent ', will you use the index?
EXPLAIN SELECT * from ' user ' WHERE username like '%ptd_% ';  The result above is a full table scan (type = = All) and is not used to the index.  Just use a% query result: EXPLAIN SELECT * from ' user ' WHERE username like ' ptd_% '; this is used to index (type = = range). EXPLAIN SELECT * from ' user ' where username like '%ptd_ '; in front of use% is also full table scan, not used to index. In summary, MySQL uses a like query only when it does not start with a%, the index is used.

MySQL Query index

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.