gpt4 book ai didi

mysql - 存在公式减慢查询。需要优化

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

WHERE   
AND NOT EXISTS
(SELECT cl.userID
FROM campaign_list cl
WHERE cl.userID = customer_profile.userID
AND (cl.notes = 'report12' or cl.notes = 'report16')
)
AND EXISTS
(SELECT cl.userID
FROM campaign_list cl
WHERE cl.userID = customer_profile.userID
AND cl.notes = 'report11'
)
AND
(SELECT max(cl.send_date)
FROM campaign_list cl
WHERE cl.userID = customer_profile.userID
AND cl.notes = 'report11'
) > lastSuccessfulDepositDate

如果没有这些行,查询将在大约 20 秒内运行。但是,使用上面的代码,运行大约需要 3 分钟。

事件列表只有 3,700 行,但它正在缓慢而稳定地增长。有什么关于加快查询速度的建议吗?

最佳答案

您是否有以下索引:campaign_list(userID, notes, send_date)?这将是三个子查询的最佳索引。

那我想问一下,你有没有分别尝试过每一个条件?也就是说,你知道每个人是否需要 1 分钟吗?或者,一个在 00:02:59 之间,另外两个在 00:00:01 之间?

并且,您可以将三个条件简化为这两个:

WHERE   
AND NOT EXISTS
(SELECT cl.userID
FROM campaign_list cl
WHERE cl.userID = customer_profile.userID AND
cl.notes IN ('report12', cl.notes = 'report16')
)
AND EXISTS
(SELECT cl.userID
FROM campaign_list cl
WHERE cl.userID = customer_profile.userID AND
cl.notes = 'report11' and
cl.send_date > ?.lastSuccessfulDepositDate
)

同样的指标也适用于此。

注意:在这种情况下,in 不会真正影响性能,但更易于编写和阅读。

关于mysql - 存在公式减慢查询。需要优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39537601/

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