现有两张数据表:A、B

# A 表,只有 id 有唯一索引(primary key)
id、name、description、age...

# B 表,只有 id 有唯一索引(primary key)
id、task_id、index_name、status、final_status...

问题:A left join B 速度很慢:

select a.id, a.name, a.description, a.age, b.task_id, b.index_name, b.status, b.final_status from A as a left join B as b on a.id=b.task_id;

原因:task_id 没有索引

解决方案:给 B.task_id 添加索引

# 添加普通索引
alter table B add index task_id(task_id);

相关文章:

  • 2021-08-31
  • 2021-12-07
  • 2022-12-23
  • 2021-08-11
  • 2022-12-23
  • 2021-06-10
  • 2021-05-16
  • 2021-08-14
猜你喜欢
  • 2021-11-04
  • 2021-12-07
  • 2022-12-23
  • 2021-03-30
  • 2021-12-26
  • 2021-12-26
相关资源
相似解决方案