如下sql如何造成锁升级哪

我们有一个db2 10.5的数据库,有一个表test.执行sql:delete from test where id>'201412093' and id显示全部
我们有一个db2 10.5的数据库,有一个表test.执行sql:
delete from test where id>'201412093' and id<'201412094' and curdate='20141209';

索引情况:
id 、curdate  (注意是随机顺序索引,非正常的顺序索引)

数据情况:
20141209日之前的数据大概有一亿多条,大于20141209的数据大概3000万条。
20141209日当天的数据大概只剩下不到1000条(其中大部分数据都清理完了)。
为什么这个sql会造成锁升级哪?
ADM5501I  DB2 is performing lock escalation. The affected application is named
"db2bp", and is associated with the workload name "SYSDEFAULTUSERWORKLOAD" and
application ID "192.168.0.34.50418.141211170003"  at member "1". The total number
of locks currently held is "195768", and the target number of locks to hold is
"97884". The current statement being executed is "delete from test
where curdate = '20141209' and id > '1412093' and id <
'1412094'". Reason code: "0"收起
参与4

查看其它 2 个回答ljbupc的回答

ljbupcljbupc软件开发工程师上海安硕科技
你索引顺序肯定是id 、curdate;
你可以建个索引curdate、id 试试,这样首先以curdate判断。。第一步过滤后就是当前的1000多条,锁肯定不多的。
不过不推荐,数据量太大。
推荐你改sql,
delete from test where id like '201412093%'  and curdate='20141209';
大于小于相加判断的逻辑要复杂很多,应该是有两次索引判断,锁资源会占用很多;你可以测试,执行计划的开销和锁肯定都会减少很多。

另推荐可以reorg+runstats一下索引;经常删除的表肯定很多无效节点。
互联网服务 · 2014-12-16
浏览1066

回答者

ljbupc
软件开发工程师上海安硕科技

ljbupc 最近回答过的问题

回答状态

  • 发布时间:2014-12-16
  • 关注会员:1 人
  • 回答浏览:1066
  • X社区推广