SQL等价改写优化案例精选资料.docVIP

  • 7
  • 0
  • 约4.27万字
  • 约 49页
  • 2016-11-27 发布于湖北
  • 举报
SQL 等价改写优化案例精选 一.统一天下 解释为:巧用各类技巧合并代码,减少表扫描次数。 案例 1 注重 COUNT(CASE WHEN)之类的合并技巧 select distinct ne_state.peer_id peer_name, to_char(ne_state.ne_state) peer_state, (case when ne_state.ne_state = 0 then to_char(0) else (select distinct to_char(nvl(ne_active.active, 0)) from dcc_sys_log, (select peer_id, decode(action, active, 1, de-active, 0, 0) active, max(log_time) from dcc_sys_log where action = active or action = de-active group by (peer_id, action)) ne_active where dcc_sys_log.peer_id = ne_active.peer_id(+) and dcc_sys_log.peer_id = ne_state.peer_id) end) peer_active, (case when ne_state.ne_state = 0 then to_char(0) else (to_char(nvl((select count(*) from dcc_ne_log where dcc_ne_log.result 1 and peer_id = ne_state.peer_id and log_time between trunc(sysdate) and sysdate group by (peer_id)), 0))) end) err_cnt, (case when ne_state.ne_state = 0 then to_char(0) else (to_char(nvl((select count(*) from dcc_ne_log in_dnl where in_dnl.direction = recv and in_dnl.peer_id = ne_state.peer_id and log_time between trunc(sysdate) and sysdate), 0))) end) recv_cnt, (case when ne_state.ne_state = 0 then to_char(0) else (to_char(nvl((select sum(length) from dcc_ne_log in_dnl where in_dnl.direction = recv and in_dnl.peer_id = ne_state.peer_id and log_time between trunc(sysdate) and sysdate), 0))) end) recv_byte, (case when ne_state.ne_state = 0 then to_char(0) else (to_char(nvl((select count(*) from dcc_ne_log in_dnl where in_dnl.direction = send and in_dnl.peer_id = ne_state.peer_id and log_time between trunc(sysdate) and sysdate), 0))) end) send_cnt, (case when ne_state.ne_state = 0 then to_char(0) else (to_char(nvl((select sum(length) from dcc_ne_log in_dnl where in_dnl.direction = send and in_dnl.peer_id = ne_state.peer_id and log_time between trunc(sysdate) and sysdate), 0))) end) send_byte from dcc_ne_log, (select distinct dsl1.peer_id peer_id, nvl(ne_disconnect_info.ne_state, 1) ne_state from dcc_sys_log dsl1, (select distinct dnl.peer_id peer_id, decode(action, disconnect, 0

文档评论(0)

1亿VIP精品文档

相关文档