大量的left join 怎么优化select a.id,a.num,b.num,b.pcs,c.num,c.pcs,d.num,d.pcs,e.num,e.pcs,a.x,a.y from a left join b.id=a.id and b.time=a.timeleft join c.id=a.id and b.time=a.timeleft join d.id=a.id and b.time=a.timeleft join e.id=a.id and b.t
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 10:59:38
大量的left join 怎么优化select a.id,a.num,b.num,b.pcs,c.num,c.pcs,d.num,d.pcs,e.num,e.pcs,a.x,a.y from a left join b.id=a.id and b.time=a.timeleft join c.id=a.id and b.time=a.timeleft join d.id=a.id and b.time=a.timeleft join e.id=a.id and b.t
大量的left join 怎么优化
select a.id,
a.num,
b.num,
b.pcs,
c.num,
c.pcs,
d.num,
d.pcs,
e.num,
e.pcs,
a.x,
a.y from a left join b.id=a.id and b.time=a.time
left join c.id=a.id and b.time=a.time
left join d.id=a.id and b.time=a.time
left join e.id=a.id and b.time=a.time
where a.time='2013-10-1'
这样查询效率很低,要几十分钟才能出laugh数据~每张表有上千万条数据,求问该如何优化?
大量的left join 怎么优化select a.id,a.num,b.num,b.pcs,c.num,c.pcs,d.num,d.pcs,e.num,e.pcs,a.x,a.y from a left join b.id=a.id and b.time=a.timeleft join c.id=a.id and b.time=a.timeleft join d.id=a.id and b.time=a.timeleft join e.id=a.id and b.t
在各个表的id和time属性上创建索引,而且把其中除了第一次left join中的 b.time=a.time外,其余的 b.time=a.time去掉,并先对b表执行 b.time='2013-10-1'的查询.
如果各表都需要判断时间的话,那么请先在各表上执行基于时间的选择操作,在参加左外连接.因此,时间字段上的索引很重要.