[Commits] cd17512babf: Range Locking: test coverage for HA_READ_PREFIX_LAST_OR_PREV ranges.

Sergei Petrunia psergey at askmonty.org
Mon Apr 29 21:00:54 EEST 2019


revision-id: cd17512babf2c1cd94b8ada4945a4993fd163e83 (fb-prod201801-231-gcd17512babf)
parent(s): aca52c36332372a4aa71daf529bfb4383a6334d0
author: Sergei Petrunia
committer: Sergei Petrunia
timestamp: 2019-04-29 21:00:54 +0300
message:

Range Locking: test coverage for HA_READ_PREFIX_LAST_OR_PREV ranges.

---
 mysql-test/suite/rocksdb/r/range_locking.result    | 26 +++++++++++++++++
 .../suite/rocksdb/r/range_locking_rev_cf.result    | 26 +++++++++++++++++
 mysql-test/suite/rocksdb/t/range_locking.inc       | 22 ++++++++++++++
 storage/rocksdb/ha_rocksdb.cc                      | 34 +++++++++++++++-------
 4 files changed, 98 insertions(+), 10 deletions(-)

diff --git a/mysql-test/suite/rocksdb/r/range_locking.result b/mysql-test/suite/rocksdb/r/range_locking.result
index a5e17f679e5..f8dad8c7b07 100644
--- a/mysql-test/suite/rocksdb/r/range_locking.result
+++ b/mysql-test/suite/rocksdb/r/range_locking.result
@@ -429,6 +429,32 @@ COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
 $cf_id	$trx_id	0000${indexnr}80000003 - 0100${indexnr}80000003	X
 $cf_id	$trx_id	0000${indexnr}8000000280000009	X
 rollback;
+#
+# Test range locking for ranges with HA_READ_PREFIX_LAST_OR_PREV
+#
+begin;
+# Should use range access with 2 keyparts and w/o filesort:
+explain 
+select * from t1 
+where pk1=4 and pk2 between 5 and 8 
+order by pk1 desc, pk2 desc
+for update;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	8	NULL	#	Using where
+select * from t1
+where pk1=4  and pk2 between 5 and 8 
+order by pk1 desc, pk2 desc
+for update;
+pk1	pk2	a
+4	8	48
+4	7	47
+4	6	46
+4	5	45
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_is_rowlocks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+$cf_id	$trx_id	0000${indexnr}8000000480000005 - 0100${indexnr}8000000480000008	X
+$cf_id	$trx_id	0000${indexnr}8000000480000004	X
+rollback;
 connection con1;
 rollback;
 disconnect con1;
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 6ab62f1208b..b07c654e7d1 100644
--- a/mysql-test/suite/rocksdb/r/range_locking_rev_cf.result
+++ b/mysql-test/suite/rocksdb/r/range_locking_rev_cf.result
@@ -389,6 +389,32 @@ COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
 $cf_id	$trx_id	0000${indexnr}8000000280000009	X
 $cf_id	$trx_id	0000${indexnr}80000003 - 0100${indexnr}80000003	X
 rollback;
+#
+# Test range locking for ranges with HA_READ_PREFIX_LAST_OR_PREV
+#
+begin;
+# Should use range access with 2 keyparts and w/o filesort:
+explain 
+select * from t1 
+where pk1=4 and pk2 between 5 and 8 
+order by pk1 desc, pk2 desc
+for update;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	range	PRIMARY	PRIMARY	8	NULL	#	Using where
+select * from t1
+where pk1=4  and pk2 between 5 and 8 
+order by pk1 desc, pk2 desc
+for update;
+pk1	pk2	a
+4	8	48
+4	7	47
+4	6	46
+4	5	45
+# select * from information_schema.rocksdb_locks; # With replacements by select_from_is_rowlocks.inc
+COLUMN_FAMILY_ID	TRANSACTION_ID	KEY	mode
+$cf_id	$trx_id	0000${indexnr}8000000480000004	X
+$cf_id	$trx_id	0000${indexnr}8000000480000008 - 0100${indexnr}8000000480000005	X
+rollback;
 connection con1;
 rollback;
 disconnect con1;
diff --git a/mysql-test/suite/rocksdb/t/range_locking.inc b/mysql-test/suite/rocksdb/t/range_locking.inc
index 265694436b1..1c5fb92b584 100644
--- a/mysql-test/suite/rocksdb/t/range_locking.inc
+++ b/mysql-test/suite/rocksdb/t/range_locking.inc
@@ -458,6 +458,28 @@ let $select_from_is_rowlocks_current_trx_only=1;
 --source suite/rocksdb/include/select_from_is_rowlocks.inc
 rollback;
 
+--echo #
+--echo # Test range locking for ranges with HA_READ_PREFIX_LAST_OR_PREV
+--echo #
+
+begin;
+--echo # Should use range access with 2 keyparts and w/o filesort:
+--replace_column 9 #
+explain 
+select * from t1 
+where pk1=4 and pk2 between 5 and 8 
+order by pk1 desc, pk2 desc
+for update;
+
+select * from t1
+where pk1=4  and pk2 between 5 and 8 
+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;
diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc
index 157e8f8bc16..9342ca84b04 100644
--- a/storage/rocksdb/ha_rocksdb.cc
+++ b/storage/rocksdb/ha_rocksdb.cc
@@ -8160,12 +8160,14 @@ int ha_rocksdb::index_read_map(uchar *const buf, const uchar *const key,
 int ha_rocksdb::set_range_lock(Rdb_transaction *tx,
                                 const Rdb_key_def &kd, 
                                 const enum ha_rkey_function &find_flag,
-                                const rocksdb::Slice &slice,
+                                const rocksdb::Slice &slice_arg,
                                 const key_range *const end_key)
 {
   rocksdb::Slice end_slice;
   uchar end_slice_buf[MAX_KEY_LENGTH];
   bool start_has_inf_suffix = false, end_has_inf_suffix = false;
+  rocksdb::Slice slice(slice_arg);
+
 
   if (m_lock_rows != RDB_LOCK_WRITE || !rocksdb_use_range_locking) {
     return 0;
@@ -8200,18 +8202,30 @@ int ha_rocksdb::set_range_lock(Rdb_transaction *tx,
     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!
-
     /*
-      We have made the kd.successor(m_sk_packed_tuple) call above.
+       We get here for queries like:
 
-      The slice is at least Rdb_key_def::INDEX_NUMBER_SIZE bytes long.
+         select * from t1 where pk1=const1 and pk2 between const2 and const3 
+         order by pk1 desc 
+         for update
+
+       assuming this uses an index on (pk1, pk2).
+       The slice has the right endpoint: {const1, const3}
+       the end_key has the left endpoint: {const1, const2}.
     */
-    memcpy(end_slice_buf, slice.data(), slice.size());
-    kd.successor(end_slice_buf, slice.size());
-    end_slice= rocksdb::Slice((const char*)end_slice_buf, slice.size());
-    start_has_inf_suffix= end_has_inf_suffix= false;
+
+    // Move the right endpoint from slice to end_slice
+    end_slice= slice;
+   
+    // Pack the left endpoint and make "slice" point to it
+    uchar pack_buffer[MAX_KEY_LENGTH];
+    uint end_slice_size=
+        kd.pack_index_tuple(table, pack_buffer, end_slice_buf,
+                            end_key->key, end_key->keypart_map);
+    slice= rocksdb::Slice(reinterpret_cast<char *>(end_slice_buf),
+                              end_slice_size);
+    start_has_inf_suffix= false;
+    end_has_inf_suffix= true;
   }
   else if (end_key) {
     // Known start range bounds: HA_READ_KEY_OR_NEXT, HA_READ_AFTER_KEY


More information about the commits mailing list