A little supplement to MySQL index

Source: Internet
Author: User
Tags mysql index

Index is a very important thing in MySQL, the common concept of the Internet is everywhere, here is not written out, the main point of their own in peacetime use a little attention in the process, in case of later self-check:

-  like '%xx'    Select *  fromTb1whereName like '%CN';--Index not used    Select *  fromTb1whereName like' CN%';---Use index--use function--not using index SELECT * from TB1 where reverse (name) ='Hwan'; --Using the index SELECT * from TB1 WHERE name = Reverse ('Hwan'); -or select * from tb1 where nid = 1 or email ='Seven@live. com'; Special: When the OR condition has an unindexed columns invalidation, the following will go through the index select * from tb1 where nid = 1 or name ='Seven'; SELECT * from tb1 where nid = 1 or email ='Seven@live. com'and name ='Alex'-Inconsistent type if the column is a string type, the incoming condition must be enclosed in quotation marks, otherwise ... select * from tb1 WHERE name = 999;-! = select * from TB1 where name! = 'Alex'--all Special: If the primary key is still going to go index select * from TB1 where nid! = 123--range-> select * from TB1 where name & Gt 'Alex'Special: If the primary key or index is an integer type, then the index select * from TB1 where nid > 123 select * from TB1 where num > 123-    Order BY Select e-mail from tb1 order by name Desc; When sorting by index, the selected mappings are not indexed if they are not indexes: if the primary key is sorted, then the index: SELECT * from Tb1 ORDER by nid desc;                -Combined index leftmost prefix if the combined index is: (name,email) name and email--Use index name--use index email --Do not use indexes

A little supplement to MySQL 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.