Home > Database > Mysql Tutorial > body text

How to Optimize MySQL LIKE Queries with Wildcards?

Barbara Streisand
Release: 2024-11-02 16:45:03
Original
975 people have browsed it

How to Optimize MySQL LIKE Queries with Wildcards?

Optimizing MySQL LIKE Queries with Wildcards

When dealing with LIKE queries involving wildcards (e.g., '%test%'), the performance of MySQL can suffer. To address this issue, there are techniques to enhance the performance of such queries.

MySQL can leverage an index for LIKE queries that conform to the pattern 'foo LIKE 'abc%' or 'foo LIKE 'abc�f%'. This is possible because the index can utilize the string portion preceding the first wildcard. However, if the goal is to match a word anywhere within a string, considering FULLTEXT indexes may be a viable alternative.

For further insights on index usage, refer to this resource: http://dev.mysql.com/doc/refman/5.1/en/mysql-indexes.html

For more information on full-text search capabilities, please consult: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

The above is the detailed content of How to Optimize MySQL LIKE Queries with Wildcards?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!