0

我对 mysql 优化和索引很陌生,但在我的新项目中,我会尝试更多地使用索引并获得更好的理解。

但是现在我在连接和 group_concat 和索引方面遇到了困难,我无法让它正常工作我已经在 tags.item_id 和 items.id 上设置了索引有主索引。

我可以从我的解释查询中看到它没有使用任何索引来进行此查询。

EXPLAIN
SELECT i.id, i.title, i.content, GROUP_CONCAT(DISTINCT t.name SEPARATOR ",") as tags 
FROM items as i 
LEFT OUTER JOIN tags as t ON t.item_id = i.id 
WHERE i.id = 103 GROUP BY i.id

结果:

1   SIMPLE  i   const   PRIMARY PRIMARY 4   const   1   
1   SIMPLE  t   ref item_id item_id 5   const   4   

希望有人可以帮助我并解释我做错了什么以及我应该如何做才能获得使用索引的正确查询。

4

1 回答 1

0

You cannot create an index on a function in MySql. A solution would be storing the tags in another column of your table and index it. Also index t.item_id ! for more explains go here

于 2012-07-02T10:36:17.913 回答