understand Oracle exec_plan

A sql is slow, but some time is fast. 


We check the created sql text, and use Oracle exec_plan to cehck, find some time it uses index we expect, but some time it uses index we never expect.


The root cause is Oracle cannot decide which index is used, so Oracle will select one, or do full_table_scan.


For example

sql is "select * from SAE_PORTFOLIO_CR_BULK where BATCH_ID={1}. and BOOKING_CENTER={2} and VALOR={3}" ( this is hsql of hibernate)

IDX_PTFL_NBR_CR_BULK on SAE_PORTFOLIO_CR_BULK (BATCH_ID, PORTFOLIO_NBR, BOOKING_CENTER, VALOR)


But if VALOR is null as condition, hibernate will create a sql, it is not we expect

select * from SAE_PORTFOLIO_CR_BULK where BATCH_ID={1}. and BOOKING_CENTER={2} 


So Oracle cannot decide to use "IDX_PTFL_NBR_CR_BULK". In case SAE_PORTFOLIO_CR_BULK is big, the performance will be poor.


In case that, we should add oracle hint

for example

select /*+index(sae_portfolio_cr_bulk,IDX_PTFL_NBR_CR_BULK) index(sae_portfolio_cr_issuer,IDX_PTFL_NBR_CR_ISSUER)*/ sum(cr_eod_exposure_in_usd) from sae_portfolio_cr_bulk where portfolio_nbr in ('286661', '986661') and booking_center='HK'  and batch_id=10000 group by booking_center,valor




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值