+ -
当前位置:首页 → 问答吧 → 关于优化一个MYSQL中以诸个临时表索引字段连接在一起的多表联合SQL.

关于优化一个MYSQL中以诸个临时表索引字段连接在一起的多表联合SQL.

时间:2011-06-23

来源:互联网

这个SQL语句是一个整合的语句,在一个软件中使用,不可以拆分,它一旦执行,将从原始表库搜索6个用表,从而生成6个临时表.这6个表的结构近似,里面的实际字段很多.并非这里写出就这几个.如下,除了指标之类的字段外,其他这些写出来的都是索引字段.每个表以外连接相连.目前执行很慢.我想请教这里的高手,如何优化才能更快的执行.
a1--a6这些表的结构为:

bsc|startdate|starttime|stopdate|stoptime|bts_index|bts_sector|cell_name|cell_ci|cell_lac|指标11|指标12|...
sql语句为:

select a1.startdate, concat(hour(a1.starttime),':00:00') as starttime, a1.Sector1, 
a1.sum_rt1_指标11+a2.sum_rt2_指标23 as `SDCCH信道切换掉话次数`,
a2.sum_rt2_指标22*0.4 as `二级干扰频带内的空闲信道平均数`,
a3.sum_rt3_指标33/a5.sum_rt4_指标45 as `上行LLC流量`,a4.DDDDD as `NB_PSI_MES`,
a5.sum_rt4_指标44 as `最坏小区个数`,
a6.sum_rt5_指标55 as `下行报务率`
from
(select startdate, concat(hour(starttime),':00:00') as starttime, concat BSC,'_',CELL_NAME,'_',BTS_INDEX,'_',BTS_SECTOR)as Sector1,
count(distinct(starttime))*90000 as CountDuration,
sum(rt1.`指标11`) as sum_rt1_指标11
sum(rt1.`指标12`) as sum_rt1_指标12
from omdb.rt110celltrxrelatedoverviewcounters1 rt1 
where startdate >= '2011-06-21' and startdate <= '2011-06-21' and starttime >= '08:00:00' and starttime < '09:00:00' 
group by startdate, hour(starttime), BSC,CELL_NAME,BTS_INDEX,BTS_SECTOR)
a1
left join 
a2.....left join......a3.....left join ......a4.....left join......a5........left join ....... a6

作者: zenistzw   发布时间: 2011-06-23

强制使用startdate 上得索引

作者: rucypli   发布时间: 2011-06-24

相关阅读 更多

热门下载

更多