多个关联表的优化?

经常碰到类似这样的语句假设有5个表,每个表都是500万左右的记录表名是a,b,c,d,e语句如下select a.idfrom aleft join b on a.id=b.idleft join c on c.custno=d.custnoleft join d on d.name=e.name and e.startdate>='20171026'假设表上语句where字段上的索引都...显示全部

经常碰到类似这样的语句

假设有5个表,每个表都是500万左右的记录
表名是a,b,c,d,e
语句如下

select a.id
from a
left join b on a.id=b.id
left join c on c.custno=d.custno
left join d on d.name=e.name and e.startdate>='20171026'

假设表上语句where字段上的索引都有,统计信息也是最新的,
请问这样的语句如何优化?

收起
参与18

查看其它 3 个回答liveonsky的回答

liveonskyliveonsky数据库开发工程师sr

1.关联字段id、custno没问题,用离散性大的字段,并添加索引
2.上面a、b表关联没问题 到在关联c表就产生笛卡尔集了,关联中最忌讳次情况发生
3.a表示主表,其他都是left join 并不会减少数据量,若确定d表是筛选条件可以作为主表

银行 · 2018-05-30

回答者

liveonsky
数据库开发工程师sr

liveonsky 最近回答过的问题

回答状态

  • 发布时间:2018-05-30
  • 关注会员:6 人
  • 回答浏览:2026
  • X社区推广