diff --git a/mysql-test/include/gap_lock_error_all.inc b/mysql-test/include/gap_lock_error_all.inc index f93b37501914..9440d717c3bf 100644 --- a/mysql-test/include/gap_lock_error_all.inc +++ b/mysql-test/include/gap_lock_error_all.inc @@ -1,3 +1,4 @@ +--let $warning_or_error= ERROR --source include/gap_lock_error_init.inc let $select_lock=for update; @@ -18,9 +19,5 @@ let $autocommit = 0; 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 index a3f6c04fa800..ce32faf1735e 100644 --- a/mysql-test/include/gap_lock_error_cleanup.inc +++ b/mysql-test/include/gap_lock_error_cleanup.inc @@ -1,4 +1,6 @@ -drop table gap1, gap2, gap3; +set global gap_lock_raise_error= off; + +drop table gap1, gap2, gap3, gap5, gap6; if (!$gap_lock_error_skip_partitioning) { drop table gap4; } diff --git a/mysql-test/include/gap_lock_error_init.inc b/mysql-test/include/gap_lock_error_init.inc index 9d732431b9e2..d9897c3fe7f4 100644 --- a/mysql-test/include/gap_lock_error_init.inc +++ b/mysql-test/include/gap_lock_error_init.inc @@ -1,3 +1,18 @@ +# ==== Usage ==== +# +# [--let $warning_or_error= WARNING | ERROR ] +# --source include/assert_no_warnings.inc +# +# Parameters: +# +# $warning_or_error +# Whether we are expected to raise warning or error. +# + +--disable_warnings +drop table if exists gap1,gap2,gap3; +--enable_warnings + eval CREATE TABLE gap1 (id1 INT, id2 INT, id3 INT, c1 INT, value INT, PRIMARY KEY (id1, id2, id3), INDEX i (c1)) ENGINE=$engine; @@ -23,6 +38,19 @@ while ($i <= $max) { --enable_query_log insert into gap3 values (1,1), (2,2),(3,3),(4,4),(5,5); + if (!$gap_lock_error_skip_partitioning) { insert into gap4 values (1,1), (2,2),(3,3),(4,4),(5,5); } + +eval CREATE TABLE gap5 ( + pk int primary key, + a int, + b int, + key(a) +) ENGINE=$engine; +insert into gap5 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +create table gap6 like gap5; +insert into gap6 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); + +eval set session gap_lock_raise_error= $warning_or_error; diff --git a/mysql-test/include/gap_lock_error_select.inc b/mysql-test/include/gap_lock_error_select.inc index 91db9bed68a0..37204229554f 100644 --- a/mysql-test/include/gap_lock_error_select.inc +++ b/mysql-test/include/gap_lock_error_select.inc @@ -1,5 +1,5 @@ eval set session autocommit=$autocommit; -let $is_gaplock_target = `SELECT @@autocommit = 0 && '$select_lock' != '' && '$expect_gap_lock_errors' = 1`; +let $is_gaplock_target = `SELECT @@autocommit = 0 && '$select_lock' != ''`; if ($is_gaplock_target) { @@ -49,12 +49,6 @@ 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) @@ -82,8 +76,4 @@ 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 index ba04eb531b56..69778f924f0d 100644 --- a/mysql-test/include/gap_lock_error_update.inc +++ b/mysql-test/include/gap_lock_error_update.inc @@ -63,6 +63,7 @@ eval create table u1( primary key (c1, c2, c3), unique key (c3, c1) ) engine=$engine; +set session gap_lock_raise_error=error; begin; insert into u1 values (1,1,1,1); commit; diff --git a/mysql-test/r/all_persisted_variables.result b/mysql-test/r/all_persisted_variables.result index 6315f91f70cd..20799e67e2b5 100644 --- a/mysql-test/r/all_persisted_variables.result +++ b/mysql-test/r/all_persisted_variables.result @@ -47,7 +47,7 @@ include/assert.inc [Expect 500+ variables in the table. Due to open Bugs, we are # Test SET PERSIST -include/assert.inc [Expect 489 persisted variables in the table.] +include/assert.inc [Expect 490 persisted variables in the table.] ************************************************************ * 3. Restart server, it must preserve the persisted variable @@ -55,9 +55,9 @@ include/assert.inc [Expect 489 persisted variables in the table.] ************************************************************ # restart -include/assert.inc [Expect 489 persisted variables in persisted_variables table.] -include/assert.inc [Expect 489 persisted variables shown as PERSISTED in variables_info table.] -include/assert.inc [Expect 489 persisted variables with matching peristed and global values.] +include/assert.inc [Expect 490 persisted variables in persisted_variables table.] +include/assert.inc [Expect 490 persisted variables shown as PERSISTED in variables_info table.] +include/assert.inc [Expect 490 persisted variables with matching peristed and global values.] ************************************************************ * 4. Test RESET PERSIST IF EXISTS. Verify persisted variable diff --git a/mysql-test/r/mysqld--help-notwin.result b/mysql-test/r/mysqld--help-notwin.result index 07f04eb0c237..0201d0a9662b 100644 --- a/mysql-test/r/mysqld--help-notwin.result +++ b/mysql-test/r/mysqld--help-notwin.result @@ -423,6 +423,11 @@ The following options may be given as the first argument: word symbols for full text search queries --ft-stopword-file=name Use stopwords from this file instead of built-in list + --gap-lock-raise-error[=name] + Controls raising a warning or an error when executing + queries that rely on Gap Lock. It can take the following + values: OFF: no error is raised WARNING: a warning is + raised ERROR: an error is raised. Default is OFF --gdb Set up signals usable for debugging. --general-log Log connections and queries to a table or log file. Defaults to logging to a file hostname.log, or if @@ -1847,6 +1852,7 @@ ft-min-word-len 4 ft-query-expansion-limit 20 ft-query-extra-word-chars FALSE ft-stopword-file (No default value) +gap-lock-raise-error OFF gdb FALSE general-log FALSE generated-random-password-length 20 diff --git a/mysql-test/suite/percona/r/gap_lock_error_memory.result b/mysql-test/suite/percona/r/gap_lock_error_memory.result index 4d12260703b4..12cd6d732d23 100644 --- a/mysql-test/suite/percona/r/gap_lock_error_memory.result +++ b/mysql-test/suite/percona/r/gap_lock_error_memory.result @@ -1,3 +1,4 @@ +drop table if exists gap1,gap2,gap3; CREATE TABLE gap1 (id1 INT, id2 INT, id3 INT, c1 INT, value INT, PRIMARY KEY (id1, id2, id3), INDEX i (c1)) ENGINE=memory; @@ -6,6 +7,16 @@ CREATE TABLE gap3 (id INT, value INT, PRIMARY KEY (id), UNIQUE KEY ui(value)) ENGINE=memory; insert into gap3 values (1,1), (2,2),(3,3),(4,4),(5,5); +CREATE TABLE gap5 ( +pk int primary key, +a int, +b int, +key(a) +) ENGINE=memory; +insert into gap5 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +create table gap6 like gap5; +insert into gap6 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +set session gap_lock_raise_error= WARNING; select sum(value) from gap1; sum(value) 500500 @@ -13,4 +24,5 @@ update gap1 set gap1.value= (select count(*) from gap2); select sum(value) from gap1; sum(value) 1000000 -drop table gap1, gap2, gap3; +set global gap_lock_raise_error= off; +drop table gap1, gap2, gap3, gap5, gap6; diff --git a/mysql-test/suite/percona/r/gap_lock_error_myisam.result b/mysql-test/suite/percona/r/gap_lock_error_myisam.result index 1090e24b8f28..16fa0054a76c 100644 --- a/mysql-test/suite/percona/r/gap_lock_error_myisam.result +++ b/mysql-test/suite/percona/r/gap_lock_error_myisam.result @@ -1,3 +1,4 @@ +drop table if exists gap1,gap2,gap3; CREATE TABLE gap1 (id1 INT, id2 INT, id3 INT, c1 INT, value INT, PRIMARY KEY (id1, id2, id3), INDEX i (c1)) ENGINE=myisam; @@ -6,6 +7,16 @@ CREATE TABLE gap3 (id INT, value INT, PRIMARY KEY (id), UNIQUE KEY ui(value)) ENGINE=myisam; insert into gap3 values (1,1), (2,2),(3,3),(4,4),(5,5); +CREATE TABLE gap5 ( +pk int primary key, +a int, +b int, +key(a) +) ENGINE=myisam; +insert into gap5 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +create table gap6 like gap5; +insert into gap6 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +set session gap_lock_raise_error= WARNING; select sum(value) from gap1; sum(value) 500500 @@ -13,4 +24,5 @@ update gap1 set gap1.value= (select count(*) from gap2); select sum(value) from gap1; sum(value) 1000000 -drop table gap1, gap2, gap3; +set global gap_lock_raise_error= off; +drop table gap1, gap2, gap3, gap5, gap6; diff --git a/mysql-test/suite/percona/t/gap_lock_error_memory.test b/mysql-test/suite/percona/t/gap_lock_error_memory.test index 8c041d83b6f9..b097c1b953c7 100644 --- a/mysql-test/suite/percona/t/gap_lock_error_memory.test +++ b/mysql-test/suite/percona/t/gap_lock_error_memory.test @@ -3,6 +3,7 @@ let $engine=memory; let $expect_gap_lock_errors=0; let $gap_lock_error_skip_partitioning=1; +--let $warning_or_error=WARNING --source include/gap_lock_error_init.inc select sum(value) from gap1; update gap1 set gap1.value= (select count(*) from gap2); diff --git a/mysql-test/suite/percona/t/gap_lock_error_myisam.test b/mysql-test/suite/percona/t/gap_lock_error_myisam.test index a4e69908b4ff..f3419a79ad2f 100644 --- a/mysql-test/suite/percona/t/gap_lock_error_myisam.test +++ b/mysql-test/suite/percona/t/gap_lock_error_myisam.test @@ -3,6 +3,7 @@ let $engine=myisam; let $expect_gap_lock_errors=0; let $gap_lock_error_skip_partitioning=1; +--let $warning_or_error=WARNING --source include/gap_lock_error_init.inc select sum(value) from gap1; update gap1 set gap1.value= (select count(*) from gap2); diff --git a/mysql-test/suite/rocksdb/include/hermitage.inc b/mysql-test/suite/rocksdb/include/hermitage.inc index 91c2c277056a..6ec5ebc2e830 100644 --- a/mysql-test/suite/rocksdb/include/hermitage.inc +++ b/mysql-test/suite/rocksdb/include/hermitage.inc @@ -105,11 +105,6 @@ commit; --source suite/rocksdb/include/hermitage_init.inc connection con1; -# MyRocks does not support gap locks in REPEATABLE-READ mode, expect error -if ($trx_isolation == "REPEATABLE READ") -{ - --error ER_UNKNOWN_ERROR -} update test set value = value + 10; connection con2; select variable_value into @a from performance_schema.global_status where variable_name='rocksdb_snapshot_conflict_errors'; @@ -127,7 +122,7 @@ if ($trx_isolation == "READ COMMITTED") # MyRocks does not support gap locks in REPEATABLE-READ mode, expect error if ($trx_isolation == "REPEATABLE READ") { - --error ER_UNKNOWN_ERROR + --error ER_LOCK_DEADLOCK reap; select variable_value-@a from performance_schema.global_status where variable_name='rocksdb_snapshot_conflict_errors'; } @@ -184,11 +179,6 @@ connection con1; select * from test where value % 5 = 0; connection con2; -# MyRocks does not support gap locks in REPEATABLE-READ mode, expect error -if ($trx_isolation == "REPEATABLE READ") -{ - --error ER_UNKNOWN_ERROR -} update test set value = 12 where value = 10; commit; connection con1; @@ -215,7 +205,7 @@ if ($trx_isolation == "READ COMMITTED") # MyRocks does not support gap locks in REPEATABLE-READ mode, expect error if ($trx_isolation == "REPEATABLE READ") { - --error ER_UNKNOWN_ERROR + --error ER_LOCK_DEADLOCK delete from test where value = 20; } commit; diff --git a/mysql-test/suite/rocksdb/include/locking_issues_case1_2.inc b/mysql-test/suite/rocksdb/include/locking_issues_case1_2.inc index 0bfcfc58a0fc..4f75d0df3ffb 100644 --- a/mysql-test/suite/rocksdb/include/locking_issues_case1_2.inc +++ b/mysql-test/suite/rocksdb/include/locking_issues_case1_2.inc @@ -26,10 +26,6 @@ connect (con2,localhost,root,,); connection con1; eval SET SESSION TRANSACTION ISOLATION LEVEL $isolation_level; BEGIN; -if ($isolation_level == "REPEATABLE READ") -{ - --error ER_UNKNOWN_ERROR -} SELECT * FROM t0 WHERE id1=1 FOR UPDATE; connection con2; diff --git a/mysql-test/suite/rocksdb/include/locking_issues_case2.inc b/mysql-test/suite/rocksdb/include/locking_issues_case2.inc index a02f6bf2599a..b55528ea2000 100644 --- a/mysql-test/suite/rocksdb/include/locking_issues_case2.inc +++ b/mysql-test/suite/rocksdb/include/locking_issues_case2.inc @@ -45,48 +45,28 @@ if ($lock_scanned_rows == 1) { connection con1; # This is expected to leave locks on all the rows in t0 - # if in READ COMMITED, REPEATABLEREAD is a gap lock violation - if ($isolation_level == "REPEATABLE READ") - { - --error ER_UNKNOWN_ERROR - } + # if in READ COMMITED SELECT * FROM t0 WHERE value > 0 FOR UPDATE; connection con2; - if ($isolation_level == "READ COMMITTED") - { - --error ER_LOCK_WAIT_TIMEOUT - } + --error ER_LOCK_WAIT_TIMEOUT UPDATE t0 SET VALUE=10 WHERE id=1; } if ($lock_scanned_rows == 0) { connection con1; - if ($isolation_level == "REPEATABLE READ") - { - --error ER_UNKNOWN_ERROR - } - # This is expected to release locks on rows with value=0 SELECT * FROM t0 WHERE value > 0 FOR UPDATE; connection con2; # This should succeed as con1 should have released the lock on row (1,0) UPDATE t0 SET VALUE=10 WHERE id=1; - if ($isolation_level == "READ COMMITTED") - { - # This should fail because lock on row (5,1) is still held. - --error ER_LOCK_WAIT_TIMEOUT - } + --error ER_LOCK_WAIT_TIMEOUT UPDATE t0 SET VALUE=10 WHERE id=5; connection con1; # Do another operation - if ($isolation_level == "REPEATABLE READ") - { - --error ER_LOCK_WAIT_TIMEOUT - } UPDATE t0 SET value=100 WHERE id in (4,5) and value>0; connection con2; diff --git a/mysql-test/suite/rocksdb/include/locking_issues_case7.inc b/mysql-test/suite/rocksdb/include/locking_issues_case7.inc index e446df9aa327..35a830b3c535 100644 --- a/mysql-test/suite/rocksdb/include/locking_issues_case7.inc +++ b/mysql-test/suite/rocksdb/include/locking_issues_case7.inc @@ -65,10 +65,6 @@ if ($lock_scanned_rows == 0) UPDATE t1 JOIN t2 ON t1.id = t2.id SET t1.value=t1.value+100 WHERE t2.id=3; connection con2; - if ($isolation_level == "REPEATABLE READ") - { - --error ER_UNKNOWN_ERROR - } UPDATE t2 SET value=value+100; SELECT * FROM t2; } diff --git a/mysql-test/suite/rocksdb/include/transaction_isolation.inc b/mysql-test/suite/rocksdb/include/transaction_isolation.inc index c78ae0f8c389..d199c2ffeeb6 100644 --- a/mysql-test/suite/rocksdb/include/transaction_isolation.inc +++ b/mysql-test/suite/rocksdb/include/transaction_isolation.inc @@ -42,10 +42,6 @@ connection con1; --sorted_result SELECT a FROM t1; # Third snapshot -if ($trx_isolation == "REPEATABLE READ") -{ - --error ER_UNKNOWN_ERROR -} INSERT INTO t1 (a) SELECT a+100 FROM t1; --sorted_result @@ -67,10 +63,6 @@ SELECT a FROM t1; # Inside the transaction # The test will have a 'logical' result for repeatable read, even although # we currently don't have an engine which works this way. -if ($trx_isolation == "REPEATABLE READ") -{ - --error ER_UNKNOWN_ERROR -} INSERT INTO t1 (a) SELECT a+200 FROM t1; --sorted_result diff --git a/mysql-test/suite/rocksdb/include/unique_sec.inc b/mysql-test/suite/rocksdb/include/unique_sec.inc index a1c65f7e13a0..34e1e213a5c4 100644 --- a/mysql-test/suite/rocksdb/include/unique_sec.inc +++ b/mysql-test/suite/rocksdb/include/unique_sec.inc @@ -1,12 +1,8 @@ # Save the initial number of concurrent sessions --source include/count_sessions.inc -eval SET SESSION TRANSACTION ISOLATION LEVEL $trx_isolation; - connect (con1,localhost,root,,); -eval SET SESSION TRANSACTION ISOLATION LEVEL $trx_isolation; connect (con2,localhost,root,,); -eval SET SESSION TRANSACTION ISOLATION LEVEL $trx_isolation; connection con1; @@ -104,16 +100,8 @@ SELECT COUNT(*) FROM t1; INSERT INTO t1 VALUES (30, 31, 30, 30, 30, 30, 30, 30); --echo # Primary key should prevent duplicate on update -if ($trx_isolation == "REPEATABLE READ") -{ - --error ER_UNKNOWN_ERROR - UPDATE t1 SET id1=30, id2=31 WHERE id2=10; -} -if ($trx_isolation == "READ COMMITTED") -{ - --error ER_LOCK_WAIT_TIMEOUT - UPDATE t1 SET id1=30, id2=31 WHERE id2=10; -} +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t1 SET id1=30, id2=31 WHERE id2=10; --echo # Unique secondary key should prevent duplicate on insert --error ER_LOCK_WAIT_TIMEOUT @@ -122,20 +110,10 @@ INSERT INTO t1 VALUES (31, 31, 32, 33, 30, 30, 30, 30); INSERT INTO t1 VALUES (32, 32, 32, 32, 34, 32, 32, 32); --echo # Unique secondary key should prevent duplicate on update -if ($trx_isolation == "REPEATABLE READ") -{ - --error ER_UNKNOWN_ERROR - UPDATE t1 SET id2=31, id3=32, id4=33 WHERE id2=8; - --error ER_UNKNOWN_ERROR - UPDATE t1 SET id5=34 WHERE id2=8; -} -if ($trx_isolation == "READ COMMITTED") -{ - --error ER_LOCK_WAIT_TIMEOUT - UPDATE t1 SET id2=31, id3=32, id4=33 WHERE id2=8; - --error ER_LOCK_WAIT_TIMEOUT - UPDATE t1 SET id5=34 WHERE id2=8; -} +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t1 SET id2=31, id3=32, id4=33 WHERE id2=8; +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t1 SET id5=34 WHERE id2=8; --echo # Adding multiple rows where one of the rows fail the duplicate --echo # check should fail the whole statement @@ -157,33 +135,16 @@ INSERT INTO t1 VALUES (37, 31, 32, NULL, 37, 37, 37, 37), SELECT COUNT(*) FROM t1; -if ($trx_isolation == "REPEATABLE READ") -{ - --echo # Fail on duplicate key update for row added in our transaction - --error ER_UNKNOWN_ERROR - UPDATE t1 SET id5=37 WHERE id1=38; +--echo # Fail on duplicate key update for row added in our transaction +--error ER_DUP_ENTRY +UPDATE t1 SET id5=37 WHERE id1=38; - --echo # Fail on lock timeout for row modified in another transaction - --error ER_UNKNOWN_ERROR - UPDATE t1 SET id5=34 WHERE id1=38; +--echo # Fail on lock timeout for row modified in another transaction +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t1 SET id5=34 WHERE id1=38; - --echo # NULL values are unique - --error ER_UNKNOWN_ERROR - UPDATE t1 SET id5=NULL WHERE value1 > 37; -} -if ($trx_isolation == "READ COMMITTED") -{ - --echo # Fail on duplicate key update for row added in our transaction - --error ER_DUP_ENTRY - UPDATE t1 SET id5=37 WHERE id1=38; - - --echo # Fail on lock timeout for row modified in another transaction - --error ER_LOCK_WAIT_TIMEOUT - UPDATE t1 SET id5=34 WHERE id1=38; - - --echo # NULL values are unique - UPDATE t1 SET id5=NULL WHERE value1 > 37; -} +--echo # NULL values are unique +UPDATE t1 SET id5=NULL WHERE value1 > 37; connection con1; COMMIT; diff --git a/mysql-test/suite/rocksdb/r/gap_lock_error.result b/mysql-test/suite/rocksdb/r/gap_lock_error.result index c531f29017da..21166a6dafcb 100644 --- a/mysql-test/suite/rocksdb/r/gap_lock_error.result +++ b/mysql-test/suite/rocksdb/r/gap_lock_error.result @@ -1,3 +1,4 @@ +drop table if exists gap1,gap2,gap3; CREATE TABLE gap1 (id1 INT, id2 INT, id3 INT, c1 INT, value INT, PRIMARY KEY (id1, id2, id3), INDEX i (c1)) ENGINE=rocksdb; @@ -10,41 +11,51 @@ PRIMARY KEY (id)) ENGINE=rocksdb PARTITION BY HASH(id) PARTITIONS 2; 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); +CREATE TABLE gap5 ( +pk int primary key, +a int, +b int, +key(a) +) ENGINE=rocksdb; +insert into gap5 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +create table gap6 like gap5; +insert into gap6 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +set session gap_lock_raise_error= ERROR; set session autocommit=0; select * from gap1 limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 limit 1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 limit 1 for update select * from gap1 where value != 100 limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where value != 100 limit 1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where value != 100 limit 1 for update select * from gap1 where id1=1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 for update select * from gap1 where id1=1 and id2= 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 for update select * from gap1 where id1=1 and id2= 1 and id3 != 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 != 1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 != 1 for update select * from gap1 where id1=1 and id2= 1 and id3 between 1 and 3 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 between 1 and 3 for update select * from gap1 where id1=1 and id2= 1 order by id3 asc limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 asc +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 asc limit 1 for update select * from gap1 where id1=1 and id2= 1 order by id3 desc limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 desc +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 desc limit 1 for update select * from gap1 order by id1 asc limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc limit 1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc limit 1 for update select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 for update select * from gap1 order by id1 desc limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc limit 1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc limit 1 for update select * from gap1 order by id1 desc, id2 desc, id3 desc limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc, id2 desc, id3 desc +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc, id2 desc, id3 desc limit 1 for update select * from gap1 force index(i) where c1=1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 force index(i) where c1=1 for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 force index(i) where c1=1 for update select * from gap3 force index(ui) where value=1 for update; id value 1 1 @@ -58,18 +69,6 @@ id1 id2 id3 c1 value select * from gap3 where id=1 for update; id value 1 1 -select * from gap4 where id=1 for update; -id value -1 1 -select * from gap4 where id in (1, 2, 3) for update; -id value -1 1 -2 2 -3 3 -select * from gap4 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap4 for update -select * from gap4 where id between 3 and 7 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap4 where id between 3 and 7 for update set session autocommit=1; select * from gap1 limit 1 for update; id1 id2 id3 c1 value @@ -123,61 +122,41 @@ id1 id2 id3 c1 value select * from gap3 where id=1 for update; id value 1 1 -select * from gap4 where id=1 for update; -id value -1 1 -select * from gap4 where id in (1, 2, 3) for update; -id value -1 1 -2 2 -3 3 -select * from gap4 for update; -id value -2 2 -4 4 -1 1 -3 3 -5 5 -select * from gap4 where id between 3 and 7 for update; -id value -4 4 -3 3 -5 5 set session autocommit=0; select * from gap1 limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 limit 1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 limit 1 lock in share mode select * from gap1 where value != 100 limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where value != 100 limit 1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where value != 100 limit 1 lock in share mode select * from gap1 where id1=1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 lock in share mode select * from gap1 where id1=1 and id2= 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 lock in share mode select * from gap1 where id1=1 and id2= 1 and id3 != 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 != 1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 != 1 lock in share mode select * from gap1 where id1=1 and id2= 1 and id3 between 1 and 3 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 and id3 between 1 and 3 lock in share mode select * from gap1 where id1=1 and id2= 1 order by id3 asc limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 asc +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 asc limit 1 lock in share mode select * from gap1 where id1=1 and id2= 1 order by id3 desc limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 desc +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where id1=1 and id2= 1 order by id3 desc limit 1 lock in share mode select * from gap1 order by id1 asc limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc limit 1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc limit 1 lock in share mode select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 asc, id2 asc, id3 asc limit 1 lock in share mode select * from gap1 order by id1 desc limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc limit 1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc limit 1 lock in share mode select * from gap1 order by id1 desc, id2 desc, id3 desc limit 1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc, id2 desc, id3 desc +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 order by id1 desc, id2 desc, id3 desc limit 1 lock in share mode select * from gap1 force index(i) where c1=1 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 force index(i) where c1=1 lock in share mode +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 force index(i) where c1=1 lock in share mode select * from gap3 force index(ui) where value=1 lock in share mode; id value 1 1 @@ -191,18 +170,6 @@ id1 id2 id3 c1 value select * from gap3 where id=1 lock in share mode; id value 1 1 -select * from gap4 where id=1 lock in share mode; -id value -1 1 -select * from gap4 where id in (1, 2, 3) lock in share mode; -id value -1 1 -2 2 -3 3 -select * from gap4 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap4 lock in share mode -select * from gap4 where id between 3 and 7 lock in share mode; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap4 where id between 3 and 7 lock in share mode set session autocommit=1; select * from gap1 limit 1 lock in share mode; id1 id2 id3 c1 value @@ -256,26 +223,6 @@ id1 id2 id3 c1 value select * from gap3 where id=1 lock in share mode; id value 1 1 -select * from gap4 where id=1 lock in share mode; -id value -1 1 -select * from gap4 where id in (1, 2, 3) lock in share mode; -id value -1 1 -2 2 -3 3 -select * from gap4 lock in share mode; -id value -2 2 -4 4 -1 1 -3 3 -5 5 -select * from gap4 where id between 3 and 7 lock in share mode; -id value -4 4 -3 3 -5 5 set session autocommit=0; select * from gap1 limit 1 ; id1 id2 id3 c1 value @@ -329,26 +276,6 @@ id1 id2 id3 c1 value select * from gap3 where id=1 ; id value 1 1 -select * from gap4 where id=1 ; -id value -1 1 -select * from gap4 where id in (1, 2, 3) ; -id value -1 1 -2 2 -3 3 -select * from gap4 ; -id value -2 2 -4 4 -1 1 -3 3 -5 5 -select * from gap4 where id between 3 and 7 ; -id value -4 4 -3 3 -5 5 set session autocommit=1; select * from gap1 limit 1 ; id1 id2 id3 c1 value @@ -402,88 +329,6 @@ id1 id2 id3 c1 value select * from gap3 where id=1 ; id value 1 1 -select * from gap4 where id=1 ; -id value -1 1 -select * from gap4 where id in (1, 2, 3) ; -id value -1 1 -2 2 -3 3 -select * from gap4 ; -id value -2 2 -4 4 -1 1 -3 3 -5 5 -select * from gap4 where id between 3 and 7 ; -id value -4 4 -3 3 -5 5 -set session autocommit=0; -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; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: 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; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: delete from gap1 where id1=2 -delete from gap1 where id1=-1 and id2=-1 and id3=-1; -commit; -insert into gap2 select * from gap1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: insert into gap2 select * from gap1 -insert into gap2 select * from gap1 where id1=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: 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 t4 engine=rocksdb select * from gap1 where id1=1 and id2=1 and id3=1; -drop table t4; -create table t4 engine=rocksdb select * from gap1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: create table t4 engine=rocksdb select * from gap1 -create table t4 engine=rocksdb select * from gap1 where id1=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: create table t4 engine=rocksdb select * from gap1 where id1=1 -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; -update gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 set gap1.value=100 where gap2.id1=3; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 set gap1.value=100 where gap2.id1=3 -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 HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: 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 -update gap1 set gap1.value= (select count(*) from gap2); -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update gap1 set gap1.value= (select count(*) from gap2) -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; -delete gap1 from gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 where gap2.id1=3; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: delete gap1 from gap1 join gap2 on gap1.id1 and gap1.id2=gap2.id2 where gap2.id1=3 -select * from gap1, gap2 limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1, gap2 limit 1 for update -select * from gap1 a, gap1 b limit 1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from gap1 a, gap1 b limit 1 for update -create table u1( -c1 int, -c2 int, -c3 int, -c4 int, -primary key (c1, c2, c3), -unique key (c3, c1) -) engine=rocksdb; -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; -c1 c2 c3 c4 -1 1 1 10 -select * from u1 where c3=1 for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from u1 where c3=1 for update -commit; -drop table u1; set session autocommit=1; insert into gap1 (id1, id2, id3) values (-1,-1,-1); insert into gap1 (id1, id2, id3) values (-1,-1,-1) @@ -493,5 +338,70 @@ 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; -drop table gap1, gap2, gap3; +set global gap_lock_raise_error= off; +drop table gap1, gap2, gap3, gap5, gap6; +drop table gap4; +drop table if exists gap1,gap2,gap3; +CREATE TABLE gap1 (id1 INT, id2 INT, id3 INT, c1 INT, value INT, +PRIMARY KEY (id1, id2, id3), +INDEX i (c1)) ENGINE=rocksdb; +CREATE TABLE gap2 like gap1; +CREATE TABLE gap3 (id INT, value INT, +PRIMARY KEY (id), +UNIQUE KEY ui(value)) ENGINE=rocksdb; +CREATE TABLE gap4 (id INT, value INT, +PRIMARY KEY (id)) ENGINE=rocksdb +PARTITION BY HASH(id) PARTITIONS 2; +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); +CREATE TABLE gap5 ( +pk int primary key, +a int, +b int, +key(a) +) ENGINE=rocksdb; +insert into gap5 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +create table gap6 like gap5; +insert into gap6 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +set session gap_lock_raise_error= WARNING; +set session autocommit=0; +select * from gap1 limit 1 for update; +id1 id2 id3 c1 value +0 0 1 1 1 +select * from gap1 where value != 100 limit 1 for update; +id1 id2 id3 c1 value +0 0 1 1 1 +set global gap_lock_raise_error= off; +drop table gap1, gap2, gap3, gap5, gap6; +drop table gap4; +drop table if exists gap1,gap2,gap3; +CREATE TABLE gap1 (id1 INT, id2 INT, id3 INT, c1 INT, value INT, +PRIMARY KEY (id1, id2, id3), +INDEX i (c1)) ENGINE=rocksdb; +CREATE TABLE gap2 like gap1; +CREATE TABLE gap3 (id INT, value INT, +PRIMARY KEY (id), +UNIQUE KEY ui(value)) ENGINE=rocksdb; +CREATE TABLE gap4 (id INT, value INT, +PRIMARY KEY (id)) ENGINE=rocksdb +PARTITION BY HASH(id) PARTITIONS 2; +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); +CREATE TABLE gap5 ( +pk int primary key, +a int, +b int, +key(a) +) ENGINE=rocksdb; +insert into gap5 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +create table gap6 like gap5; +insert into gap6 values (1,1,1), (2,2,2), (3,3,3), (4,4,4); +set session gap_lock_raise_error= ERROR; +set session autocommit=0; +select * from gap1 limit 1 for update; +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 limit 1 for update +select * from gap1 where value != 100 limit 1 for update; +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from gap1 where value != 100 limit 1 for update +set global gap_lock_raise_error= off; +drop table gap1, gap2, gap3, gap5, gap6; drop table gap4; diff --git a/mysql-test/suite/rocksdb/r/gap_lock_issue254.result b/mysql-test/suite/rocksdb/r/gap_lock_issue254.result index 30fbaf47315a..31518c3f56d3 100644 --- a/mysql-test/suite/rocksdb/r/gap_lock_issue254.result +++ b/mysql-test/suite/rocksdb/r/gap_lock_issue254.result @@ -1,9 +1,11 @@ +set gap_lock_raise_error=error; create table t (id int primary key, value int) engine=rocksdb; begin; update t set value=100 where id in (1, 2); commit; begin; select * from t for update; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: select * from t for update +ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction. Query: select * from t for update commit; drop table t; +set gap_lock_raise_error=off; diff --git a/mysql-test/suite/rocksdb/r/hermitage.result b/mysql-test/suite/rocksdb/r/hermitage.result index 2781d94d0ade..0f518131aeeb 100644 --- a/mysql-test/suite/rocksdb/r/hermitage.result +++ b/mysql-test/suite/rocksdb/r/hermitage.result @@ -471,7 +471,6 @@ connection con3; begin; connection con1; update test set value = value + 10; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update test set value = value + 10 connection con2; select variable_value into @a from performance_schema.global_status where variable_name='rocksdb_snapshot_conflict_errors'; select * from test; @@ -482,10 +481,10 @@ delete from test where value = 20; connection con1; commit; connection con2; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: delete from test where value = 20 +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) select variable_value-@a from performance_schema.global_status where variable_name='rocksdb_snapshot_conflict_errors'; variable_value-@a -0 +1 commit; connection con1; truncate table test; @@ -510,7 +509,7 @@ update test set value = 12 where id = 1; connection con1; commit; connection con2; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) commit; connection con1; truncate table test; @@ -554,7 +553,6 @@ id value 2 20 connection con2; update test set value = 12 where value = 10; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update test set value = 12 where value = 10 commit; connection con1; select * from test where value % 3 = 0; @@ -582,7 +580,7 @@ update test set value = 18 where id = 2; commit; connection con1; delete from test where value = 20; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: delete from test where value = 20 +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) commit; connection con1; truncate table test; diff --git a/mysql-test/suite/rocksdb/r/issue111.result b/mysql-test/suite/rocksdb/r/issue111.result index 040b816f8bd3..e9d925f310ec 100644 --- a/mysql-test/suite/rocksdb/r/issue111.result +++ b/mysql-test/suite/rocksdb/r/issue111.result @@ -31,5 +31,5 @@ begin; update t1 set col2=123456 where pk=0; commit; update t1 set col2=col2+1 where col1 < 10 limit 5; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set col2=col2+1 where col1 < 10 limit 5 +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) drop table t1, ten, one_k; diff --git a/mysql-test/suite/rocksdb/r/level_repeatable_read.result b/mysql-test/suite/rocksdb/r/level_repeatable_read.result index 482249082103..bd2671333984 100644 --- a/mysql-test/suite/rocksdb/r/level_repeatable_read.result +++ b/mysql-test/suite/rocksdb/r/level_repeatable_read.result @@ -19,7 +19,6 @@ connection con1; SELECT a FROM t1; a INSERT INTO t1 (a) SELECT a+100 FROM t1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: INSERT INTO t1 (a) SELECT a+100 FROM t1 SELECT a FROM t1; a connection con2; @@ -36,7 +35,6 @@ connection con1; SELECT a FROM t1; a INSERT INTO t1 (a) SELECT a+200 FROM t1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: INSERT INTO t1 (a) SELECT a+200 FROM t1 SELECT a FROM t1; a COMMIT; @@ -91,7 +89,7 @@ INSERT INTO t3 (pk) VALUES(1) ON DUPLICATE KEY UPDATE count=count+1; COMMIT; connection con1; INSERT INTO t3 (pk) VALUES(1) ON DUPLICATE KEY UPDATE count=count+1; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) COMMIT; SELECT count FROM t3; count diff --git a/mysql-test/suite/rocksdb/r/locking_issues.result b/mysql-test/suite/rocksdb/r/locking_issues.result index 128a02454634..5393f0dd8290 100644 --- a/mysql-test/suite/rocksdb/r/locking_issues.result +++ b/mysql-test/suite/rocksdb/r/locking_issues.result @@ -54,7 +54,8 @@ INSERT INTO t0 VALUES (1,1,0), (3,3,0), (4,4,0), (6,6,0); SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN; SELECT * FROM t0 WHERE id1=1 FOR UPDATE; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: SELECT * FROM t0 WHERE id1=1 FOR UPDATE +id1 id2 value +1 1 0 SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN; SELECT * FROM t0 WHERE id1=1 AND id2=4 FOR UPDATE; @@ -100,11 +101,13 @@ BEGIN; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN; SELECT * FROM t0 WHERE value > 0 FOR UPDATE; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: SELECT * FROM t0 WHERE value > 0 FOR UPDATE +id value +2 1 +5 1 UPDATE t0 SET VALUE=10 WHERE id=1; UPDATE t0 SET VALUE=10 WHERE id=5; -UPDATE t0 SET value=100 WHERE id in (4,5) and value>0; ERROR HY000: Lock wait timeout exceeded; try restarting transaction +UPDATE t0 SET value=100 WHERE id in (4,5) and value>0; SELECT * FROM t0 WHERE id=4 FOR UPDATE; id value 4 0 @@ -115,7 +118,7 @@ id value 2 1 3 0 4 0 -5 10 +5 1 COMMIT; DROP TABLE t0; @@ -173,8 +176,11 @@ BEGIN; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; BEGIN; SELECT * FROM t0 WHERE value > 0 FOR UPDATE; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: SELECT * FROM t0 WHERE value > 0 FOR UPDATE +id value +2 1 +5 1 UPDATE t0 SET VALUE=10 WHERE id=1; +ERROR HY000: Lock wait timeout exceeded; try restarting transaction COMMIT; DROP TABLE t0; SET GLOBAL rocksdb_lock_scanned_rows=0; @@ -322,14 +328,13 @@ BEGIN; lock_scanned_rows is 0 UPDATE t1 JOIN t2 ON t1.id = t2.id SET t1.value=t1.value+100 WHERE t2.id=3; UPDATE t2 SET value=value+100; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t2 SET value=value+100 SELECT * FROM t2; id value -1 1 -2 2 -3 3 -4 4 -5 5 +1 101 +2 102 +3 103 +4 104 +5 105 COMMIT; DROP TABLE t1; DROP TABLE t2; diff --git a/mysql-test/suite/rocksdb/r/rocksdb_concurrent_delete.result b/mysql-test/suite/rocksdb/r/rocksdb_concurrent_delete.result index 69d46cb09e79..3364c00e4e18 100644 --- a/mysql-test/suite/rocksdb/r/rocksdb_concurrent_delete.result +++ b/mysql-test/suite/rocksdb/r/rocksdb_concurrent_delete.result @@ -20,14 +20,14 @@ SELECT * FROM t1 order by t1.pk ASC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 3; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) --PK end row delete SET debug_sync='rocksdb_concurrent_delete SIGNAL parked WAIT_FOR go'; SELECT * FROM t1 order by t1.pk ASC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 5; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) set debug_sync='RESET'; drop table t1; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; @@ -52,14 +52,14 @@ SELECT a FROM t1 FORCE INDEX(a) FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 3; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) --SK end row delete SET debug_sync='rocksdb_concurrent_upd_or_delete_sk SIGNAL parked WAIT_FOR go'; SELECT a FROM t1 FORCE INDEX(a) FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 5; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) set debug_sync='RESET'; drop table t1; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; @@ -84,14 +84,14 @@ SELECT * FROM t1 order by t1.pk DESC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 3; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) --PK end row delete SET debug_sync='rocksdb_concurrent_delete SIGNAL parked WAIT_FOR go'; SELECT * FROM t1 order by t1.pk DESC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 1; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) set debug_sync='RESET'; drop table t1; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; @@ -116,14 +116,14 @@ SELECT * FROM t1 order by t1.pk ASC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 3; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) --PK end row delete SET debug_sync='rocksdb_concurrent_delete SIGNAL parked WAIT_FOR go'; SELECT * FROM t1 order by t1.pk ASC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 5; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) set debug_sync='RESET'; drop table t1; SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; @@ -148,14 +148,14 @@ SELECT * FROM t1 order by t1.pk DESC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 3; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) --PK end row delete SET debug_sync='rocksdb_concurrent_delete SIGNAL parked WAIT_FOR go'; SELECT * FROM t1 order by t1.pk DESC FOR UPDATE; SET debug_sync='now WAIT_FOR parked'; DELETE FROM t1 WHERE pk = 1; SET debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) set debug_sync='RESET'; drop table t1; set debug_sync='RESET'; @@ -182,7 +182,7 @@ update t1 force index (PRIMARY) set value=200 where id1=1; set debug_sync='now WAIT_FOR parked'; delete from t1 where id1=1 and id2=3; set debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) select * from t1 where id1=1; id1 id2 value 1 2 100 @@ -195,7 +195,7 @@ update t1 force index (PRIMARY) set value=300 where id1=1; set debug_sync='now WAIT_FOR parked'; delete from t1 where id1=1 and id2=5; set debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) select * from t1 where id1=1; id1 id2 value 1 2 100 @@ -226,7 +226,7 @@ update t1 force index (sk) set value=200 where id1=1; set debug_sync='now WAIT_FOR parked'; delete from t1 where id1=1 and id2=3; set debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) select * from t1 where id1=1; id1 id2 value 1 2 100 @@ -239,7 +239,7 @@ update t1 force index (sk) set value=300 where id1=1; set debug_sync='now WAIT_FOR parked'; delete from t1 where id1=1 and id2=5; set debug_sync='now SIGNAL go'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) select * from t1 where id1=1; id1 id2 value 1 2 100 diff --git a/mysql-test/suite/rocksdb/r/rocksdb_concurrent_point_update_sk.result b/mysql-test/suite/rocksdb/r/rocksdb_concurrent_point_update_sk.result index 1aba3958792c..f49ec6d15c5e 100644 --- a/mysql-test/suite/rocksdb/r/rocksdb_concurrent_point_update_sk.result +++ b/mysql-test/suite/rocksdb/r/rocksdb_concurrent_point_update_sk.result @@ -1,3 +1,57 @@ +call mtr.add_suppression("Got error 522 when reading table"); +Conn A creating table +CREATE TABLE table1 ( +row_key BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, +val1 TINYINT NOT NULL, +val2 VARCHAR(128) NOT NULL, +PRIMARY KEY (row_key), +KEY idx_val1 (val1) +) ENGINE=RocksDB; +INSERT INTO table1 (val1, val2) VALUES (14, 'Alfa'), (14, 'Bravo'), (14, 'Charlie'), (14, 'Delta'); +Conn A: `table1` created with 4 rows +Conn A: Table before +SELECT * FROM table1; +row_key val1 val2 +1 14 Alfa +2 14 Bravo +3 14 Charlie +4 14 Delta +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +START TRANSACTION; +Conn A: Started TRANSACTION A (SELECT .. FOR UPDATE ) +set DEBUG_SYNC = "rocksdb_concurrent_upd_or_delete_sk SIGNAL waiting_for_update WAIT_FOR update_done"; +Conn A: activate DEBUG_SYNC point rocksdb_concurrent_upd_or_delete_sk +SELECT * from table1 FORCE INDEX(idx_val1) WHERE row_key = 1 AND val1 = 14 AND val2 = 'Alfa' FOR UPDATE; +Conn A: Sent SELECT +SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; +START TRANSACTION; +Conn B: Started TRANSACTION B (Concurrent update) +Conn B: Waiting for Conn A to hit `waiting_for_update` +set DEBUG_SYNC = "now WAIT_FOR waiting_for_update"; +Conn B: Conn A triggered `waiting_for_update` +UPDATE table1 SET val1 = 15 WHERE val1 = 14 AND val2 = 'Alfa'; +SELECT * FROM table1; +row_key val1 val2 +1 15 Alfa +2 14 Bravo +3 14 Charlie +4 14 Delta +COMMIT; +Conn B: COMMIT for update done +set DEBUG_SYNC = "now SIGNAL update_done"; +Conn B: signalled Conn A with event `update_done` +Conn A: reaping SELECT * from table1 FORCE INDEX(idx_val1) WHERE row_key = 1 AND val1 = 14 AND val2 = 'Alfa'; +The SELECT output should see the snapshot conflict error +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) +ROLLBACK; +Conn A: Table after +SELECT * FROM table1; +row_key val1 val2 +1 15 Alfa +2 14 Bravo +3 14 Charlie +4 14 Delta +DROP TABLE table1; Conn A creating table CREATE TABLE table1 ( row_key BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, diff --git a/mysql-test/suite/rocksdb/r/rocksdb_locks.result b/mysql-test/suite/rocksdb/r/rocksdb_locks.result index 925cd2c60dbd..c09959736dd6 100644 --- a/mysql-test/suite/rocksdb/r/rocksdb_locks.result +++ b/mysql-test/suite/rocksdb/r/rocksdb_locks.result @@ -57,7 +57,7 @@ UPDATE t1 SET value=30 WHERE id=3; COMMIT; connection con1; SELECT * FROM t1 WHERE id=3 FOR UPDATE; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) ROLLBACK; disconnect con1; connection default; diff --git a/mysql-test/suite/rocksdb/r/transaction.result b/mysql-test/suite/rocksdb/r/transaction.result index 2d7a1dbeeaf7..4f3c381cc18e 100644 --- a/mysql-test/suite/rocksdb/r/transaction.result +++ b/mysql-test/suite/rocksdb/r/transaction.result @@ -321,474 +321,8 @@ value 10 1 rollback; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; update t1 set value2=100 where value=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set value2=100 where value=1 -select * from t1 where id=1; -id value value2 -1 1 1 -select * from t1 where value=1; -id value value2 -1 1 1 -select value from t1 where value=1; -value -1 -select * from t1 where value2=1; -id value value2 -1 1 1 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select value from t1 where value < 3 order by id; -value -1 -2 -select * from t1 where value2 < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 order by id; -id value value2 -1 1 1 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -select value from t1 order by id; -value -1 -2 -3 -4 -5 -6 -8 -9 -10 -rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set value2=100 where value=1; -select * from t1 where id=1; -id value value2 -1 1 100 -select * from t1 where value=1; -id value value2 -1 1 100 -select value from t1 where value=1; -value -1 -select * from t1 where value2=1; -id value value2 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -1 1 100 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -1 1 100 -2 2 2 -select value from t1 where value < 3 order by id; -value -1 -2 -select * from t1 where value2 < 3 order by id; -id value value2 -2 2 2 -select * from t1 order by id; -id value value2 -1 1 100 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -select value from t1 order by id; -value -1 -2 -3 -4 -5 -6 -8 -9 -10 -rollback; -set session transaction_isolation=@orig_tx_iso; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; -begin; -update t1 set value=100 where value=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set value=100 where value=1 -select * from t1 where id=1; -id value value2 -1 1 1 -select * from t1 where value=1; -id value value2 -1 1 1 -select value from t1 where value=1; -value -1 -select * from t1 where value2=1; -id value value2 -1 1 1 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select value from t1 where value < 3 order by id; -value -1 -2 -select * from t1 where value2 < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 order by id; -id value value2 -1 1 1 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -select value from t1 order by id; -value -1 -2 -3 -4 -5 -6 -8 -9 -10 -rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set value=100 where value=1; -select * from t1 where id=1; -id value value2 -1 100 1 -select * from t1 where value=1; -id value value2 -select value from t1 where value=1; -value -select * from t1 where value2=1; -id value value2 -1 100 1 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -1 100 1 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -2 2 2 -select value from t1 where value < 3 order by id; -value -2 -select * from t1 where value2 < 3 order by id; -id value value2 -1 100 1 -2 2 2 -select * from t1 order by id; -id value value2 -1 100 1 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -select value from t1 order by id; -value -100 -2 -3 -4 -5 -6 -8 -9 -10 -rollback; -set session transaction_isolation=@orig_tx_iso; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; -begin; -update t1 set id=100 where value=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set id=100 where value=1 -select * from t1 where id=1; -id value value2 -1 1 1 -select * from t1 where value=1; -id value value2 -1 1 1 -select value from t1 where value=1; -value -1 -select * from t1 where value2=1; -id value value2 -1 1 1 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select value from t1 where value < 3 order by id; -value -1 -2 -select * from t1 where value2 < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 order by id; -id value value2 -1 1 1 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -select value from t1 order by id; -value -1 -2 -3 -4 -5 -6 -8 -9 -10 -rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set id=100 where value=1; -select * from t1 where id=1; -id value value2 -select * from t1 where value=1; -id value value2 -100 1 1 -select value from t1 where value=1; -value -1 -select * from t1 where value2=1; -id value value2 -100 1 1 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -2 2 2 -100 1 1 -select value from t1 where value < 3 order by id; -value -2 -1 -select * from t1 where value2 < 3 order by id; -id value value2 -2 2 2 -100 1 1 -select * from t1 order by id; -id value value2 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -100 1 1 -select value from t1 order by id; -value -2 -3 -4 -5 -6 -8 -9 -10 -1 -rollback; -set session transaction_isolation=@orig_tx_iso; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; -begin; -update t1 set value2=100 where value2=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set value2=100 where value2=1 -select * from t1 where id=1; -id value value2 -1 1 1 -select * from t1 where value=1; -id value value2 -1 1 1 -select value from t1 where value=1; -value -1 -select * from t1 where value2=1; -id value value2 -1 1 1 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select value from t1 where value < 3 order by id; -value -1 -2 -select * from t1 where value2 < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 order by id; -id value value2 -1 1 1 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -select value from t1 order by id; -value -1 -2 -3 -4 -5 -6 -8 -9 -10 -rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set value2=100 where value2=1; select * from t1 where id=1; id value value2 1 1 100 @@ -850,78 +384,8 @@ value 9 10 rollback; -set session transaction_isolation=@orig_tx_iso; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; -begin; -update t1 set value=100 where value2=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set value=100 where value2=1 -select * from t1 where id=1; -id value value2 -1 1 1 -select * from t1 where value=1; -id value value2 -1 1 1 -select value from t1 where value=1; -value -1 -select * from t1 where value2=1; -id value value2 -1 1 1 -select * from t1 where id=5; -id value value2 -5 5 5 -select * from t1 where value=5; -id value value2 -5 5 5 -select value from t1 where value=5; -value -5 -select * from t1 where value2=5; -id value value2 -5 5 5 -select * from t1 where id < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 where value < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select value from t1 where value < 3 order by id; -value -1 -2 -select * from t1 where value2 < 3 order by id; -id value value2 -1 1 1 -2 2 2 -select * from t1 order by id; -id value value2 -1 1 1 -2 2 2 -3 3 3 -4 4 4 -5 5 5 -6 6 6 -8 8 8 -9 9 9 -10 10 10 -select value from t1 order by id; -value -1 -2 -3 -4 -5 -6 -8 -9 -10 -rollback; -set session transaction_isolation='READ-COMMITTED'; begin; -update t1 set value=100 where value2=1; +update t1 set value=100 where value=1; select * from t1 where id=1; id value value2 1 100 1 @@ -981,24 +445,19 @@ value 9 10 rollback; -set session transaction_isolation=@orig_tx_iso; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; -update t1 set id=100 where value2=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set id=100 where value2=1 +update t1 set id=100 where value=1; select * from t1 where id=1; id value value2 -1 1 1 select * from t1 where value=1; id value value2 -1 1 1 +100 1 1 select value from t1 where value=1; value 1 select * from t1 where value2=1; id value value2 -1 1 1 +100 1 1 select * from t1 where id=5; id value value2 5 5 5 @@ -1013,23 +472,21 @@ id value value2 5 5 5 select * from t1 where id < 3 order by id; id value value2 -1 1 1 2 2 2 select * from t1 where value < 3 order by id; id value value2 -1 1 1 2 2 2 +100 1 1 select value from t1 where value < 3 order by id; value -1 2 +1 select * from t1 where value2 < 3 order by id; id value value2 -1 1 1 2 2 2 +100 1 1 select * from t1 order by id; id value value2 -1 1 1 2 2 2 3 3 3 4 4 4 @@ -1038,9 +495,9 @@ id value value2 8 8 8 9 9 9 10 10 10 +100 1 1 select value from t1 order by id; value -1 2 3 4 @@ -1049,21 +506,21 @@ value 8 9 10 +1 rollback; -set session transaction_isolation='READ-COMMITTED'; begin; -update t1 set id=100 where value2=1; +update t1 set value2=100 where value2=1; select * from t1 where id=1; id value value2 +1 1 100 select * from t1 where value=1; id value value2 -100 1 1 +1 1 100 select value from t1 where value=1; value 1 select * from t1 where value2=1; id value value2 -100 1 1 select * from t1 where id=5; id value value2 5 5 5 @@ -1078,21 +535,22 @@ id value value2 5 5 5 select * from t1 where id < 3 order by id; id value value2 +1 1 100 2 2 2 select * from t1 where value < 3 order by id; id value value2 +1 1 100 2 2 2 -100 1 1 select value from t1 where value < 3 order by id; value -2 1 +2 select * from t1 where value2 < 3 order by id; id value value2 2 2 2 -100 1 1 select * from t1 order by id; id value value2 +1 1 100 2 2 2 3 3 3 4 4 4 @@ -1101,9 +559,9 @@ id value value2 8 8 8 9 9 9 10 10 10 -100 1 1 select value from t1 order by id; value +1 2 3 4 @@ -1112,19 +570,19 @@ value 8 9 10 -1 rollback; -set session transaction_isolation=@orig_tx_iso; begin; -delete from t1 where id=1; +update t1 set value=100 where value2=1; select * from t1 where id=1; id value value2 +1 100 1 select * from t1 where value=1; id value value2 select value from t1 where value=1; value select * from t1 where value2=1; id value value2 +1 100 1 select * from t1 where id=5; id value value2 5 5 5 @@ -1139,6 +597,7 @@ id value value2 5 5 5 select * from t1 where id < 3 order by id; id value value2 +1 100 1 2 2 2 select * from t1 where value < 3 order by id; id value value2 @@ -1148,9 +607,11 @@ value 2 select * from t1 where value2 < 3 order by id; id value value2 +1 100 1 2 2 2 select * from t1 order by id; id value value2 +1 100 1 2 2 2 3 3 3 4 4 4 @@ -1161,6 +622,7 @@ id value value2 10 10 10 select value from t1 order by id; value +100 2 3 4 @@ -1170,23 +632,19 @@ value 9 10 rollback; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; -delete from t1 where value=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: delete from t1 where value=1 +update t1 set id=100 where value2=1; select * from t1 where id=1; id value value2 -1 1 1 select * from t1 where value=1; id value value2 -1 1 1 +100 1 1 select value from t1 where value=1; value 1 select * from t1 where value2=1; id value value2 -1 1 1 +100 1 1 select * from t1 where id=5; id value value2 5 5 5 @@ -1201,23 +659,21 @@ id value value2 5 5 5 select * from t1 where id < 3 order by id; id value value2 -1 1 1 2 2 2 select * from t1 where value < 3 order by id; id value value2 -1 1 1 2 2 2 +100 1 1 select value from t1 where value < 3 order by id; value -1 2 +1 select * from t1 where value2 < 3 order by id; id value value2 -1 1 1 2 2 2 +100 1 1 select * from t1 order by id; id value value2 -1 1 1 2 2 2 3 3 3 4 4 4 @@ -1226,9 +682,9 @@ id value value2 8 8 8 9 9 9 10 10 10 +100 1 1 select value from t1 order by id; value -1 2 3 4 @@ -1237,10 +693,10 @@ value 8 9 10 +1 rollback; -set session transaction_isolation='READ-COMMITTED'; begin; -delete from t1 where value=1; +delete from t1 where id=1; select * from t1 where id=1; id value value2 select * from t1 where value=1; @@ -1294,24 +750,16 @@ value 9 10 rollback; -set session transaction_isolation=@orig_tx_iso; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; -delete from t1 where value2=1; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: delete from t1 where value2=1 +delete from t1 where value=1; select * from t1 where id=1; id value value2 -1 1 1 select * from t1 where value=1; id value value2 -1 1 1 select value from t1 where value=1; value -1 select * from t1 where value2=1; id value value2 -1 1 1 select * from t1 where id=5; id value value2 5 5 5 @@ -1326,23 +774,18 @@ id value value2 5 5 5 select * from t1 where id < 3 order by id; id value value2 -1 1 1 2 2 2 select * from t1 where value < 3 order by id; id value value2 -1 1 1 2 2 2 select value from t1 where value < 3 order by id; value -1 2 select * from t1 where value2 < 3 order by id; id value value2 -1 1 1 2 2 2 select * from t1 order by id; id value value2 -1 1 1 2 2 2 3 3 3 4 4 4 @@ -1353,7 +796,6 @@ id value value2 10 10 10 select value from t1 order by id; value -1 2 3 4 @@ -1363,7 +805,6 @@ value 9 10 rollback; -set session transaction_isolation='READ-COMMITTED'; begin; delete from t1 where value2=1; select * from t1 where id=1; @@ -1419,20 +860,14 @@ value 9 10 rollback; -set session transaction_isolation=@orig_tx_iso; -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; insert into t1 values (11,11,11); insert into t1 values (12,12,12); insert into t1 values (13,13,13); delete from t1 where id=9; delete from t1 where value=8; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: delete from t1 where value=8 update t1 set id=100 where value2=5; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set id=100 where value2=5 update t1 set value=103 where value=4; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: update t1 set value=103 where value=4 update t1 set id=115 where id=3; select * from t1 where id=1; id value value2 @@ -1448,16 +883,15 @@ id value value2 1 1 1 select * from t1 where id=5; id value value2 -5 5 5 select * from t1 where value=5; id value value2 -5 5 5 +100 5 5 select value from t1 where value=5; value 5 select * from t1 where value2=5; id value value2 -5 5 5 +100 5 5 select * from t1 where id < 3 order by id; id value value2 1 1 1 @@ -1478,27 +912,25 @@ select * from t1 order by id; id value value2 1 1 1 2 2 2 -4 4 4 -5 5 5 +4 103 4 6 6 6 -8 8 8 10 10 10 11 11 11 12 12 12 13 13 13 +100 5 5 115 3 3 select value from t1 order by id; value 1 2 -4 -5 +103 6 -8 10 11 12 13 +5 3 rollback; set session transaction_isolation='READ-COMMITTED'; @@ -1575,7 +1007,6 @@ value 5 3 rollback; -set session transaction_isolation=@orig_tx_iso; drop table t1; # # #802: MyRocks: Statement rollback doesnt work correctly for nested statements diff --git a/mysql-test/suite/rocksdb/r/unique_check.result b/mysql-test/suite/rocksdb/r/unique_check.result index dd2ad87e45f6..dac15460db0b 100644 --- a/mysql-test/suite/rocksdb/r/unique_check.result +++ b/mysql-test/suite/rocksdb/r/unique_check.result @@ -101,7 +101,7 @@ Warnings: Warning 1287 'VALUES function' is deprecated and will be removed in a future release. Please use an alias (INSERT INTO ... VALUES (...) AS alias) and replace VALUES(col) in the ON DUPLICATE KEY UPDATE clause with alias.col instead commit; set debug_sync='now SIGNAL trx_a_cont'; -ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction (snapshot conflict) rollback; drop table t1; set debug_sync='RESET'; diff --git a/mysql-test/suite/rocksdb/r/unique_sec.result b/mysql-test/suite/rocksdb/r/unique_sec.result index 8db8814501c3..a6b60e80f857 100644 --- a/mysql-test/suite/rocksdb/r/unique_sec.result +++ b/mysql-test/suite/rocksdb/r/unique_sec.result @@ -1,6 +1,3 @@ -SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; -SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; -SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; CREATE TABLE t1 (id1 INT NOT NULL, id2 INT NOT NULL, id3 VARCHAR(32), id4 INT, id5 VARCHAR(32), value1 INT, value2 INT, value3 VARCHAR(32), @@ -162,9 +159,6 @@ id1 id2 id3 id4 id5 value1 value2 value3 39 31 32 NULL 39 37 37 37 40 40 40 40 40 40 40 40 DROP TABLE t1; -SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; -SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; -SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; CREATE TABLE t1 (id1 INT NOT NULL, id2 INT NOT NULL, id3 VARCHAR(32), id4 INT, id5 VARCHAR(32), value1 INT, value2 INT, value3 VARCHAR(32), @@ -244,7 +238,7 @@ INSERT INTO t1 VALUES (30, 31, 30, 30, 30, 30, 30, 30); ERROR HY000: Lock wait timeout exceeded; try restarting transaction # Primary key should prevent duplicate on update UPDATE t1 SET id1=30, id2=31 WHERE id2=10; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id1=30, id2=31 WHERE id2=10 +ERROR HY000: Lock wait timeout exceeded; try restarting transaction # Unique secondary key should prevent duplicate on insert INSERT INTO t1 VALUES (31, 31, 32, 33, 30, 30, 30, 30); ERROR HY000: Lock wait timeout exceeded; try restarting transaction @@ -252,9 +246,9 @@ INSERT INTO t1 VALUES (32, 32, 32, 32, 34, 32, 32, 32); ERROR HY000: Lock wait timeout exceeded; try restarting transaction # Unique secondary key should prevent duplicate on update UPDATE t1 SET id2=31, id3=32, id4=33 WHERE id2=8; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id2=31, id3=32, id4=33 WHERE id2=8 +ERROR HY000: Lock wait timeout exceeded; try restarting transaction UPDATE t1 SET id5=34 WHERE id2=8; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=34 WHERE id2=8 +ERROR HY000: Lock wait timeout exceeded; try restarting transaction # Adding multiple rows where one of the rows fail the duplicate # check should fail the whole statement INSERT INTO t1 VALUES (35, 35, 35, 35, 35, 35, 35, 35), @@ -276,13 +270,12 @@ COUNT(*) 16 # Fail on duplicate key update for row added in our transaction UPDATE t1 SET id5=37 WHERE id1=38; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=37 WHERE id1=38 +ERROR 23000: Duplicate entry '37' for key 't1.id5' # Fail on lock timeout for row modified in another transaction UPDATE t1 SET id5=34 WHERE id1=38; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=34 WHERE id1=38 +ERROR HY000: Lock wait timeout exceeded; try restarting transaction # NULL values are unique UPDATE t1 SET id5=NULL WHERE value1 > 37; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=NULL WHERE value1 > 37 COMMIT; COMMIT; BEGIN; diff --git a/mysql-test/suite/rocksdb/r/unique_sec_rev_cf.result b/mysql-test/suite/rocksdb/r/unique_sec_rev_cf.result index a5465e7bda76..7c373b5333b8 100644 --- a/mysql-test/suite/rocksdb/r/unique_sec_rev_cf.result +++ b/mysql-test/suite/rocksdb/r/unique_sec_rev_cf.result @@ -1,6 +1,3 @@ -SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; -SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; -SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED; CREATE TABLE t1 (id1 INT NOT NULL, id2 INT NOT NULL, id3 VARCHAR(32), id4 INT, id5 VARCHAR(32), value1 INT, value2 INT, value3 VARCHAR(32), @@ -162,168 +159,3 @@ id1 id2 id3 id4 id5 value1 value2 value3 2 2 2 2 2 3 1 1 1 1 1 1 1 2 0 0 DROP TABLE t1; -SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; -SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; -SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; -CREATE TABLE t1 (id1 INT NOT NULL, id2 INT NOT NULL, id3 VARCHAR(32), -id4 INT, id5 VARCHAR(32), -value1 INT, value2 INT, value3 VARCHAR(32), -PRIMARY KEY (id1, id2) COMMENT 'cfname=rev:cf', -UNIQUE INDEX (id2, id1) COMMENT 'cfname=rev:cf', -UNIQUE INDEX (id2, id3, id4) COMMENT 'cfname=rev:cf', -INDEX (id1) COMMENT 'cfname=rev:cf', -INDEX (id3, id1) COMMENT 'cfname=rev:cf', -UNIQUE INDEX(id5) COMMENT 'cfname=rev:cf', -INDEX (id2, id5)) ENGINE=ROCKSDB; -SELECT COUNT(*) FROM t1; -COUNT(*) -10 -# Test inserting a key that returns duplicate error -INSERT INTO t1 VALUES (1, 1, 11, 11, 11, 11, 11, 11); -ERROR 23000: Duplicate entry '1-1' for key 't1.PRIMARY' -INSERT INTO t1 VALUES (5, 5, 11, 11, 11, 11, 11, 11); -ERROR 23000: Duplicate entry '5-5' for key 't1.PRIMARY' -INSERT INTO t1 VALUES (10, 10, 11, 11, 11, 11, 11, 11); -ERROR 23000: Duplicate entry '10-10' for key 't1.PRIMARY' -INSERT INTO t1 VALUES (11, 1, 1, 1, 11, 11, 11, 11); -ERROR 23000: Duplicate entry '1-1-1' for key 't1.id2_2' -INSERT INTO t1 VALUES (11, 5, 5, 5, 11, 11, 11, 11); -ERROR 23000: Duplicate entry '5-5-5' for key 't1.id2_2' -INSERT INTO t1 VALUES (11, 10, 10, 10, 11, 11, 11, 11); -ERROR 23000: Duplicate entry '10-10-10' for key 't1.id2_2' -INSERT INTO t1 VALUES (11, 11, 11, 11, 1, 11, 11, 11); -ERROR 23000: Duplicate entry '1' for key 't1.id5' -INSERT INTO t1 VALUES (11, 11, 11, 11, 5, 11, 11, 11); -ERROR 23000: Duplicate entry '5' for key 't1.id5' -INSERT INTO t1 VALUES (11, 11, 11, 11, 10, 11, 11, 11); -ERROR 23000: Duplicate entry '10' for key 't1.id5' -# Test updating a key that returns duplicate error -UPDATE t1 SET id2=1, id3=1, id4=1 WHERE id1=2; -ERROR 23000: Duplicate entry '1-1-1' for key 't1.id2_2' -UPDATE t1 SET id2=1, id3=1, id4=1; -ERROR 23000: Duplicate entry '1-1-1' for key 't1.id2_2' -SELECT COUNT(*) FROM t1; -COUNT(*) -10 -# Test updating a key to itself -UPDATE t1 set id2=id4; -UPDATE t1 set id5=id3, value1=value2; -UPDATE t1 set value3=value1; -# Test modifying values should not cause duplicates -UPDATE t1 SET value1=value3+1; -UPDATE t1 SET value3=value3 div 2; -UPDATE t1 SET value2=value3; -SELECT COUNT(*) FROM t1; -COUNT(*) -10 -# Test NULL values are considered unique -INSERT INTO t1 VALUES (20, 20, 20, NULL, NULL, 20, 20, 20); -INSERT INTO t1 VALUES (21, 20, 20, NULL, NULL, 20, 20, 20); -INSERT INTO t1 VALUES (22, 20, 20, NULL, NULL, 20, 20, 20); -SELECT COUNT(*) FROM t1; -COUNT(*) -13 -# Adding multiple rows where one of the rows fail the duplicate -# check should fail the whole statement -INSERT INTO t1 VALUES (23, 23, 23, 23, 23, 23, 23, 23), -(24, 24, 24, 24, 24, 24, 24, 24), -(25, 10, 10, 10, 25, 25, 25, 25), -(26, 26, 26, 26, 26, 26, 26, 26); -ERROR 23000: Duplicate entry '10-10-10' for key 't1.id2_2' -SELECT COUNT(*) FROM t1; -COUNT(*) -13 -BEGIN; -INSERT INTO t1 VALUES (30, 31, 32, 33, 34, 30, 30, 30); -BEGIN; -SELECT COUNT(*) FROM t1; -COUNT(*) -13 -# Primary key should prevent duplicate on insert -INSERT INTO t1 VALUES (30, 31, 30, 30, 30, 30, 30, 30); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -# Primary key should prevent duplicate on update -UPDATE t1 SET id1=30, id2=31 WHERE id2=10; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id1=30, id2=31 WHERE id2=10 -# Unique secondary key should prevent duplicate on insert -INSERT INTO t1 VALUES (31, 31, 32, 33, 30, 30, 30, 30); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -INSERT INTO t1 VALUES (32, 32, 32, 32, 34, 32, 32, 32); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -# Unique secondary key should prevent duplicate on update -UPDATE t1 SET id2=31, id3=32, id4=33 WHERE id2=8; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id2=31, id3=32, id4=33 WHERE id2=8 -UPDATE t1 SET id5=34 WHERE id2=8; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=34 WHERE id2=8 -# Adding multiple rows where one of the rows fail the duplicate -# check should fail the whole statement -INSERT INTO t1 VALUES (35, 35, 35, 35, 35, 35, 35, 35), -(36, 36, 36, 36, 36, 36, 36, 36), -(37, 31, 32, 33, 37, 37, 37, 37), -(38, 38, 38, 38, 38, 38, 38, 38); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -INSERT INTO t1 VALUES (35, 35, 35, 35, 35, 35, 35, 35), -(36, 36, 36, 36, 36, 36, 36, 36), -(37, 37, 37, 37, 34, 37, 37, 37), -(38, 38, 38, 38, 38, 38, 38, 38); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -# NULL values are unique and duplicates in value fields are ignored -INSERT INTO t1 VALUES (37, 31, 32, NULL, 37, 37, 37, 37), -(38, 31, 32, NULL, 38, 37, 37, 37), -(39, 31, 32, NULL, 39, 37, 37, 37); -SELECT COUNT(*) FROM t1; -COUNT(*) -16 -# Fail on duplicate key update for row added in our transaction -UPDATE t1 SET id5=37 WHERE id1=38; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=37 WHERE id1=38 -# Fail on lock timeout for row modified in another transaction -UPDATE t1 SET id5=34 WHERE id1=38; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=34 WHERE id1=38 -# NULL values are unique -UPDATE t1 SET id5=NULL WHERE value1 > 37; -ERROR HY000: Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either rewrite queries to use all unique key columns in WHERE equal conditions, or rewrite to single-table, single-statement transaction. Query: UPDATE t1 SET id5=NULL WHERE value1 > 37 -COMMIT; -COMMIT; -BEGIN; -SELECT COUNT(*) FROM t1; -COUNT(*) -17 -BEGIN; -INSERT INTO t1 VALUES (40, 40, 40, 40, 40, 40, 40, 40); -# When transaction is pending, fail on lock acquisition -INSERT INTO t1 VALUES (40, 40, 40, 40, 40, 40, 40, 40); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -INSERT INTO t1 VALUES (41, 40, 40, 40, 40, 40, 40, 40); -ERROR HY000: Lock wait timeout exceeded; try restarting transaction -SELECT COUNT(*) FROM t1; -COUNT(*) -17 -COMMIT; -# When transaction is committed, fail on duplicate key -INSERT INTO t1 VALUES (40, 40, 40, 40, 40, 40, 40, 40); -Got one of the listed errors -INSERT INTO t1 VALUES (41, 40, 40, 40, 40, 40, 40, 40); -ERROR 23000: Duplicate entry '40-40-40' for key 't1.id2_2' -ROLLBACK; -SELECT * FROM t1; -id1 id2 id3 id4 id5 value1 value2 value3 -40 40 40 40 40 40 40 40 -39 31 32 NULL 39 37 37 37 -38 31 32 NULL 38 37 37 37 -37 31 32 NULL 37 37 37 37 -30 31 32 33 34 30 30 30 -22 20 20 NULL NULL 20 20 20 -21 20 20 NULL NULL 20 20 20 -20 20 20 NULL NULL 20 20 20 -10 10 10 10 10 11 5 5 -9 9 9 9 9 10 4 4 -8 8 8 8 8 9 4 4 -7 7 7 7 7 8 3 3 -6 6 6 6 6 7 3 3 -5 5 5 5 5 6 2 2 -4 4 4 4 4 5 2 2 -3 3 3 3 3 4 1 1 -2 2 2 2 2 3 1 1 -1 1 1 1 1 2 0 0 -DROP TABLE t1; diff --git a/mysql-test/suite/rocksdb/t/gap_lock_error.test b/mysql-test/suite/rocksdb/t/gap_lock_error.test index 6c9cf64259e6..461a622c95d8 100644 --- a/mysql-test/suite/rocksdb/t/gap_lock_error.test +++ b/mysql-test/suite/rocksdb/t/gap_lock_error.test @@ -1,5 +1,27 @@ --source include/have_rocksdb.inc let $engine=rocksdb; -let $expect_gap_lock_errors=1; + --source include/gap_lock_error_all.inc + +--let $warning_or_error=WARNING +--source include/gap_lock_error_init.inc + +set session autocommit=0; +--disable_warnings +select * from gap1 limit 1 for update; +select * from gap1 where value != 100 limit 1 for update; +--enable_warnings + +--source include/gap_lock_error_cleanup.inc + +--let $warning_or_error=ERROR +--source include/gap_lock_error_init.inc + +set session autocommit=0; +--error 1105 +select * from gap1 limit 1 for update; +--error 1105 +select * from gap1 where value != 100 limit 1 for update; + +--source include/gap_lock_error_cleanup.inc diff --git a/mysql-test/suite/rocksdb/t/gap_lock_issue254.test b/mysql-test/suite/rocksdb/t/gap_lock_issue254.test index 0b42496d1f62..408850ef425d 100644 --- a/mysql-test/suite/rocksdb/t/gap_lock_issue254.test +++ b/mysql-test/suite/rocksdb/t/gap_lock_issue254.test @@ -2,12 +2,15 @@ -- source include/have_rocksdb.inc # For issue#254 +set gap_lock_raise_error=error; create table t (id int primary key, value int) engine=rocksdb; begin; update t set value=100 where id in (1, 2); commit; begin; ---error ER_UNKNOWN_ERROR +--error 1105 select * from t for update; commit; drop table t; +# Set it back to 0 - otherwise mtr.check_warnings would trigger the check +set gap_lock_raise_error=off; \ No newline at end of file diff --git a/mysql-test/suite/rocksdb/t/issue111.test b/mysql-test/suite/rocksdb/t/issue111.test index 500b8c42b154..bf0cb3008e80 100644 --- a/mysql-test/suite/rocksdb/t/issue111.test +++ b/mysql-test/suite/rocksdb/t/issue111.test @@ -43,11 +43,7 @@ commit; connection default; -# MyRocks does not support gap locks in REPEATABLE-READ mode -# Upstream would have granted a ghost lock on the gaps and then encountered -# a real row deadlock. Percona Server prevents the gap lock entirely -# --error ER_LOCK_DEADLOCK ---error ER_UNKNOWN_ERROR +--error ER_LOCK_DEADLOCK update t1 set col2=col2+1 where col1 < 10 limit 5; disconnect con2; diff --git a/mysql-test/suite/rocksdb/t/rocksdb_concurrent_point_update_sk.test b/mysql-test/suite/rocksdb/t/rocksdb_concurrent_point_update_sk.test index d19933ca48d5..126945183998 100644 --- a/mysql-test/suite/rocksdb/t/rocksdb_concurrent_point_update_sk.test +++ b/mysql-test/suite/rocksdb/t/rocksdb_concurrent_point_update_sk.test @@ -1,3 +1,4 @@ +call mtr.add_suppression("Got error 522 when reading table"); --source include/have_rocksdb.inc --source include/have_debug_sync.inc @@ -16,8 +17,8 @@ # by the concurrent update will return KEY_NOT_FOUND back to the SQL layer # In this case, the user will be returned no row. -#let $isolation_level = REPEATABLE READ; -#--source rocksdb_concurrent_point_update_sk.inc +let $isolation_level = REPEATABLE READ; +--source rocksdb_concurrent_point_update_sk.inc let $isolation_level = READ COMMITTED; --source rocksdb_concurrent_point_update_sk.inc diff --git a/mysql-test/suite/rocksdb/t/transaction.test b/mysql-test/suite/rocksdb/t/transaction.test index 6f0a329842cf..8b18995b19f6 100644 --- a/mysql-test/suite/rocksdb/t/transaction.test +++ b/mysql-test/suite/rocksdb/t/transaction.test @@ -35,113 +35,41 @@ update t1 set id=100 where id=1; rollback; # update non-index column key by secondary key -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; ---error ER_UNKNOWN_ERROR update t1 set value2=100 where value=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set value2=100 where value=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation=@orig_tx_iso; + # update secondary key by secondary key -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; -begin; ---error ER_UNKNOWN_ERROR -update t1 set value=100 where value=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation='READ-COMMITTED'; begin; update t1 set value=100 where value=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation=@orig_tx_iso; # update primary key by secondary key -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; ---error ER_UNKNOWN_ERROR update t1 set id=100 where value=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set id=100 where value=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation=@orig_tx_iso; # update non-index column by non-index column -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; ---error ER_UNKNOWN_ERROR update t1 set value2=100 where value2=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set value2=100 where value2=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation=@orig_tx_iso; # update secondary key by non-index column -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; ---error ER_UNKNOWN_ERROR update t1 set value=100 where value2=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set value=100 where value2=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation=@orig_tx_iso; # update primary key column by non-index column -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; ---error ER_UNKNOWN_ERROR update t1 set id=100 where value2=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -update t1 set id=100 where value2=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation=@orig_tx_iso; - # delete by primary key begin; @@ -150,58 +78,25 @@ delete from t1 where id=1; rollback; # delete by secondary key -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; ---error ER_UNKNOWN_ERROR delete from t1 where value=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation='READ-COMMITTED'; -begin; -delete from t1 where value=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation=@orig_tx_iso; # delete by non-index column -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; -begin; ---error ER_UNKNOWN_ERROR -delete from t1 where value2=1; ---source suite/rocksdb/include/transaction_select.inc -rollback; -set session transaction_isolation='READ-COMMITTED'; begin; delete from t1 where value2=1; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation=@orig_tx_iso; - # mixed -# MyRocks does not support gap locks in REPEATABLE-READ mode, so we will -# execute this twice, once to illustrate the gap lock error in RR mode, and once -# in RC mode to illustrate passing functionality -set @orig_tx_iso=@@session.transaction_isolation; -set session transaction_isolation='REPEATABLE-READ'; begin; insert into t1 values (11,11,11); insert into t1 values (12,12,12); insert into t1 values (13,13,13); delete from t1 where id=9; ---error ER_UNKNOWN_ERROR delete from t1 where value=8; ---error ER_UNKNOWN_ERROR update t1 set id=100 where value2=5; ---error ER_UNKNOWN_ERROR update t1 set value=103 where value=4; update t1 set id=115 where id=3; --source suite/rocksdb/include/transaction_select.inc @@ -218,7 +113,6 @@ update t1 set value=103 where value=4; update t1 set id=115 where id=3; --source suite/rocksdb/include/transaction_select.inc rollback; -set session transaction_isolation=@orig_tx_iso; drop table t1; diff --git a/mysql-test/suite/rocksdb/t/unique_sec_rev_cf.test b/mysql-test/suite/rocksdb/t/unique_sec_rev_cf.test index e9740f1bfc8a..355d672cd8a0 100644 --- a/mysql-test/suite/rocksdb/t/unique_sec_rev_cf.test +++ b/mysql-test/suite/rocksdb/t/unique_sec_rev_cf.test @@ -2,11 +2,5 @@ let ddl= $MYSQLTEST_VARDIR/tmp/unique_sec_rev_cf.sql; --exec sed s/##CF##/" COMMENT 'cfname=rev:cf'"/g suite/rocksdb/include/unique_sec.inc > $ddl - -# MyRocks does not support gap locks in REPEATABLE-READ mode, so run through -# this sequence twice, one for each supported transaction level -let $trx_isolation = READ COMMITTED; ---source $ddl -let $trx_isolation = REPEATABLE READ; --source $ddl --remove_file $ddl diff --git a/share/messages_to_clients.txt b/share/messages_to_clients.txt index 645c2f54fb21..043fc2ca984c 100644 --- a/share/messages_to_clients.txt +++ b/share/messages_to_clients.txt @@ -10613,6 +10613,9 @@ ER_CF_DROPPED ER_CANT_DROP_CF eng "Cannot drop Column family ('%s') because it is in use or does not exist." +ER_GAP_LOCK_USED + eng "Using Gap Lock without full unique key in multi-table or multi-statement transactions is not allowed. You need to either 1: Execute 'SET SESSION gap_lock_raise_error=off' if you are sure that your application does not rely on Gap Lock. 2: Rewrite queries to use all unique key columns in WHERE equal conditions. 3: Rewrite to single-table, single-statement transaction." + # # End of MyRocks specific client messages # diff --git a/sql/handler.cc b/sql/handler.cc index ce333e327887..34cc0ec01077 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -4616,9 +4616,15 @@ void handler::print_error(int error, myf errflag) { case HA_ERR_LOCK_TABLE_FULL: textno = ER_LOCK_TABLE_FULL; break; - case HA_ERR_LOCK_DEADLOCK: - textno = ER_LOCK_DEADLOCK; - break; + case HA_ERR_LOCK_DEADLOCK: { + String str, + full_err_msg(ER_DEFAULT(ER_LOCK_DEADLOCK), system_charset_info); + get_error_message(error, &str); + full_err_msg.append(str); + my_printf_error(ER_LOCK_DEADLOCK, "%s", errflag, + full_err_msg.c_ptr_safe()); + return; + } case HA_ERR_READ_ONLY_TRANSACTION: textno = ER_READ_ONLY_TRANSACTION; break; @@ -8722,6 +8728,7 @@ bool handler::is_using_prohibited_gap_locks(TABLE *table, if (!using_full_primary_key && has_transactions() && !has_gap_locks() && thd_tx_isolation(thd) >= ISO_REPEATABLE_READ && !thd->rli_slave && + thd->gap_lock_raise_allowed() && (thd->lex->table_count >= 2 || thd->in_multi_stmt_transaction_mode()) && (lock_type >= TL_WRITE_ALLOW_WRITE || lock_type == TL_READ_WITH_SHARED_LOCKS || @@ -8731,15 +8738,17 @@ bool handler::is_using_prohibited_gap_locks(TABLE *table, thd->lex->sql_command != SQLCOM_CREATE_INDEX && thd->lex->sql_command != SQLCOM_CHECK && thd->lex->sql_command != SQLCOM_OPTIMIZE) { - my_printf_error(ER_UNKNOWN_ERROR, - "Using Gap Lock without full unique key in multi-table " - "or multi-statement transactions is not " - "allowed. You need to either rewrite queries to use " - "all unique key columns in WHERE equal conditions, or " - "rewrite to single-table, single-statement " - "transaction. Query: %s", - MYF(0), thd->query().str); - return true; + if (thd->gap_lock_raise_warning()) { + // raise a warning + push_warning(const_cast(thd), Sql_condition::SL_WARNING, + ER_GAP_LOCK_USED, ER_THD(thd, ER_GAP_LOCK_USED)); + return true; + } else if (thd->gap_lock_raise_error()) { + std::string msg(ER_THD(thd, ER_GAP_LOCK_USED)); + msg.append(" Query: %s"); + my_printf_error(ER_UNKNOWN_ERROR, msg.c_str(), MYF(0), thd->query().str); + return true; + } } return false; } diff --git a/sql/sql_class.h b/sql/sql_class.h index 0e326f68d8d3..16a5c24cf4cb 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4474,6 +4474,47 @@ class THD : public MDL_context_owner, */ void raise_note_printf(uint code, ...); + /* + Possible values used for gap_lock_raise_error session variable + - OFF: silent + - WARNING: raise a warning + - ERROR: raise an error + */ + enum enum_gap_lock_raise_values { + GAP_LOCK_RAISE_OFF = 0, + GAP_LOCK_RAISE_WARNING = 1, + GAP_LOCK_RAISE_ERROR = 2, + /* Add new control before the following line */ + GAP_LOCK_RAISE_INVALID + }; + + /** + Check whether we can raise warning/error when gap locks are used in a query + @return true if we can raise one, false otherwise. + */ + bool gap_lock_raise_allowed() const { + return (variables.gap_lock_raise_error != GAP_LOCK_RAISE_OFF ? true + : false); + } + + /** + Check whether we can raise a warning when gap locks are used in a query + @return true if we can raise a warning, false otherwise. + */ + bool gap_lock_raise_warning() const { + return (variables.gap_lock_raise_error == GAP_LOCK_RAISE_WARNING ? true + : false); + } + + /** + Check whether we can raise an error when gap locks are used in a query + @return true if we can raise an error, false otherwise. + */ + bool gap_lock_raise_error() const { + return (variables.gap_lock_raise_error == GAP_LOCK_RAISE_ERROR ? true + : false); + } + private: /* Only the implementation of the SIGNAL and RESIGNAL statements diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index ad8bfa281c3c..f6501029eece 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -130,6 +130,7 @@ #include "sql/server_component/log_builtins_imp.h" #include "sql/session_tracker.h" #include "sql/sp_head.h" // SP_PSI_STATEMENT_INFO_COUNT +#include "sql/sql_class.h" // THD, enum_gap_lock_raise_values #include "sql/sql_lex.h" #include "sql/sql_locale.h" // my_locale_by_number #include "sql/sql_parse.h" // killall_non_super_threads @@ -5917,6 +5918,19 @@ static Sys_var_ulong Sys_default_week_format( HINT_UPDATEABLE SESSION_VAR(default_week_format), CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 7), DEFAULT(0), BLOCK_SIZE(1)); +static const char *gap_lock_raise_values[] = {"OFF", "WARNING", "ERROR", 0}; + +static Sys_var_enum Sys_gap_lock_raise_error( + "gap_lock_raise_error", + "Controls raising a warning or an error when executing queries that " + "rely on Gap Lock. It can take the following values: " + "OFF: no error is raised " + "WARNING: a warning is raised " + "ERROR: an error is raised. " + "Default is OFF", + SESSION_VAR(gap_lock_raise_error), CMD_LINE(OPT_ARG), gap_lock_raise_values, + DEFAULT(THD::GAP_LOCK_RAISE_OFF)); + static Sys_var_ulong Sys_group_concat_max_len( "group_concat_max_len", "The maximum length of the result of function GROUP_CONCAT()", diff --git a/sql/system_variables.h b/sql/system_variables.h index b4645afc78e2..0b37ad166fdc 100644 --- a/sql/system_variables.h +++ b/sql/system_variables.h @@ -697,6 +697,11 @@ struct System_variables { */ Explain_format_type explain_format; + /** + @sa Sys_gap_lock_raise_error + */ + ulong gap_lock_raise_error; + /** Used to specify the JSON format version used by EXPLAIN FORMAT=JSON with the old (non-hypergraph) join optimizer. diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 4f1cbcae094d..89fe81c0d136 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -3236,6 +3236,7 @@ class Rdb_transaction { public: rocksdb::ReadOptions m_read_opts; int64_t m_snapshot_timestamp = 0; + String m_detailed_error; /* Tracks the number of tables in use through external_lock. @@ -3293,6 +3294,7 @@ class Rdb_transaction { if (s.IsDeadlock()) { thd->mark_transaction_to_rollback(true /* whole transaction */); + m_detailed_error = String(); rocksdb_row_lock_deadlocks++; return HA_ERR_LOCK_DEADLOCK; } else if (s.IsBusy()) { @@ -3305,6 +3307,7 @@ class Rdb_transaction { user_host_buff, static_cast(thd->query().length), thd->query().str); } + m_detailed_error = String(" (snapshot conflict)", system_charset_info); return HA_ERR_ROCKSDB_STATUS_BUSY; } @@ -8174,6 +8177,13 @@ bool ha_rocksdb::get_error_message(const int error, String *const buf) { "HA_ERR_ROCKSDB_LAST > HA_ERR_LAST"); assert(buf != nullptr); + if (error == HA_ERR_LOCK_WAIT_TIMEOUT || error == HA_ERR_LOCK_DEADLOCK || + error == HA_ERR_ROCKSDB_STATUS_BUSY) { + Rdb_transaction *const tx = get_tx_from_thd(ha_thd()); + assert(tx != nullptr); + buf->append(tx->m_detailed_error); + DBUG_RETURN(true); + } buf->append(rdb_get_error_messages(error));