需要一些查询帮助。 在数据库中有〜700k图像,每个图像都有自己的标签。 我希望能够使用全文搜索查询按标签搜索图片。 该查询完全符合我的要求,但速度很慢。 有些人可以帮助我加快速度,或创建另一个。 在'image_tag'表中的id字段和名称字段中存在索引。缓慢的mysql查询全文搜索标签数据库
SELECT
image.*
FROM image
INNER JOIN (SELECT image_to_tag.image_id,
GROUP_CONCAT(image_tag.`name`) AS tags
FROM image_to_tag
INNER JOIN image_tag
ON (image_tag.id = image_to_tag.image_tag_id)
GROUP BY image_to_tag.image_id) t ON t.image_id = image.id
WHERE MATCH (t.tags) AGAINST ('+justin* +backgrounds*' IN BOOLEAN MODE)
表:图像
id | filename
1 | image1.jpg
2 | image2.jpg
3 | image3.jpg
表:image_to_tag
image_id | image_tag_id
1 | 1
1 | 2
2 | 3
2 | 4
表:IMAGE_TAG
id | name
1 | justin bieber
2 | backgrounds
3 | justin timberlake
4 | other backgrounds
如果我搜索 “贾斯汀背景” 我想找到图像1和2. 如果我搜索“贾斯汀·比伯背景”,我想查找图片1.
首先,避免在查询中使用'*'。 – RubahMalam
已经尝试过,但它没有太大帮助,0.1秒。 –