【发布时间】:2019-09-20 17:41:40
【问题描述】:
在探索来自 CloudWatch 的日志时,我发现了一些我无法解释的查询
# Time: 190726 1:05:16
# User@Host: company[company] @ [210.10.5.183] Id: 938
# Query_time: 238.040510 Lock_time: 0.000033 Rows_sent: 8988370 Rows_examined: 8988370
use application;
SET timestamp=1564103116;
SELECT /*!40001 SQL_NO_CACHE */ * FROM `dictionary_translations`;
# Time: 190726 1:09:53
# User@Host: company[company] @ [210.10.5.183] Id: 938
# Query_time: 277.528088 Lock_time: 0.000035 Rows_sent: 3223714 Rows_examined: 3223714
SET timestamp=1564103393;
SELECT /*!40001 SQL_NO_CACHE */ * FROM `email_events`;
...
正如您所见,这些查询花费了很多时间,因此必须对其进行优化。
应用程序在 Rails 上运行,也许 Active Record 正在做一些同步?
这些查询的“性质”是什么?如何优化?
【问题讨论】:
-
没有
WHERE子句。您正在获取字典中的每条记录。那是 800 万行。根据您的使用方式,您可能需要限制它。 -
dictionary_translations 是视图.. 还是平面表??
标签: mysql sql ruby-on-rails rails-activerecord amazon-cloudwatch