暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
10_4_SQL语句改写代码
422
8页
4次
2019-12-31
5墨值下载
高性能 SQL 调优精要与案例解析 10.4 SQL 语句改写
电子工业出版社 闫书清
10.4 SQL 语句改写
10.4.1 消除视图
改写前:
SQL> create view v_test as
select * from tab1 where col1=...;
SQL> select * from tab2 t2,tab3 t3,v_test v
where t2.col1=t3.col1
and t3.col1=v.col1
and v.col2=...;
改写后:
SQL> select * from tab2 t2,tab3 t3,tab1 t1
where t2.col1=t3.col1
and t3.col1=t1.col1
and t1.col2=...
and t1.col1=...;
10.4.2 标量子查询改为外连
改写前:
SQL> select t1.col1,
(
select col2
from
(
select t2.col1,sum(t2.col2) col2
from tab2 t2
group by t2.col1
) t3
where t3.col1=t1.col2
) col2_sum
from tab1 t1
where t1.col3=...;
改写后:
SQL> select t1.col1,t3.col2 col2_sum
from tab1 t1,
(
select t2.col1,sum(t2.col2) col2
from tab2 t2
group by t2.col1
) t3
where t1.col2=t3.col1(+)
and t1.col3=...;
高性能 SQL 调优精要与案例解析 10.4 SQL 语句改写
电子工业出版社 闫书清
10.4.3 update 改为 merge into
改写前:
SQL> update tab1 t1 set col2=
(
select col2
from tab2 t2
where t1.col1=t2.col1
)
where t1.col3=...;
改写后:
SQL> merge into tab1 t1
using tab2 t2
on
(
t1.col1=t2.col1
)
when matched then
update set t1.col2=t2.col2
where t1.col3=...;
10.4.4 正确使用分析函数
改写前:
SQL> select t1.col1 from tab1 t1
where t1.col2>
(
select avg(col2)
from tab1 t2
where t2.col3=t1.col3
);
改写后:
SQL> select t2.col1 from
(
select t1.col1,t1.col2,avg(t1.col2) over(partition by c3) avg_col2
from tab1 t1
) t2
where t2.col2>t2.avg_col2;
10.4.5 with as 去除多次扫
改写前:
SQL> select t1.col1,t1.col2 from tab1 t1
where t1.col3 in
(
select col2
from tab2
where col1=...
)
and t1.col4 in
of 8
5墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜