3 つのテーブルがあり、それらをlikeマッチで検索する必要があります。クエリは 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) を使用して、フィールド値から特殊文字を削除し、そのキーワードで計算しました..