[Commits] 38b85e5ff25: Range Locking: add a testcase for HA_READ_PREFIX_LAST range

Sergei Petrunia psergey at askmonty.org
Mon Apr 29 20:07:15 EEST 2019


revision-id: 38b85e5ff2564d495d69857f17f4ada547cdb44f (fb-prod201801-229-g38b85e5ff25)
parent(s): 0a80ecf45ff5973d4a01fb63e1f6fcdaf1ecf7e9
author: Sergei Petrunia
committer: Sergei Petrunia
timestamp: 2019-04-29 20:07:15 +0300
message:

Range Locking: add a testcase for HA_READ_PREFIX_LAST range

---
 .../rocksdb/include/select_from_is_rowlocks.inc    | 18 +++++--
 mysql-test/suite/rocksdb/r/range_locking.result    | 55 ++++++++++++++++++++++
 .../suite/rocksdb/r/range_locking_rev_cf.result    | 55 ++++++++++++++++++++++
 mysql-test/suite/rocksdb/t/range_locking.inc       | 52 ++++++++++++++++++++
 storage/rocksdb/ha_rocksdb.cc                      | 15 ++++++
 5 files changed, 190 insertions(+), 5 deletions(-)

diff --git a/mysql-test/suite/rocksdb/include/select_from_is_rowlocks.inc b/mysql-test/suite/rocksdb/include/select_from_is_rowlocks.inc
index 307b1e53552..61f3ee2c9f3 100644
--- a/mysql-test/suite/rocksdb/include/select_from_is_rowlocks.inc
+++ b/mysql-test/suite/rocksdb/include/select_from_is_rowlocks.inc
@@ -7,10 +7,18 @@ set @rtrx_id=(select transaction_id from information_schema.rocksdb_trx
 set @indexnr= (select lpad(hex(index_number),6,'0') from information_schema.rocksdb_ddl
                where table_name='t1' and index_name='PRIMARY');
 
-select 
-  replace(column_family_id, @cf_id, "$cf_id") as COLUMN_FAMILY_ID,
-  replace(transaction_id, @rtrx_id, "$trx_id")as TRANSACTION_ID,
-  replace(`key`, @indexnr, '${indexnr}') as `KEY`,
+let $extra_where = where 1;
+
+if ($select_from_is_rowlocks_current_trx_only) 
+{
+  let $extra_where = where transaction_id=(select transaction_id from information_schema.rocksdb_trx where connection_id()=thread_id);
+}
+
+eval select 
+  replace(column_family_id, @cf_id, "\$cf_id") as COLUMN_FAMILY_ID,
+  replace(transaction_id, @rtrx_id, "\$trx_id")as TRANSACTION_ID,
+  replace(`key`, @indexnr, '\${indexnr}') as `KEY`,
   mode
-from information_schema.rocksdb_locks;
+from information_schema.rocksdb_locks $extra_where;
+
 --enable_query_log
diff --git a/mysql-test/suite/rocksdb/r/range_locking.result b/mysql-test/suite/rocksdb/r/range_locking.result
index 5ab797b30d4..e9f6d667931 100644
--- a/mysql-test/suite/rocksdb/r/range_locking.result
+++ b/mysql-test/suite/rocksdb/r/range_locking.result
@@ -379,3 +379,58 @@ rollback;
 disconnect con1;
 connection default;
 drop table t1;
+#
+# Test range locking for ranges with HA_READ_PREFIX_LAST
+#
+create table t0(a int) engine=rocksdb;
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (
+pk1 int,
+pk2 int,
+a int,
+primary key(pk1, pk2) comment '$pk_cf'
+) engine=rocksdb;
+insert into t1 
+select 
+A.a, B.a, A.a*10+B.a
+from
+t0 A, t0 B;
+connect  con1,localhost,root,,;
+connection con1;
+begin;
+insert into t1 values (0x1112222,0x1112222,0);
+connection default;
+begin;
+# Should use ref access w/o filesort:
+explain
+select * from t1
+where pk1=3
+order by pk1 desc, pk2 desc
+for update;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	PRIMARY	PRIMARY	4	const	#	Using where
+select * from t1
+where pk1=3
+order by pk1 desc, pk2 desc
+for update;
+pk1	pk2	a
+3	9	39
+3	8	38
+3	7	37
+3	6	36
+3	5	35
+3	4	34
+3	3	33
+3	2	32
+3	1	31
+3	0	30
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_is_rowlocks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+0	$trx_id	0000${indexnr}80000003 - 0100${indexnr}80000003	X
+0	$trx_id	0000${indexnr}8000000280000009	X
+rollback;
+connection con1;
+rollback;
+disconnect con1;
+connection default;
+drop table t0, t1;
diff --git a/mysql-test/suite/rocksdb/r/range_locking_rev_cf.result b/mysql-test/suite/rocksdb/r/range_locking_rev_cf.result
index 073ebd3afa8..a52f35e1862 100644
--- a/mysql-test/suite/rocksdb/r/range_locking_rev_cf.result
+++ b/mysql-test/suite/rocksdb/r/range_locking_rev_cf.result
@@ -339,3 +339,58 @@ rollback;
 disconnect con1;
 connection default;
 drop table t1;
+#
+# Test range locking for ranges with HA_READ_PREFIX_LAST
+#
+create table t0(a int) engine=rocksdb;
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (
+pk1 int,
+pk2 int,
+a int,
+primary key(pk1, pk2) comment '$pk_cf'
+) engine=rocksdb;
+insert into t1 
+select 
+A.a, B.a, A.a*10+B.a
+from
+t0 A, t0 B;
+connect  con1,localhost,root,,;
+connection con1;
+begin;
+insert into t1 values (0x1112222,0x1112222,0);
+connection default;
+begin;
+# Should use ref access w/o filesort:
+explain
+select * from t1
+where pk1=3
+order by pk1 desc, pk2 desc
+for update;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	PRIMARY	PRIMARY	4	const	#	Using where
+select * from t1
+where pk1=3
+order by pk1 desc, pk2 desc
+for update;
+pk1	pk2	a
+3	9	39
+3	8	38
+3	7	37
+3	6	36
+3	5	35
+3	4	34
+3	3	33
+3	2	32
+3	1	31
+3	0	30
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_is_rowlocks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+0	$trx_id	0000${indexnr}80000003 - 0100${indexnr}80000003	X
+0	$trx_id	0000${indexnr}8000000280000009	X
+rollback;
+connection con1;
+rollback;
+disconnect con1;
+connection default;
+drop table t0, t1;
diff --git a/mysql-test/suite/rocksdb/t/range_locking.inc b/mysql-test/suite/rocksdb/t/range_locking.inc
index db71f91c3b0..866264176dc 100644
--- a/mysql-test/suite/rocksdb/t/range_locking.inc
+++ b/mysql-test/suite/rocksdb/t/range_locking.inc
@@ -411,3 +411,55 @@ disconnect con1;
 connection default;
 drop table t1;
 
+--echo #
+--echo # Test range locking for ranges with HA_READ_PREFIX_LAST
+--echo #
+create table t0(a int) engine=rocksdb;
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1 (
+  pk1 int,
+  pk2 int,
+  a int,
+  primary key(pk1, pk2) comment '$pk_cf'
+) engine=rocksdb;
+
+insert into t1 
+select 
+  A.a, B.a, A.a*10+B.a
+from
+  t0 A, t0 B;
+
+
+# Get a lock in another connection so that the primary transaction is not using
+# STO optimization, and its locks can be seen in I_S.rocksdb_locks
+--connect (con1,localhost,root,,)
+connection con1;
+begin;
+insert into t1 values (0x1112222,0x1112222,0);
+
+connection default;
+begin;
+--echo # Should use ref access w/o filesort:
+--replace_column 9 #
+explain
+select * from t1
+where pk1=3
+order by pk1 desc, pk2 desc
+for update;
+
+select * from t1
+where pk1=3
+order by pk1 desc, pk2 desc
+for update;
+
+let $select_from_is_rowlocks_current_trx_only=1;
+--source suite/rocksdb/include/select_from_is_rowlocks.inc
+rollback;
+
+connection con1;
+rollback;
+disconnect con1;
+connection default;
+
+drop table t0, t1;
diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc
index 0c4dea535ca..157e8f8bc16 100644
--- a/storage/rocksdb/ha_rocksdb.cc
+++ b/storage/rocksdb/ha_rocksdb.cc
@@ -8185,6 +8185,21 @@ int ha_rocksdb::set_range_lock(Rdb_transaction *tx,
     end_slice= slice;
   }
   else if (find_flag == HA_READ_PREFIX_LAST) {
+    /*
+       We get here for queries like:
+
+         select * from t1 where pk1=const order by pk1 desc for update
+
+       assuming this uses an index on (pk1, ...)
+       We get end_key=nullptr.
+
+       The range to lock is the same as with HA_READ_KEY_EXACT above.
+    */
+    end_slice= slice;
+    start_has_inf_suffix= false;
+    end_has_inf_suffix= true;
+  } 
+  else if (find_flag == HA_READ_PREFIX_LAST_OR_PREV) {
     //psergey-todo: swap the bounds? so that the start bounds is the end?
     //Testscase!
 


More information about the commits mailing list