gpt4 book ai didi

mysql - mysql查询全文检索标签数据库慢

转载 作者:行者123 更新时间:2023-11-29 21:59:20 25 4
gpt4 key购买 nike

需要一些查询帮助。数据库中有大约 70 万张图像,每个图像都有自己的标签。我希望能够通过全文搜索查询通过图像的标签来搜索图像。该查询完全符合我的要求,但速度非常慢。有人可以帮我加快速度吗,或者创建另一个。“image_tag”表中的所有 id 字段和名称字段都有索引。

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。如果我搜索“justin bieber 背景”,我想找到图像 1。

最佳答案

请尝试这个,并告诉我是否可以更快一点。

select id,filename from image
where id in(
select image_id from image_to_tag a
inner join image_tag b
on b.id = a.image_tag_id and b.name like '%justin%'
)

关于mysql - mysql查询全文检索标签数据库慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32811637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com