Home >Database >Mysql Tutorial >How Can Fulltext Indexes Enhance Performance for LIKE \'%string%\' Queries in InnoDB?
Background: Optimizing queries that utilize the LIKE '%string%' syntax can be challenging, especially in an InnoDB environment. To address this, let's delve into the available options and their limitations.
Limitations of Basic Indexing:
Creating a standard index, as demonstrated with ALTER TABLE example ADD INDEX idxSearch (keywords);, does not resolve the performance issue for queries like LIKE '%whatever%'. This is because InnoDB indexes are constructed from the beginning of the string to the end. As a result, "floating" searches, where the string can appear anywhere within the field, cannot leverage these indexes.
Introducing Fulltext Indexes:
For flexible string searches, fulltext indexes come into play. They are tailored for scenarios where search terms can appear anywhere in the indexed column. InnoDB's support for fulltext indexes as of version 5.6.4 enables leveraging their benefits even with InnoDB tables.
Implementation:
To implement a fulltext index, execute the following query:
ALTER TABLE example ADD FULLTEXT INDEX (keywords)
Benefits of Fulltext Indexes:
Additional Considerations:
The above is the detailed content of How Can Fulltext Indexes Enhance Performance for LIKE \'%string%\' Queries in InnoDB?. For more information, please follow other related articles on the PHP Chinese website!