Skip to content

Commit

Permalink
Issue facebook#22: SELECT ... FOR UPDATE takes a long time
Browse files Browse the repository at this point in the history
- Specify the right column family when making a rocksdb::Get() call.
  • Loading branch information
spetrunia authored and jkedgar committed Jan 4, 2017
1 parent 9f4757a commit cac1f42
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
31 changes: 31 additions & 0 deletions mysql-test/r/rocksdb.result
Original file line number Diff line number Diff line change
Expand Up @@ -1440,3 +1440,34 @@ PRIMARY KEY (id),
index (key1) comment '$per_idnex_cf'
)engine=rocksdb;
ERROR 42000: This version of MySQL doesn't yet support 'column family name looks like a typo of $per_index_cf'
#
# Issue #22: SELECT ... FOR UPDATE takes a long time
#
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t1 (
id1 int,
id2 int,
value1 int,
value2 int,
primary key(id1, id2) COMMENT 'new_column_family',
key(id2)
) engine=rocksdb default charset=latin1 collate=latin1_bin;
insert into t1 select A.a, B.a, 31, 1234 from t0 A, t0 B;
explain
select * from t1 where id1=30 and value1=30 for update;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref PRIMARY PRIMARY 4 const 10 Using where
set @var1=(select variable_value
from information_schema.global_status
where variable_name='rocksdb_number_keys_read');
select * from t1 where id1=3 and value1=3 for update;
id1 id2 value1 value2
set @var2=(select variable_value
from information_schema.global_status
where variable_name='rocksdb_number_keys_read');
# The following must return true (before the fix, the difference was 70):
select if((@var2 - @var1) < 30, 1, @var2-@var1);
if((@var2 - @var1) < 30, 1, @var2-@var1)
1
drop table t0,t1;
34 changes: 34 additions & 0 deletions mysql-test/t/rocksdb.test
Original file line number Diff line number Diff line change
Expand Up @@ -1283,3 +1283,37 @@ create table t1 (
index (key1) comment '$per_idnex_cf'
)engine=rocksdb;


--echo #
--echo # Issue #22: SELECT ... FOR UPDATE takes a long time
--echo #
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

create table t1 (
id1 int,
id2 int,
value1 int,
value2 int,
primary key(id1, id2) COMMENT 'new_column_family',
key(id2)
) engine=rocksdb default charset=latin1 collate=latin1_bin;

insert into t1 select A.a, B.a, 31, 1234 from t0 A, t0 B;

explain
select * from t1 where id1=30 and value1=30 for update;

set @var1=(select variable_value
from information_schema.global_status
where variable_name='rocksdb_number_keys_read');

select * from t1 where id1=3 and value1=3 for update;

set @var2=(select variable_value
from information_schema.global_status
where variable_name='rocksdb_number_keys_read');
--echo # The following must return true (before the fix, the difference was 70):
select if((@var2 - @var1) < 30, 1, @var2-@var1);

drop table t0,t1;
6 changes: 4 additions & 2 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,8 @@ int ha_rocksdb::rnd_next_with_direction(uchar *buf, bool move_forward)
bool found;
if (!trx->changes.Get(key, &retrieved_record, &found))
{
rocksdb::Status s= rdb->Get(options, key, &retrieved_record);
rocksdb::Status s= rdb->Get(options, pk_descr->get_cf(), key,
&retrieved_record);
found= !s.IsNotFound();
}

Expand Down Expand Up @@ -2774,7 +2775,8 @@ int ha_rocksdb::update_row(const uchar *old_data, uchar *new_data)
{
rocksdb::ReadOptions options;
/* Not setting options.snapshot, we need to check the real contents */
rocksdb::Status s= rdb->Get(options, key_slice, &retrieved_record);
rocksdb::Status s= rdb->Get(options, pk_descr->get_cf(), key_slice,
&retrieved_record);
found= !s.IsNotFound();
}

Expand Down

0 comments on commit cac1f42

Please sign in to comment.