# check for any locking weirdness on INSERT triggers
source include/have_tokudb.inc;
set default_storage_engine='tokudb';
disable_warnings;
drop table if exists t1;
drop table if exists t1_audit;
enable_warnings;

create table t1 (
col1 int not null,
col2 int not null,
primary key (col1));

create table t1_audit (
col1 int not null,
action varchar(32) not null,
ts timestamp not null default now());

insert into t1 (col1,col2) values (0,0);
insert into t1_audit (col1,action) values (0,'DUMMY');
set local tokudb_prelock_empty=0;

create trigger t1_trigger before insert on t1
for each row
insert into t1_audit (col1, action) values (new.col1, 'BEFORE INSERT');
start transaction;
insert into t1 (col1, col2) values (1,1);
select col1,col2 from t1;
select col1,action from t1_audit;
select locks_dname,locks_key_left,locks_key_right from information_schema.tokudb_locks order by locks_dname,locks_key_left,locks_key_right;
# note the locks on t1 and t1_audit
commit;
drop trigger t1_trigger;

create trigger t1_trigger after insert on t1
for each row
insert into t1_audit (col1, action) values (new.col1, 'AFTER INSERT');
start transaction;
insert into t1 (col1, col2) values (2,2);
select col1,col2 from t1;
select col1,action from t1_audit;
select locks_dname,locks_key_left,locks_key_right from information_schema.tokudb_locks order by locks_dname,locks_key_left,locks_key_right;
# note the locks on t1 and t1_audit
commit;
drop trigger t1_trigger;

drop table t1;
drop table t1_audit;
