gpt4 book ai didi

mysql - 嵌套子查询太慢

转载 作者:行者123 更新时间:2023-11-29 07:02:43 26 4
gpt4 key购买 nike

以下使用双重嵌套子查询的 mysql 查询太慢

SELECT t.name
FROM creatives AS c
INNER JOIN term_relationships AS tr ON tr.creative_id=c.creative_id
INNER JOIN terms AS t ON t.term_id=tr.term_id
WHERE c.creative_id IN
(SELECT creative_id
FROM term_relationships
WHERE term_id IN
(SELECT offer_term_id
FROM offer_urls))
AND t.taxonomy LIKE 'ad_network';

内部查询

SELECT creative_id
FROM term_relationships
WHERE term_id IN
(SELECT offer_term_id
FROM offer_urls)

非常快(0.04秒)

但是完整的查询不会提供结果。等了大约5分钟我就放弃了。

有什么办法可以优化这个吗?

最佳答案

尝试:

SELECT t.name
FROM creatives AS c
JOIN term_relationships AS tr ON tr.creative_id=c.creative_id
JOIN terms AS t ON t.term_id=tr.term_id
JOIN term_relationships tr2 ON tr2.creative_id = c.creative_id
JOIN offer_urls ou ON ou.offer_term_id = tr2.term_id
WHERE t.taxonomy LIKE 'ad_network';

这个仅使用 JOIN 编写的版本会快得多。

关于mysql - 嵌套子查询太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42799132/

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