Select/Update 引起的read by other session

Select/Update 引起的buffer lock争用于Select/Select 或Update/Update 引起的buffer lock 争用机制有很大差异。


Oracle 的Select 操作i奔上一致性读取(cr)为基础,若实际应该读取的数据已修改,则必须读取持有过去映像的CR块。这时若CR块不在当前的高速缓冲区上时,

则应该从磁盘读取撤销块。若多个会话试图读取撤销块时,在将撤销块载入到内存上的过程中发生buffer lock争用。因此Select/Update引起的buffer lock

争用会在如下情况发生:

*特定进程修改特定表,数据的过去映像记录在撤销块。

*很多进程试图同时(或之后)读取已修改的数据。

让我们通过测试对此进行确认,测试方案如下:


1)创建拥有5W行的BFW_TEST表

2)一个进程上对BFW_TEST表执行Update,以此创建撤销块。

3)多个进程同时对已修改的数据执行读取(select)操作

4)在此过程中发生buffer lock争用。


【测试6】Select/Update 引起的buffer lock争用

--执行select 的procedure
create or replace procedure  bfw_do_select
is 
begin
 for x in (select t1.id as ID1,t2.id as ID2 from bfw_test t1,bfw_test t2 where rownum<=500000) loop
 null;
 end loop;
 end;

---对相同的表执行Update的Procedure
create or replace procedure bfw_do_update
is 
begin
           update bfw_test set id='';
           end;


---在执行Update期间,多个会话同时执行Select操作。

var job_no number;
begin
    dbms_job.submit(:job_no,'bfw_do_update;');
    commit;
    for idx in 1 .. 10 loop
      dbms_job.submit(:job_no,'bfw_do_select;');
      end loop;
      commit;
      end;



1	24-6月 -14 11.24.32.652 上午	6	db file sequential read	3	16295	1	0	0	3	16295
2	24-6月 -14 11.24.32.652 上午	11	db file sequential read	3	759361	1	0	0	3	759361
3	24-6月 -14 11.24.32.652 上午	13	read by other session	3	16295	22	0	0	3	16295
4	24-6月 -14 11.24.32.652 上午	15	read by other session	3	16295	22	0	0	3	16295
9	24-6月 -14 11.24.32.652 上午	1147	read by other session	3	16295	22	0	0	3	16295
10	24-6月 -14 11.24.32.652 上午	1149	read by other session	3	16295	22	0	0	3	16295
11	24-6月 -14 11.24.32.652 上午	1151	read by other session	3	16295	22	0	0	3	16295
12	24-6月 -14 11.24.32.652 上午	1713	read by other session	3	16295	22	0	0	3	16295
14	24-6月 -14 11.24.32.652 上午	1718	read by other session	3	16295	22	0	0	3	16295
15	24-6月 -14 11.24.32.652 上午	1720	read by other session	3	16295	22	0	0	3	16295
16	24-6月 -14 11.24.31.642 上午	6	read by other session	3	16705	22	0	0	3	16705

查看访问的对象:
SQL>  select owner,segment_name,segment_type from dba_extents
 where file_id=3 and 16295 between block_id and block_id + blocks-1;  2  

OWNER	   SEGMENT_NAME 								     SEGMENT_TYPE
---------- --------------------------------------------------------------------------------- ------------------
SYS	   _SYSSMU3_4004931649$ 							     TYPE2 UNDO



原文地址:https://www.cnblogs.com/hzcya1995/p/13352249.html