我正在研究一些临时表以供练习。 一个查询花费了大约 550 秒的太多时间。Db 托管在具有 8cpu 和 16GB ram 的 AWS RDS 中。 下面的查询必须在不同的 DB( prod ) 中运行,首先检查测试 testDB
create table test_01 as
select *
from
(
select
person
,age
,dob
,place
from
person
where
person is not null
and age is not null
and dob is not null
and place is not null
limit 1000
) ps_u
left join
employee em_u
on ps_u.age = em_u.em_age
and ps_u.place = em_u.location
order by person
limit 1000
查询或资源是否有问题, CPU 利用率显示 30% ram 还可以,不要太多。 让我知道任何优化查询的建议。
最佳答案
检查您的左联接。这可能是一个原因。 left join 将返回左表中的所有内容,如果该表有很多条目,它会减慢您的查询速度。
有了它,您可以将查询分成两个单独的查询并使用不同的调整检查执行时间。
尝试返回特定行而不是 *。
关于mysql - 查询需要很长时间才能在 AWS RDS 中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47902867/