Oralce多个远程库做关联查询的优化
原数据SQL
SELECT substr(A.NE_NAME, 1, 3) city, ROUND(sum(A.COUNTER_1279177418 * 23 + A.COUNTER_1279177419 * 34 + COUNTER_1279177420 * 40 + COUNTER_1279177421 * 54) / 1024 / 1024 / 1024, 2) + ROUND(sum(B.COUNTER_1279178418 * 23 + B.COUNTER_1279178419 * 34 + COUNTER_1279178420 * 40 + COUNTER_1279178421 * 54) / 1024 / 1024 / 1024, 2) GPRS_RLC_DL, ROUND(sum(COUNTER_1279179418 * 22 + COUNTER_1279179419 * 28 + COUNTER_1279179420 * 37 + COUNTER_1279179421 * 44 + COUNTER_1279179422 * 56 + COUNTER_1279179423 * 74 + COUNTER_1279179424 * 56 + COUNTER_1279179425 * 68 + COUNTER_1279179426 * 74) / 1024 / 1024 / 1024, YUA 2) + ROUND(sum(COUNTER_1279180418 * 22 + COUNTER_1279180419 * 28 + COUNTER_1279180420 * 37 + COUNTER_1279180421 * 44 + COUNTER_1279180422 * 56 + COUNTER_1279180423 * 74 + COUNTER_1279180424 * 56 + COUNTER_1279180425 * 68 + COUNTER_1279180426 * 74) / 1024 / 1024 / 1024, 2) EDGE_RLC_DL FROM (select scan_start_time, MO, NE_NAME, COUNTER_1279177418, COUNTER_1279177419, COUNTER_1279177420, COUNTER_1279177421 from rcounterdb.OP_HUW_ULT_1275072525_3 where scan_start_time >= TO_DATE(TO_CHAR(SYSDATE - 1, 'YYYY-MM-DD'), 'YYYY-MM-DD') and scan_start_time < TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM-DD'), 'YYYY-MM-DD') and to_char(scan_start_time, 'hh24') in ('10', '08', '09', '18', '19', '20')) A, (select scan_start_time, MO, NE_NAME, COUNTER_1279178418, COUNTER_1279178419, COUNTER_1279178420, COUNTER_1279178421 from rcounterdb.OP_HUW_ULT_1275072526_3 where scan_start_time >= TO_DATE(TO_CHAR(SYSDATE - 1, 'YYYY-MM-DD'), 'YYYY-MM-DD') and scan_start_time < TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM-DD'), 'YYYY-MM-DD') and to_char(scan_start_time, 'hh24') in ('10', '08', '09', '18', '19', '20')) B, (select scan_start_time, MO, NE_NAME, COUNTER_1279179418, COUNTER_1279179419, COUNTER_1279179420, COUNTER_1279179421, COUNTER_1279179422, COUNTER_1279179423, COUNTER_1279179424, COUNTER_1279179425, COUNTER_1279179426 from rcounterdb.OP_HUW_ULT_1275072527_3 where scan_start_time >= TO_DATE(TO_CHAR(SYSDATE - 1, 'YYYY-MM-DD'), 'YYYY-MM-DD') and scan_start_time < TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM-DD'), 'YYYY-MM-DD') and to_char(scan_start_time, 'hh24') in ('10', '08', '09', '18', '19', '20')) C, (select scan_start_time, MO, NE_NAME, COUNTER_1279180418, COUNTER_1279180419, COUNTER_1279180420, COUNTER_1279180421, COUNTER_1279180422, COUNTER_1279180423, COUNTER_1279180424, COUNTER_1279180425, COUNTER_1279180426 from rcounterdb.OP_HUW_ULT_1275072528_3 where scan_start_time >= TO_DATE(TO_CHAR(SYSDATE - 1, 'YYYY-MM-DD'), 'YYYY-MM-DD') and scan_start_time < TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM-DD'), 'YYYY-MM-DD') and to_char(scan_start_time, 'hh24') in ('10', '08', '09', '18', '19', '20')) G WHERE a.scan_start_time = B.scan_start_time AND a.scan_start_time = C.scan_start_time AND A.scan_start_time = G.scan_start_time AND A.MO = B.MO AND a.MO = C.MO AND A.MO = G.MO AND A.NE_NAME = B.NE_NAME AND a.NE_NAME = C.NE_NAME AND A.NE_NAME = G.NE_NAME group by substr(A.NE_NAME, 1, 3)
分析一下这条SQL的基本操作是将远程数据库的表进行相应的关联查询,分析性能的损失可能是在远程做链接操作所以将远程的表先搬到本地,然后进行相应的关联操作
通过这种方式所进行的优化方案
--A数据信息提取(39s) create table sniper1 nologging parallel (degree 4) as SELECT A.COUNTER_1279177418, A.COUNTER_1279177419, a.COUNTER_1279177420, a.COUNTER_1279177421, a.scan_start_time, a.MO, a.ne_name from rcounterdb.OP_HUW_ULT_1275072525_3 a where 1 = 1 and to_char(a.scan_start_time, 'hh24') in ('10', '08', '09', '18', '19', '20') AND a.scan_start_time >= TO_DATE('2012-7-1', 'YYYY-MM-DD') and a.scan_start_time < TO_DATE('2012-8-1', 'YYYY-MM-DD') --B信息数据提取(4min) create table sniper1 create table sniper2 nologging parallel (degree 4) as select B.COUNTER_1279178418, B.COUNTER_1279178419, b.COUNTER_1279178420, b.COUNTER_1279178421, b.scan_start_time, b.mo, b.ne_name from rcounterdb.OP_HUW_ULT_1275072526_3 B --C信息数据提取(5min) create table sniper3 nologging parallel (degree 4) as select c.COUNTER_1279179418 ,COUNTER_1279179419 , c.COUNTER_1279179420 ,c.COUNTER_1279179421, c.COUNTER_1279179422 , c.COUNTER_1279179423 ,COUNTER_1279179424,COUNTER_1279179425, c.COUNTER_1279179426,c.scan_start_time,c.mo,c.ne_name from rcounterdb.OP_HUW_ULT_1275072527_3 C --信息数据提取(5min) create table sniper4 nologging parallel (degree 4) as select g.COUNTER_1279180418, g.COUNTER_1279180419, g.COUNTER_1279180420, g.COUNTER_1279180421, g.COUNTER_1279180422, g.COUNTER_1279180423, g.COUNTER_1279180424, g.COUNTER_1279180425, g.COUNTER_1279180426, g.scan_start_time, g.mo, g.ne_name from rcounterdb.OP_HUW_ULT_1275072528_3 G --合并数据量大的中间部分 SELECT substr(A.NE_NAME, 1, 3) city, ROUND(sum(A.COUNTER_1279177418 * 23 + A.COUNTER_1279177419 * 34 + COUNTER_1279177420 * 40 + COUNTER_1279177421 * 54) / 1024 / 1024 / 1024, 2) + ROUND(sum(B.COUNTER_1279178418 * 23 + B.COUNTER_1279178419 * 34 + COUNTER_1279178420 * 40 + COUNTER_1279178421 * 54) / 1024 / 1024 / 1024, 2) GPRS_RLC_DL, ROUND(sum(COUNTER_1279179418 * 22 + COUNTER_1279179419 * 28 + COUNTER_1279179420 * 37 + COUNTER_1279179421 * 44 + COUNTER_1279179422 * 56 + COUNTER_1279179423 * 74 + COUNTER_1279179424 * 56 + COUNTER_1279179425 * 68 + COUNTER_1279179426 * 74) / 1024 / 1024 / 1024, 2) + ROUND(sum(COUNTER_1279180418 * 22 + COUNTER_1279180419 * 28 + COUNTER_1279180420 * 37 + COUNTER_1279180421 * 44 + COUNTER_1279180422 * 56 + COUNTER_1279180423 * 74 + COUNTER_1279180424 * 56 + COUNTER_1279180425 * 68 + COUNTER_1279180426 * 74) / 1024 / 1024 / 1024, 2) EDGE_RLC_DL FROM sniper1 A, sniper2 B, sniper3 C, sniper4 G WHERE a.scan_start_time = B.scan_start_time AND a.scan_start_time = C.scan_start_time AND A.scan_start_time = G.scan_start_time AND A.MO = B.MO AND a.MO = C.MO AND A.MO = G.MO AND A.NE_NAME = B.NE_NAME AND a.NE_NAME = C.NE_NAME AND A.NE_NAME = G.NE_NAME group by substr(A.NE_NAME, 1, 3)
调整后的SQL变为
select X.CITY_NAME, X.CITY_ID, X.city_code, nvl(GSM网数据总流量GB, 0) + nvl(EDGE_RLC_DL + gprs_RLC_DL, 0) all_gprs, nvl(GSM网EDGE数据总流量GB, 0) + nvl(EDGE_RLC_DL, 0) EDGE, ROUND((nvl(GSM网EDGE数据总流量GB, 0) + nvl(EDGE_RLC_DL, 0)) / (nvl(GSM网数据总流量GB, 0) + nvl(EDGE_RLC_DL + gprs_RLC_DL, 0)) * 100, 2) EDGE流量占比 FROM (select c.city_name 城市, C.CITY_ID, c.city_desc city_code, ROUND((SUM(nvl(gprs_rlc_up, 0)) + SUM(nvl(gprs_rlc_dl, 0)) + SUM(nvl(edge_rlc_up, 0)) + SUM(nvl(edge_rlc_dl, 0))) / 1024 / 1024, 2) GSM网数据总流量GB, ROUND((SUM(nvl(edge_rlc_up, 0)) + SUM(nvl(edge_rlc_dl, 0))) / 1024 / 1024, 2) GSM网EDGE数据总流量GB, ROUND((SUM(nvl(edge_rlc_up, 0)) + SUM(nvl(edge_rlc_dl, 0))) / (SUM(nvl(gprs_rlc_up, 0)) + SUM(nvl(gprs_rlc_dl, 0)) + SUM(nvl(edge_rlc_up, 0)) + SUM(nvl(edge_rlc_dl, 0))) * 100, 2) EDGE数量流量占比 from unite.upr_c2_ne_vendor T, config.uc_citys c where t.city_code = c.city_code and to_char(t.GENTIME, 'hh24') in ('10', '08', '09', '18', '19', '20') and t.gentime >= TO_DATE('2012-7-1', 'YYYY-MM-DD') and t.gentime < TO_DATE('2012-8-1', 'YYYY-MM-DD') and t.vendor_name != 'HUAWEI' GROUP BY c.city_name, C.CITY_ID, c.city_desc) m, (SELECT substr(A.NE_NAME, 1, 3) city, ROUND(sum(A.COUNTER_1279177418 * 23 + A.COUNTER_1279177419 * 34 + COUNTER_1279177420 * 40 + COUNTER_1279177421 * 54) / 1024 / 1024 / 1024, 2) + ROUND(sum(B.COUNTER_1279178418 * 23 + B.COUNTER_1279178419 * 34 + COUNTER_1279178420 * 40 + COUNTER_1279178421 * 54) / 1024 / 1024 / 1024, 2) GPRS_RLC_DL, ROUND(sum(COUNTER_1279179418 * 22 + COUNTER_1279179419 * 28 + COUNTER_1279179420 * 37 + COUNTER_1279179421 * 44 + COUNTER_1279179422 * 56 + COUNTER_1279179423 * 74 + COUNTER_1279179424 * 56 + COUNTER_1279179425 * 68 + COUNTER_1279179426 * 74) / 1024 / 1024 / 1024, 2) + ROUND(sum(COUNTER_1279180418 * 22 + COUNTER_1279180419 * 28 + COUNTER_1279180420 * 37 + COUNTER_1279180421 * 44 + COUNTER_1279180422 * 56 + COUNTER_1279180423 * 74 + COUNTER_1279180424 * 56 + COUNTER_1279180425 * 68 + COUNTER_1279180426 * 74) / 1024 / 1024 / 1024, 2) EDGE_RLC_DL FROM sniper1 A, sniper2 B, sniper3 C, sniper4 G WHERE a.scan_start_time = B.scan_start_time AND a.scan_start_time = C.scan_start_time AND A.scan_start_time = G.scan_start_time AND A.MO = B.MO AND a.MO = C.MO AND A.MO = G.MO AND A.NE_NAME = B.NE_NAME AND a.NE_NAME = C.NE_NAME AND A.NE_NAME = G.NE_NAME group by substr(A.NE_NAME, 1, 3)) b, CONFIG.UC_CITYS X WHERE X.CITY_DESC = B.city(+) and x.city_id != 0 AND X.CITY_ID = M.CITY_ID(+) order by x.city_id
调整后SQL的执行时间减少了一半左右。
Mr-sniper
北京市海淀区
邮箱:rafx_z@hotmail.com
北京市海淀区
邮箱:rafx_z@hotmail.com