mysql fuzzy query like optimization

Use like %value% without indexing

SELECT `column` FROM `table` WHERE `field` like '%keyword%';

1. You can use like value% to match the previous value, and you can go to the index

SELECT `column` FROM `table` WHERE `field` like 'keyword%';

2. Use mysql built-in function to
query the position of the content in the field value

-- 查询keyword在field中的位置
SELECT `column` FROM `table` WHERE LOCATE('keyword', `field`)>0

-- 等同与上面的别名
SELECT `column` FROM `table` WHERE POSITION('keyword' IN `filed`)

-- 同别名
SELECT `column` FROM `table` WHERE INSTR(`field`, 'keyword' )>0 

Description: keyword represents the content that needs to be matched, and field is a database field

Guess you like

Origin blog.csdn.net/weixin_44684303/article/details/112023121