Mysql SQL语句运行缓慢
从日志表加载数据时遇到问题。我正在尝试筛选包含字符串的列上的表。下面是我使用的语句。我可以在4周前提取数据,但当我尝试提取更多历史数据时,它会超时。我把暂停时间延长到了600秒,但还是犯了同样的错误。所以我想有更好的方法来写我的陈述 此外,如果可能的话,我希望有基于该值的最新时间戳 先谢谢你。 乔 对于此查询:Mysql SQL语句运行缓慢,mysql,sql,performance,loading,statements,Mysql,Sql,Performance,Loading,Statements,从日志表加载数据时遇到问题。我正在尝试筛选包含字符串的列上的表。下面是我使用的语句。我可以在4周前提取数据,但当我尝试提取更多历史数据时,它会超时。我把暂停时间延长到了600秒,但还是犯了同样的错误。所以我想有更好的方法来写我的陈述 此外,如果可能的话,我希望有基于该值的最新时间戳 先谢谢你。 乔 对于此查询: select dl.user_id, dl.timestamp, dl.value, dl.operation, concat(concat(un.first_name,
select dl.user_id, dl.timestamp, dl.value, dl.operation,
concat(concat(un.first_name, ' '),
un.last_name) AS "User"
from data_log dl
where dl.timestamp >= date '2019-12-01' and
dl.operation = 'update' and
dl.values like '%"date_time"%';
您需要一个关于数据操作、时间戳和值的索引。这可能有助于解决性能问题。我们讨论了多少行?有哪些索引?还有,您希望like匹配什么,即dl.values的形式是什么?dl.values的类型是什么?有关查询性能的问题始终需要对所有相关表执行SHOW CREATE TABLE语句以及对给定查询的解释。另外,请注意,像“%”一样,不能使用索引
select dl.user_id, dl.timestamp, dl.value, dl.operation,
concat(concat(un.first_name, ' '),
un.last_name) AS "User"
from data_log dl
where dl.timestamp >= date '2019-12-01' and
dl.operation = 'update' and
dl.values like '%"date_time"%';