gpt4 book ai didi

mysql - 慢更新查询

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

我在从 select 语句更新表时遇到问题...命令如下:

UPDATE CrashReport SET STATUS = '2' WHERE id IN (
SELECT report_id
FROM CrashInfo
WHERE info_title LIKE 'STACK_TRACE_ID'
AND info_value IN (
SELECT info_value
FROM CrashInfo
WHERE report_id = **report_id**
AND info_title = 'STACK_TRACE_ID'
)
)

我传递给此查询的参数将是子子查询中的report_id...选择需要0.113秒来单独执行,但更新查询总共需要0.113秒执行时间为 4.868 秒。是因为更新查询将对表的每一行执行 select 语句吗?我怎样才能让它更快?

谢谢

最佳答案

类似这样的事情:

SET @myVal = (
SELECT info_value
FROM CrashInfo
WHERE report_id = **report_id**
AND info_title = 'STACK_TRACE_ID');

UPDATE CrashReport SET STATUS = '2' WHERE id IN (
SELECT report_id
FROM CrashInfo
WHERE info_title LIKE 'STACK_TRACE_ID'
AND info_value IN (@myVal)
)

关于mysql - 慢更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22050471/

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