summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2017-03-05 14:32:30 +0200
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2017-03-05 15:18:26 +0200
commit97041acf7f6dd17636fea9edfe25a6105d893db6 (patch)
tree7efb6b7068187e4ccc19c5d9e36b18e55cdf86b2
parent4c3b732d9f011122407f39550e9030e142d1b8d2 (diff)
downloadmariadb-git-97041acf7f6dd17636fea9edfe25a6105d893db6.tar.gz
Fix tokudb.gap_lock_error test
TokuDB testsuite makes use of includes not found in our default 10.0. Cherry pick them from Percona Server's include directory.
-rw-r--r--mysql-test/include/gap_lock_error_all.inc27
-rw-r--r--mysql-test/include/gap_lock_error_cleanup.inc1
-rw-r--r--mysql-test/include/gap_lock_error_init.inc24
-rw-r--r--mysql-test/include/gap_lock_error_select.inc89
-rw-r--r--mysql-test/include/gap_lock_error_update.inc91
-rw-r--r--storage/tokudb/mysql-test/tokudb/r/gap_lock_error.result12
6 files changed, 238 insertions, 6 deletions
diff --git a/mysql-test/include/gap_lock_error_all.inc b/mysql-test/include/gap_lock_error_all.inc
new file mode 100644
index 00000000000..fc69dfb56f0
--- /dev/null
+++ b/mysql-test/include/gap_lock_error_all.inc
@@ -0,0 +1,27 @@
+--source include/have_partition.inc
+--source include/gap_lock_error_init.inc
+
+let $select_lock=for update;
+let $autocommit = 0;
+--source include/gap_lock_error_select.inc
+let $autocommit = 1;
+--source include/gap_lock_error_select.inc
+
+let $select_lock=lock in share mode;
+let $autocommit = 0;
+--source include/gap_lock_error_select.inc
+let $autocommit = 1;
+--source include/gap_lock_error_select.inc
+
+let $select_lock=;
+let $autocommit = 0;
+--source include/gap_lock_error_select.inc
+let $autocommit = 1;
+--source include/gap_lock_error_select.inc
+
+let $autocommit = 0;
+--source include/gap_lock_error_update.inc
+let $autocommit = 1;
+--source include/gap_lock_error_update.inc
+
+--source include/gap_lock_error_cleanup.inc
diff --git a/mysql-test/include/gap_lock_error_cleanup.inc b/mysql-test/include/gap_lock_error_cleanup.inc
new file mode 100644
index 00000000000..8558b5a528f
--- /dev/null
+++ b/mysql-test/include/gap_lock_error_cleanup.inc
@@ -0,0 +1 @@
+drop table gap1, gap2, gap3, gap4;
diff --git a/mysql-test/include/gap_lock_error_init.inc b/mysql-test/include/gap_lock_error_init.inc
new file mode 100644
index 00000000000..26aa852a398
--- /dev/null
+++ b/mysql-test/include/gap_lock_error_init.inc
@@ -0,0 +1,24 @@
+eval CREATE TABLE gap1 (id1 INT, id2 INT, id3 INT, c1 INT, value INT,
+ PRIMARY KEY (id1, id2, id3),
+ INDEX i (c1)) ENGINE=$engine;
+CREATE TABLE gap2 like gap1;
+eval CREATE TABLE gap3 (id INT, value INT,
+ PRIMARY KEY (id),
+ UNIQUE KEY ui(value)) ENGINE=$engine;
+eval CREATE TABLE gap4 (id INT, value INT,
+ PRIMARY KEY (id)) ENGINE=$engine
+ PARTITION BY HASH(id) PARTITIONS 2;
+--disable_query_log
+let $max = 1000;
+let $i = 1;
+while ($i <= $max) {
+ eval INSERT INTO gap1 (id1, id2, id3, c1, value)
+ VALUES ($i div 2, $i div 10, $i, $i, $i);
+ eval INSERT INTO gap2 (id1, id2, id3, c1, value)
+ VALUES ($i div 2, $i div 10, $i, $i, $i);
+ inc $i;
+}
+--enable_query_log
+
+insert into gap3 values (1,1), (2,2),(3,3),(4,4),(5,5);
+insert into gap4 values (1,1), (2,2),(3,3),(4,4),(5,5);
diff --git a/mysql-test/include/gap_lock_error_select.inc b/mysql-test/include/gap_lock_error_select.inc
new file mode 100644
index 00000000000..91db9bed68a
--- /dev/null
+++ b/mysql-test/include/gap_lock_error_select.inc
@@ -0,0 +1,89 @@
+eval set session autocommit=$autocommit;
+let $is_gaplock_target = `SELECT @@autocommit = 0 && '$select_lock' != '' && '$expect_gap_lock_errors' = 1`;
+
+if ($is_gaplock_target)
+{
+# rnd_init
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 limit 1 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 where value != 100 limit 1 $select_lock;
+# index_read_map
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 where id1=1 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 where id1=1 and id2= 1 $select_lock;
+# read_range_first
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 where id1=1 and id2= 1 and id3 != 1 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 where id1=1 and id2= 1 and id3
+ between 1 and 3 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 where id1=1 and id2= 1 order by id3 asc
+ limit 1 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 where id1=1 and id2= 1 order by id3 desc
+ limit 1 $select_lock;
+# index_first
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 order by id1 asc limit 1 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 $select_lock;
+# index_last
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 order by id1 desc limit 1 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 order by id1 desc, id2 desc, id3 desc
+ limit 1 $select_lock;
+# secondary index lookup
+--error ER_UNKNOWN_ERROR
+eval select * from gap1 force index(i) where c1=1 $select_lock;
+# unique index lookup, ensure no gap lock errors as this is effectively a
+# single point select that does not lock ranges or gaps of keys
+eval select * from gap3 force index(ui) where value=1 $select_lock;
+# primary key lookup, ensure no gap lock errors as these are effectively
+# single point selects that do not lock ranges or gaps of keys
+eval select * from gap1 where id1=1 and id2=1 and id3=1 $select_lock;
+eval select * from gap1 where id1=1 and id2=1 and id3 in (1, 2, 3) $select_lock;
+eval select * from gap1 where id1=1 and id2=1 and id3=1 and value=1
+ order by c1 $select_lock;
+eval select * from gap3 where id=1 $select_lock;
+eval select * from gap4 where id=1 $select_lock;
+eval select * from gap4 where id in (1, 2, 3) $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap4 $select_lock;
+--error ER_UNKNOWN_ERROR
+eval select * from gap4 where id between 3 and 7 $select_lock;
+}
+
+if (!$is_gaplock_target)
+{
+eval select * from gap1 limit 1 $select_lock;
+eval select * from gap1 where value != 100 limit 1 $select_lock;
+eval select * from gap1 where id1=1 $select_lock;
+eval select * from gap1 where id1=1 and id2= 1 $select_lock;
+eval select * from gap1 where id1=1 and id2= 1 and id3 != 1 $select_lock;
+eval select * from gap1 where id1=1 and id2= 1 and id3
+ between 1 and 3 $select_lock;
+eval select * from gap1 where id1=1 and id2= 1 order by id3 asc
+ limit 1 $select_lock;
+eval select * from gap1 where id1=1 and id2= 1 order by id3 desc
+ limit 1 $select_lock;
+eval select * from gap1 order by id1 asc limit 1 $select_lock;
+eval select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 $select_lock;
+eval select * from gap1 order by id1 desc limit 1 $select_lock;
+eval select * from gap1 order by id1 desc, id2 desc, id3 desc
+ limit 1 $select_lock;
+eval select * from gap1 force index(i) where c1=1 $select_lock;
+eval select * from gap3 force index(ui) where value=1 $select_lock;
+eval select * from gap1 where id1=1 and id2=1 and id3=1 $select_lock;
+eval select * from gap1 where id1=1 and id2=1 and id3 in (1, 2, 3) $select_lock;
+eval select * from gap1 where id1=1 and id2=1 and id3=1 and value=1
+ order by c1 $select_lock;
+eval select * from gap3 where id=1 $select_lock;
+eval select * from gap4 where id=1 $select_lock;
+eval select * from gap4 where id in (1, 2, 3) $select_lock;
+eval select * from gap4 $select_lock;
+eval select * from gap4 where id between 3 and 7 $select_lock;
+}
diff --git a/mysql-test/include/gap_lock_error_update.inc b/mysql-test/include/gap_lock_error_update.inc
new file mode 100644
index 00000000000..d456cf81588
--- /dev/null
+++ b/mysql-test/include/gap_lock_error_update.inc
@@ -0,0 +1,91 @@
+eval set session autocommit=$autocommit;
+let $is_gaplock_target = `SELECT @@autocommit = 0 && '$expect_gap_lock_errors' = 1`;
+
+if ($is_gaplock_target)
+{
+## single-table insert,update,delete
+insert into gap1 (id1, id2, id3) values (-1,-1,-1);
+insert into gap1 (id1, id2, id3) values (-1,-1,-1)
+ on duplicate key update value=100;
+--error ER_UNKNOWN_ERROR
+update gap1 set value=100 where id1=1;
+update gap1 set value=100 where id1=1 and id2=1 and id3=1;
+--error ER_UNKNOWN_ERROR
+delete from gap1 where id1=2;
+delete from gap1 where id1=-1 and id2=-1 and id3=-1;
+commit;
+
+## multi-table statements (preventing all gap locks with autocommit)
+# insert into select
+--error ER_UNKNOWN_ERROR
+insert into gap2 select * from gap1;
+--error ER_UNKNOWN_ERROR
+insert into gap2 select * from gap1 where id1=1;
+insert into gap2 select * from gap1 where id1=1 and id2=1 and id3=1;
+
+# create table select
+create table t4 select * from gap1 where id1=1 and id2=1 and id3=1;
+drop table t4;
+--error ER_UNKNOWN_ERROR
+create table t4 select * from gap1;
+--error ER_UNKNOWN_ERROR
+create table t4 select * from gap1 where id1=1;
+
+# update join
+update gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 set gap1.value=100 where gap2.id1=3
+ and gap2.id2=3 and gap2.id3=3;
+--error ER_UNKNOWN_ERROR
+update gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 set gap1.value=100 where gap2.id1=3;
+--error ER_UNKNOWN_ERROR
+update gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 join gap3 on gap1.id1=gap3.id
+ set gap1.value=100 where gap2.id1=3;
+--error ER_UNKNOWN_ERROR
+update gap1 set gap1.value= (select count(*) from gap2);
+
+# delete join
+delete gap1 from gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 where gap2.id1=3
+ and gap2.id2=3 and gap2.id3=3;
+--error ER_UNKNOWN_ERROR
+delete gap1 from gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 where gap2.id1=3;
+
+# select join / self join
+--error ER_UNKNOWN_ERROR
+select * from gap1, gap2 limit 1 for update;
+--error ER_UNKNOWN_ERROR
+select * from gap1 a, gap1 b limit 1 for update;
+
+# unique secondary key
+create table u1(
+ c1 int,
+ c2 int,
+ c3 int,
+ c4 int,
+ primary key (c1, c2, c3),
+ unique key (c3, c1)
+);
+begin;
+insert into u1 values (1,1,1,1);
+commit;
+begin;
+insert into u1 values (1,2,1,1) on duplicate key update c4=10;
+commit;
+begin;
+select * from u1 where c3=1 and c1 = 1 for update;
+--error ER_UNKNOWN_ERROR
+select * from u1 where c3=1 for update;
+commit;
+drop table u1;
+}
+
+if (!$is_gaplock_target)
+{
+# autocommit doesn't prevent single table operations
+insert into gap1 (id1, id2, id3) values (-1,-1,-1);
+insert into gap1 (id1, id2, id3) values (-1,-1,-1)
+ on duplicate key update value=100;
+update gap1 set value=100 where id1=1;
+update gap1 set value=100 where id1=1 and id2=1 and id3=1;
+delete from gap1 where id1=2;
+delete from gap1 where id1=-1 and id2=-1 and id3=-1;
+commit;
+}
diff --git a/storage/tokudb/mysql-test/tokudb/r/gap_lock_error.result b/storage/tokudb/mysql-test/tokudb/r/gap_lock_error.result
index 2994280303f..41e294f7d8d 100644
--- a/storage/tokudb/mysql-test/tokudb/r/gap_lock_error.result
+++ b/storage/tokudb/mysql-test/tokudb/r/gap_lock_error.result
@@ -80,8 +80,8 @@ id value
5 5
select * from gap4 where id between 3 and 7 for update;
id value
-4 4
3 3
+4 4
5 5
set session autocommit=1;
select * from gap1 limit 1 for update;
@@ -153,8 +153,8 @@ id value
5 5
select * from gap4 where id between 3 and 7 for update;
id value
-4 4
3 3
+4 4
5 5
set session autocommit=0;
select * from gap1 limit 1 lock in share mode;
@@ -226,8 +226,8 @@ id value
5 5
select * from gap4 where id between 3 and 7 lock in share mode;
id value
-4 4
3 3
+4 4
5 5
set session autocommit=1;
select * from gap1 limit 1 lock in share mode;
@@ -299,8 +299,8 @@ id value
5 5
select * from gap4 where id between 3 and 7 lock in share mode;
id value
-4 4
3 3
+4 4
5 5
set session autocommit=0;
select * from gap1 limit 1 ;
@@ -372,8 +372,8 @@ id value
5 5
select * from gap4 where id between 3 and 7 ;
id value
-4 4
3 3
+4 4
5 5
set session autocommit=1;
select * from gap1 limit 1 ;
@@ -445,8 +445,8 @@ id value
5 5
select * from gap4 where id between 3 and 7 ;
id value
-4 4
3 3
+4 4
5 5
set session autocommit=0;
insert into gap1 (id1, id2, id3) values (-1,-1,-1);