In MySQL, likexxx % can use indexes, but like % xxx % cannot. Mysqldescartist; + ------------ + --------------------------------------------- + ------ + ----- + ---------
In MySQL, likexxx % can use indexes, but like % xxx % cannot. Mysqldescartist; + ------------ + --------------------------------------------- + ------ + ----- + ---------
Indexes can be used for like 'xxx % 'in MySQL, but like' % xxx % 'cannot.
For example:
Now we can further optimize it by overwriting the index:
Here, artist_id is the primary key (clustered index), and the data (InnoDB engine) is saved on the leaf node. The select artist_id column can be obtained from the index, you do not need to read data rows (as long as your SELECT field is an index, you can use the overwrite Index). By overwriting the index and server space, you can reduce IO and improve performance.
Overwrite the index simply: I want to find a content in the book, but I wrote this directory in detail and I got it in the directory. I don't need to go to this page to view it.
Previous SQL Execution time:
Optimized SQL Execution time:
This article is from the blog "hechun's technical column". The server space must be retained.