SQL Fuzzy Query optimization

Source: Internet
Author: User

When you use a like fuzzy query in an SQL statement, you should try to avoid the percent of percent, because the fuzzy query is relatively slow, and when this happens, you should consider optimization.

For example, I query a table for records created in 2012

SELECT * from ' component_data ' WHERE creation_date like ' 2012% ';

Time to get

[SQL] SELECT * from ' component_data ' WHERE creation_date like ' 2012% '; rows affected: 0 Time: 0.500ms

Consider the following SQL after optimization

SELECT * from ' component_data ' WHERE creation_date>= ' 2012-01-01 ' and creation_date< ' 2013-01-01 ';

Run results

[SQL] SELECT * from ' component_data ' WHERE creation_date>= ' 2012-01-01 ' and creation_date< ' 2013-01-01 '; rows affected: 0 Time: 0.328ms

It can be seen that the improvement after the optimization is very large. This difference is more pronounced when the results of the query are relatively long. I have more than 9,000 data for this query.

I just cite an example. When you encounter like query, we should give full play to your intelligence, specific problems to be specific treatment, to optimize

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.