在DB2 V9.7版本之前或者DB2 V9.7版本未启用CC特性,那么如果查询扫描到正在被插入或者修改的记录,
那么查询将会挂起,直到修改记录的会话提交或者回滚。
[huateng@db2server ~]$ db2 connect to dbtest
Database Connection Information
Database server = DB2/LINUX 9.7.0
SQL authorization ID = HUATENG
Local database alias = DBTEST
[huateng@db2server ~]$ db2 get db cfg | grep CUR_COMMIT
Currently Committed (CUR_COMMIT) = DISABLED
当前的数据库版本是9.7 ,未开启 Currently Committed 特性。
会话1进行了如下的修改,没有提交:
db2 => select * from t
ID
-----------
1
2
3
4
5
6
7
8
8 record(s) selected.
db2 => update t set id=9 where id=8
DB20000I The SQL command completed successfully.
db2 =>
此时会话2进行如下查询将会导致挂起:
db2 => select * from t where id=1
直到会话1进行了提交。
如果T表的ID上有索引,那么结果就会不同:
会话1:
db2 => select * from t
ID
-----------
1
2
3
4
5
6
7
8
8 record(s) selected.
db2 => create index idx_t_01 on t(id)
DB20000I The SQL command completed successfully.
db2 => commit
DB20000I The SQL command completed successfully.
db2 => update t set id=9 where id=8
DB20000I The SQL command completed successfully.
db2 =>
会话2此时进行如下查询将会在瞬间完成
db2 => select * from t where id=1
ID
-----------
1
1 record(s) selected.
这是此时查询将会通过索引而定位到id=1的记录,无需扫描到ID=8的记录,因此不会阻塞。
阅读(1617) | 评论(0) | 转发(0) |