执行较慢的待优化的SQL:
update business_new
set fare1_balance_ratio = (select BALANCE_RATIO from bfare2
where bfare2.exchange_type = business_new.exchange_type and
bfare2.stock_type = business_new.stock_type and
(bfare2.entrust_way = business_new.entrust_way) and
(bfare2.entrust_type = business_new.entrust_type)
and bfare2.fare_type = '0')

从执行计划可以看出,走的就是nl关联,所以慢是正常的。
于是将其改写为merge,如下:
merge into business_new using bfare2
on (bfare2.exchange_type = business_new.exchange_type and
bfare2.stock_type = business_new.stock_type and
(bfare2.entrust_way = business_new.entrust_way) and
(bfare2.entrust_type

文章讨论了如何通过将SQL查询中的`update`语句改写为`merge`和`inlineview`来提高性能,强调了主键关联的重要性以及避免ORA-01779错误的方法。还提到了使用批量update和针对大数据表的优化技巧,如分区表和临时禁用索引。
最低0.47元/天 解锁文章
3万+

被折叠的 条评论
为什么被折叠?



