rlliso3multi.sql
来自「derby database source code.good for you.」· SQL 代码 · 共 496 行 · 第 1/2 页
SQL
496 行
---------------------------------------------------------------------------------- Test multi user lock interaction under isolation level 3. default isolation-- level has been set as a property to serializable.------------------------------------------------------------------------------------------------------------------------------------------------------------------ Test 0: verify isolation level by seeing if a read lock is released or not.--------------------------------------------------------------------------------connect 'wombat' as scanner;set isolation to rr;-- by default, holdability of ResultSet objects created using this Connection object is true. Following will set it to false for this connection.NoHoldForConnection;connect 'wombat' as writer;set isolation to rr;-- by default, holdability of ResultSet objects created using this Connection object is true. Following will set it to false for this connection.NoHoldForConnection;run resource 'createTestProcedures.subsql';call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.storage.pageSize', '4096');-- set upset connection scanner;autocommit off;create table test_0 (a int);insert into test_0 values (1);commit;set connection writer;autocommit off;-- scanner should hold read lock on table until end of transaction.set connection scanner;select * from test_0;-- writer should get a lock timeout.set connection writer;insert into test_0 values (2);-- scanner should only see the original row.set connection scanner;select * from test_0;commit;select * from test_0;-- cleanupset connection scanner;drop table test_0;commit;disconnect;set connection writer;disconnect;---------------------------------------------------------------------------------- Test 1: make sure a leaf root growing get's the right lock.------------------------------------------------------------------------------------------------------------------------------------------------------------------ Test setup - create a 1 page btre, with the page ready to split.--------------------------------------------------------------------------------connect 'wombat' as scanner;set isolation to rr;-- by default, holdability of ResultSet objects created using this Connection object is true. Following will set it to false for this connection.NoHoldForConnection;connect 'wombat' as rootgrower;set isolation to rr;-- by default, holdability of ResultSet objects created using this Connection object is true. Following will set it to false for this connection.NoHoldForConnection;set connection scanner;autocommit off;create table a (a varchar(1000), b varchar(1000)) ;insert into a values (PADSTRING('a',1000), PADSTRING('a',1000));insert into a values (PADSTRING('b',1000), PADSTRING('b',1000));insert into a values (PADSTRING('c',1000), PADSTRING('c',1000));create index a_idx on a (a) ;;commit;set connection rootgrower;autocommit off;commit;---------------------------------------------------------------------------------- Set up scanner to be doing a row locked covered scan on the index.--------------------------------------------------------------------------------set connection scanner;autocommit off;CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.language.bulkFetchDefault','1');get cursor scan_cursor as 'select a from a where a >= PADSTRING(''a'',1000) and a < PADSTRING(''c'',1000) ';call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.language.bulkFetchDefault', '16');next scan_cursor;---------------------------------------------------------------------------------- This should block on the scan lock held by the scanner on the first page.--------------------------------------------------------------------------------set connection rootgrower;autocommit off;insert into a values (PADSTRING('d',1000), PADSTRING('d',1000));---------------------------------------------------------------------------------- The scan should continue unaffected.--------------------------------------------------------------------------------set connection scanner;next scan_cursor;next scan_cursor;---------------------------------------------------------------------------------- This insert will block on the previous key lock of the scanner.--------------------------------------------------------------------------------set connection rootgrower;insert into a values (PADSTRING('ab',1000), PADSTRING('ab',1000));---------------------------------------------------------------------------------- Now the grow root should be allowed (note that cursor scan has locks-- on the leaf page being grown - just not the scan lock).--------------------------------------------------------------------------------set connection rootgrower;insert into a values (PADSTRING('d',1000), PADSTRING('d',1000));select a from a;---------------------------------------------------------------------------------- cleanup.--------------------------------------------------------------------------------set connection rootgrower;commit;disconnect;set connection scanner;commit;drop table a;commit;disconnect;---------------------------------------------------------------------------------- Test 2: make sure previous key locks are gotten correctly.--------------------------------------------------------------------------------connect 'wombat' as client_1;set isolation to rr;-- by default, holdability of ResultSet objects created using this Connection object is true. Following will set it to false for this connection.NoHoldForConnection;connect 'wombat' as client_2;set isolation to rr;-- by default, holdability of ResultSet objects created using this Connection object is true. Following will set it to false for this connection.NoHoldForConnection;set connection client_1;autocommit off;create table a (a varchar(1000), b varchar(1000)) ;create index a_idx on a (a) ;commit;insert into a values (PADSTRING('b',1000), PADSTRING('b',1000));set connection client_2;autocommit off;---------------------------------------------------------------------------------- the following will not cause a time out, as the previous-- key insert lock will not conflict with other insert locks, only other-- select locks, or non insert update locks.--------------------------------------------------------------------------------insert into a values (PADSTRING('c',1000), PADSTRING('c',1000));---------------------------------------------------------------------------------- the following should NOT cause a time out--------------------------------------------------------------------------------insert into a values (PADSTRING('a',1000), PADSTRING('a',1000));---------------------------------------------------------------------------------- cleanup.--------------------------------------------------------------------------------set connection client_1;commit;set connection client_2;commit;drop table a;commit;---------------------------------------------------------------------------------- Test 3: make sure an exact key insert into unique key index blocks.--------------------------------------------------------------------------------set connection client_1;autocommit off;create table a (a varchar(1000), b varchar(1000));create unique index a_idx on a (a) ;commit;insert into a values (PADSTRING('b',1000), PADSTRING('b',1000));set connection client_2;autocommit off;---------------------------------------------------------------------------------- the following should cause a time out, as the previous-- key lock will conflict with client_1's lock on 'b'--------------------------------------------------------------------------------insert into a values (PADSTRING('b',1000), PADSTRING('b',1000));---------------------------------------------------------------------------------- Test 4: make sure that row lock wait in a heap scan works--------------------------------------------------------------------------------set connection client_1;autocommit off;create table test_4 (a int, b varchar(1000), c varchar(1000)) ;commit;set connection client_2;autocommit off;commit;-- client_1 will get a single row lock in the heap.set connection client_1;insert into test_4 values (1, PADSTRING('a',1000), PADSTRING('b',1000)); -- client_2 scans table, blocking on a row lock on the client_1 insert row, -- will get timout message.set connection client_2;select * from test_4;-- release the insert lock.set connection client_1;commit;-- reader should be able to see row now.set connection client_2;select * from test_4;commit;-- cleanupset connection client_1;drop table test_4;commit;---------------------------------------------------------------------------------- Test 5: make sure a that a group fetch through a secondary index correctly-- handles the previous to first key locking. In serializable the-- scanner should hold the previous to first key lock until end of -- transaction, thus blocking the attempted insert to the range.--------------------------------------------------------------------------------connect 'wombat' as scanner;set isolation to rr;-- by default, holdability of ResultSet objects created using this Connection object is true. Following will set it to false for this connection.NoHoldForConnection;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?