| 1 |
--echo #Test for Shared, GAP locks |
| 2 |
|
| 3 |
-- connect (con1,localhost,root,,) |
| 4 |
-- connect (con2,localhost,root,,) |
| 5 |
-- connect (con3,localhost,root,,) |
| 6 |
|
| 7 |
--disable_warnings |
| 8 |
drop table if exists t1_s_gap; |
| 9 |
drop table if exists t2_s_gap; |
| 10 |
--enable_warnings |
| 11 |
|
| 12 |
--connection con1 |
| 13 |
use test; |
| 14 |
create table t1_s_gap (col1 int primary key); |
| 15 |
create table t2_s_gap (col1 int primary key, col2 int not null, foreign key(col2) references t1_s_gap(col1)); |
| 16 |
insert into t1_s_gap values (10),(20),(30),(40); |
| 17 |
|
| 18 |
--connection con2 |
| 19 |
start transaction; |
| 20 |
--ERROR 1452 |
| 21 |
insert into t2_s_gap values (1, 25); |
| 22 |
|
| 23 |
--connection con3 |
| 24 |
use performance_schema; |
| 25 |
|
| 26 |
select object_schema, object_name, lock_type, lock_mode, lock_status, lock_data |
| 27 |
from data_locks |
| 28 |
where object_name in ('t1_s_gap', 't2_s_gap') |
| 29 |
and (lock_type = 'TABLE') |
| 30 |
order by object_name, lock_type, lock_mode, lock_status, lock_data; |
| 31 |
|
| 32 |
# |
| 33 |
# For RECORD data locks, innodb returns: |
| 34 |
# - The LOCK_DATA for the record if it is still present in the buffer pool |
| 35 |
# This is the most frequent output for this test case. |
| 36 |
# - Or NULL if the record has been expelled from the buffer pool already. |
| 37 |
# This can happen, and causes spurious test failures. |
| 38 |
# |
| 39 |
# This is by design of innodb, the code is not reading back a page |
| 40 |
# from disk just to give the LOCK_DATA information, |
| 41 |
# when the record is otherwise not needed. |
| 42 |
# |
| 43 |
# So, to avoid spurious failures, we print '30-or-null' for both cases. |
| 44 |
# |
| 45 |
select object_schema, object_name, lock_type, lock_mode, lock_status, |
| 46 |
if(lock_data is null, '30-or-null', |
| 47 |
if (lock_data = '30', '30-or-null', lock_data)) |
| 48 |
as lock_data |
| 49 |
from data_locks |
| 50 |
where object_name in ('t1_s_gap', 't2_s_gap') |
| 51 |
and (lock_type != 'TABLE') |
| 52 |
order by object_name, lock_type, lock_mode, lock_status, lock_data; |
| 53 |
|
| 54 |
--connection con1 |
| 55 |
start transaction; |
| 56 |
--send |
| 57 |
insert into t1_s_gap values (25); |
| 58 |
|
| 59 |
-- connection default |
| 60 |
let $wait_condition= SELECT COUNT(*)>=1 FROM performance_schema.data_locks |
| 61 |
where OBJECT_NAME='t1_s_gap' and LOCK_STATUS='WAITING'; |
| 62 |
--source include/wait_condition.inc |
| 63 |
|
| 64 |
--connection con3 |
| 65 |
use performance_schema; |
| 66 |
|
| 67 |
select object_schema, object_name, lock_type, lock_mode, lock_status, lock_data |
| 68 |
from data_locks |
| 69 |
where object_name in ('t1_s_gap', 't2_s_gap') |
| 70 |
and (lock_type = 'TABLE') |
| 71 |
order by object_name, lock_type, lock_mode, lock_status, lock_data; |
| 72 |
|
| 73 |
select object_schema, object_name, lock_type, lock_mode, lock_status, |
| 74 |
if(lock_data is null, '30-or-null', |
| 75 |
if (lock_data = '30', '30-or-null', lock_data)) |
| 76 |
as lock_data |
| 77 |
from data_locks |
| 78 |
where object_name in ('t1_s_gap', 't2_s_gap') |
| 79 |
and (lock_type != 'TABLE') |
| 80 |
order by object_name, lock_type, lock_mode, lock_status, lock_data; |
| 81 |
|
| 82 |
--connection con2 |
| 83 |
commit; |
| 84 |
|
| 85 |
--connection con1 |
| 86 |
--reap |
| 87 |
commit; |
| 88 |
drop table t2_s_gap; |
| 89 |
drop table t1_s_gap; |
| 90 |
|
| 91 |
--disconnect con1 |
| 92 |
--disconnect con2 |
| 93 |
--disconnect con3 |