我有三张桌子,我必须用类似的匹配来搜索它们。该查询运行超过 10,000 条记录。它工作正常,但需要 4 秒才能给出结果。我能做些什么来提高速度并将其缩短到 1 秒?
profile_category_table
----------------------
restaurant
sea food restaurant
profile_keywords_table
----------------------
rest
restroom
r.s.t
company_profile_table
---------------------
maha restaurants
indian restaurants
询问:
SELECT name
FROM (
(SELECT PC_name AS name
FROM profile_category_table
WHERE PC_status=1
AND PC_parentid!=0
AND (regex_replace('[^a-zA-Z0-9\-]','',remove_specialCharacter(PC_name)) LIKE '%rest%')
GROUP BY PC_name)
UNION
(SELECT PROFKEY_name AS name
FROM profile_keywords_table
WHERE PROFKEY_status=1
AND (regex_replace('[^a-zA-Z0-9\-]','',remove_specialCharacter(PROFKEY_name)) LIKE '%rest%')
GROUP BY PROFKEY_name)
UNION
(SELECT COM_name AS name
FROM company_profile_table
WHERE COM_status=1
AND (regex_replace('[^a-zA-Z0-9\-]','',remove_specialCharacter(COM_name)) LIKE '%rest%')
GROUP BY COM_name))a
ORDER BY IF(name LIKE '%rest%',1,0) DESC LIMIT 0, 2
我也添加了 INDEX FOR THAT 列。
如果用户在文本框中使用文本进行搜索..自动建议结果应该是..
结果
restaurant
sea food restaurant
maha restaurants
indian restaurants
rest
restroom
r.s.t
我使用 regex_replace('[^a-zA-Z0-9-]','',remove_specialCharacter(COM_name) 从字段值中删除特殊字符并使用该关键字进行数学运算..