per*_*eam 4 mysql sql indexing performance select
我有这个mysql查询,我不确定索引查询中的所有字段的含义是什么.我的意思是可以索引CASE语句,Join Statement和Where Statement中的所有字段吗?索引字段是否有任何性能影响?
SELECT roots.id as root_id, root_words.*,
CASE
WHEN root_words.title LIKE '%text%' THEN 1
WHEN root_words.unsigned_title LIKE '%normalised_text%' THEN 2
WHEN unsigned_source LIKE '%normalised_text%' THEN 3
WHEN roots.root LIKE '%text%' THEN 4
END as priorities
FROM roots INNER JOIN root_words ON roots.id=root_words.root_id
WHERE (root_words.unsigned_title LIKE '%normalised_text%') OR (root_words.title LIKE '%text%')
OR (unsigned_source LIKE '%normalised_text."%') OR (roots.root LIKE '%text%') ORDER by priorities
Run Code Online (Sandbox Code Playgroud)
另外,如何进一步提高上述查询的速度?
谢谢!
您索引表中的列,而不是查询.
您指定的搜索条件都不能使用索引(因为搜索条件以外卡开头).
你应该确保id列被索引,以加快JOIN.(据推测,它已经被索引为一个表中的PRIMARY KEY和另一个表中的FOREIGN KEY).
要加快此查询速度,您需要使用全文搜索.添加索引不会加速此特定查询,并且会花费您在INSERT,UPDATE和DELETE上花费时间.