gpt4 book ai didi

MySQL 慢双连接

转载 作者:行者123 更新时间:2023-11-30 23:34:18 25 4
gpt4 key购买 nike

我有一个包含 from_uidto_uid(均已编入索引)的链接表,我想过滤掉某些 ID。所以我这样做:

SELECT l.uid
FROM Link l
JOIN filter_ids t1 ON l.from_uid = t1.id
JOIN filter_ids t2 ON l.to_uid = t2.id

现在由于某种原因,这出乎意料地慢 :( 而每个单独的连接都非常快。它不能正确使用索引吗?

EXPLAIN 告诉我:

id  select  table type  possible_keys   key      key_len ref  rows  Extra
1 SIMPLE t1 index Null PRIMARY 34 Null 12205 Using index
1 SIMPLE l ref from_uid,to_uid from_uid 96 func 6 Using where
1 SIMPLE t2 index Null PRIMARY 34 Null 12205 Using where; Using index; Using join buffer

最佳答案

不知道它是否有帮助,但请尝试:

select l.uid
from Link l
where l.from_uid in (select id from filter_ids)
and l.to_uid in (select id from filter_ids)

也许它会更好地使用索引。

关于MySQL 慢双连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8914854/

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