MySQL Fuzzy query optimization

Source: Internet
Author: User
Tags mysql manual

Use the following function to make a fuzzy query, if the occurrence of the position >0, indicates that the string is contained.

Query efficiency is higher than like.
Such as:

Table.field like  '%aaa% ' can be changed to locate (' AAA ', Table.field) > 0

Note: Locate (SUBSTR,STR)


Use explain to see the results, the less rows the better!

1, use like query

2, query with locate

It is obvious that, although the rows of the two are the same here, the value of filtered, after locate, is 10 times times the value of like.

Note: the column is filtered described in the MySQL manual:

The filtered column indicates an estimated percentage of table rows that would be filtered by the table condition. That's, rows shows the estimated number of rows examined and rowsxfiltered/100 shows the number of rows that would be Joined with previous tables. This column is displayed if EXPLAIN EXTENDED. (New in MySQL 5.1.12)

In other words,the higher the filtered, the better!

MySQL Fuzzy query optimization

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.