外键约束列没建索引导致大量library cache pin/library cache lock

外键约束列没建索引导致大量library cache pin/library cache lock

清空一个100多万行的大表的数据,发现一直执行了几个小时:
delete B001.T_B11;
通过以下SQL进行跟踪,发现经常会出现library cache pin和library cache lock的等待,怀疑有大量的recursive sql在执行,于是对这个session做了10046:
发现有大量的如下SQL执行,每删除1行T_B11,都会执行下面2条SQL一次,
PARSING IN CURSOR #3 len=93 dep=2 uid=0 oct=3 lid=0 tim=1435131097407618 hv=2174374139 ad='b4b86f9e0' sqlid='a16ztda0tnn7v'
 select /*+ all_rows */ count(1) from "B001"."T_BA19" where "BID" = :1
END OF STMT
BINDS #3:
 Bind#0
  oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
  oacflg=12 fl2=0001 frm=00 csi=00 siz=24 off=0
  kxsbbbfp=2b20a2af4d90  bln=22  avl=04  flg=05
  value=232156
EXEC #3:c=0,e=198,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=1,plh=4133059621,tim=1435131097407770
FETCH #3:c=0,e=39,p=0,cr=1,cu=0,mis=0,r=1,dep=2,og=1,plh=4133059621,tim=1435131097407841
CLOSE #3:c=0,e=3,dep=2,type=3,tim=1435131097407880
=====================
PARSING IN CURSOR #3 len=87 dep=2 uid=0 oct=3 lid=0 tim=1435131097410498 hv=2660531033 ad='b49211628' sqlid='1mhux5ug98yut'
 select /*+ all_rows */ count(1) from "B001"."T_BA18" where "BID" = :1
END OF STMT
BINDS #3:
 Bind#0
  oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
  oacflg=12 fl2=0001 frm=00 csi=00 siz=24 off=0
  kxsbbbfp=2b20a2af4d90  bln=22  avl=04  flg=05
  value=232156
EXEC #3:c=0,e=193,p=0,cr=0,cu=0,mis=0,r=0,dep=2,og=1,plh=3617316486,tim=1435131097410645
FETCH #3:c=6000,e=5402,p=0,cr=1342,cu=0,mis=0,r=1,dep=2,og=1,plh=3617316486,tim=1435131097416075
CLOSE #3:c=0,e=2,dep=2,type=3,tim=1435131097416182
T_BA18与T_BA19都是有外键与T_B11相关联的,看到这里,基本上确定T_BA18、T_BA19对应的外键列上没有创建索引导致delete主表缓慢。
因为每删除主表的一行,都会去子表进行验证查询,而子表列上没有创建索引的话,会导致查询缓慢。
并且在此过程会对子表施加S锁,这就是library cache pin的由来。
(oracle对library cache pin的解释中有一句非常经典的话:
An X request (3) will be blocked by anypins held S mode (2) on the object.
An S request (2) will be blocked by any X mode (3) pin held, or may queue behind some other X request.)
对两张子表的BID列添加索引之后,问题解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值