High Case sensitivity and performance of mysql queries

Source: Internet
Author: User

High Case sensitivity and performance of mysql queries

Mysql queries are case-insensitive by default, for example:

1

2

3

4

5

6

7

<A href = "/tags. php/select/" target = "_ blank"> select </a> * from table_name where a like 'a %'

 

Select * from table_name where a like 'a %'

 

Select * from table_name where a like 'a %'

 

Select * from table_name where a like 'a %'

The results are the same.

To make mysql queries case sensitive, you can:
 

1

2

3

4

5

6

7

Select * from table_name where binary a like 'a %'

 

Select * from table_name where binary a like 'a %'

 

Select * from table_name where binary a like 'a %'

 

Select * from table_name where binary a like 'a %'

You can also identify a table when creating it.
 

1

2

3

4

5

6

7

8

9

10

11

Create table table_name (

 

A varchar (20) binary

 

)

 

Create table table_name (

 

A varchar (20) binary

 

)

Test 30 W data

1

SELECT * FROM 'tablename' WHERE (BINARY weixin = 'value') LIMIT 1;

Indexing is not supported. It is not recommended to consider the query efficiency. The preceding SQL statements do not have any problems at first glance, but when there is more data in the table, the problem will be highlighted. If no index is used, the query efficiency will be very low.

 

 

Supports indexing and high query efficiency (recommended)

1

SELECT * FROM 'tablename' WHERE weixin = 'value' COLLATE utf8_bin LIMIT 1;

Query analysis:



The above description clearly shows the fundamental difference between the two SQL statements in efficiency. Use binary with caution.

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.