吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1643|回复: 1
收起左侧

[其他转载] Oracle union all 优化问题——善用执行计划

[复制链接]
woaishizhende1 发表于 2021-10-15 22:46
执行情况的描述: 单个代码块运行较快,约10秒内,但两个代码 通过 union all 连接后,运行时间大约15分钟。
解决方案:Oracle 的 PL\SQL 的 F5 进入 执行计划界面,查看程序运行的时间以及提高执行速度的代码修改方法。
本质是:前面的代码块有重复调入表,全局搜索过多。
1、表连接时,把有索引的表作为主表进行连接,
2、表连接时,连接条件为多个时,可把多个条件通过'||'连接成一个联合条件进行连接,
3、表连接时,减少限制条件使用 in,not
4、表连接时,在where 减少 不同表的限制条件
由于工作需要,对原来的代码进行简写
with t1 as (
select
from t join s on t.a  = s.a and t.b = s.b
where t.c in ('')
and s.限制条件
group by
),
t2 as (
select
from t join s on t.a  = s.a and t.b = s.b
where t.c in ('')
and s.限制条件
group by
),
t3 as (
select
from t join s on t.a  = s.a and t.b = s.b
where t.c in ('')
and s.限制条件
group by
)
select XX
from t1 left join t3 on 条件
union all
select XX
from t1 left join t2 on 条件;
修改后
with t1 as (
select
from s(有索引的表)  join (select a ,b from t where t.c = '' ) t on t.a|| t.b  = s.a|| s.b
where t.限制条件
group by
),
t2 as (
select
from s(有索引的表)  join (select a ,b from t where t.c = '' ) t on t.a|| t.b  = s.a|| s.b
where t.限制条件
group by
),
t3 as (
select
from s(有索引的表)  join (select a ,b from t where t.c = '' ) t on t.a|| t.b  = s.a|| s.b
where t.限制条件
group by
)
select XX
from t1 left join t3 on 条件
union all
select XX
from t1 left join t2 on 条件;

免费评分

参与人数 1吾爱币 +5 热心值 +1 收起 理由
苏紫方璇 + 5 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

a397555462 发表于 2021-10-16 10:58
使用”||“连接多个条件,也会正常走索引吗?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-18 04:04

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表