Skip to content

Commit

Permalink
MariaRocks port: get rocksdb.rocksdb_icp[_rev] to work
Browse files Browse the repository at this point in the history
- Fix the test cases to not use userstat counters specific to
  facebook/mysql-5.6
- Make testcase also check MariaDB's ICP counters
- Remove ha_rocksdb::check_index_cond(), call handler_index_cond_check
  instead.
  • Loading branch information
spetrunia committed Jan 8, 2017
1 parent 93d3a39 commit 520d206
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 112 deletions.
39 changes: 2 additions & 37 deletions storage/rocksdb/ha_rocksdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6795,7 +6795,7 @@ int ha_rocksdb::find_icp_matching_index_rec(const bool &move_forward,
return HA_ERR_INTERNAL_ERROR;
}

const enum icp_result icp_status= check_index_cond();
const enum icp_result icp_status= handler_index_cond_check(this);
if (icp_status == ICP_NO_MATCH)
{
if (move_forward)
Expand All @@ -6804,7 +6804,7 @@ int ha_rocksdb::find_icp_matching_index_rec(const bool &move_forward,
m_scan_it->Prev();
continue; /* Get the next (or prev) index tuple */
}
else if (icp_status == ICP_OUT_OF_RANGE)
else if (icp_status == ICP_OUT_OF_RANGE || icp_status == ICP_ABORTED_BY_USER)
{
/* We have walked out of range we are scanning */
table->status= STATUS_NOT_FOUND;
Expand Down Expand Up @@ -9951,41 +9951,6 @@ class Item* ha_rocksdb::idx_cond_push(uint keyno, class Item* const idx_cond)
}


/*
@brief
Check the index condition.
@detail
Check the index condition. (The caller has unpacked all needed index
columns into table->record[0])
@return
ICP_NO_MATCH - Condition not satisfied (caller should continue
scanning)
OUT_OF_RANGE - We've left the range we're scanning (caller should
stop scanning and return HA_ERR_END_OF_FILE)
ICP_MATCH - Condition is satisfied (caller should fetch the record
and return it)
*/

enum icp_result ha_rocksdb::check_index_cond() const
{
DBUG_ASSERT(pushed_idx_cond);
DBUG_ASSERT(pushed_idx_cond_keyno != MAX_KEY);

// MARIAROCKS_NOT_YET: MariaRocks todo: switch to using
// handler_index_cond_check() call?
if (end_range && compare_key2(end_range) > 0)
{
/* caller should return HA_ERR_END_OF_FILE already */
return ICP_OUT_OF_RANGE;
}

return pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH;
}


/**
Checking if an index is used for ascending scan or not
Expand Down
1 change: 0 additions & 1 deletion storage/rocksdb/ha_rocksdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,6 @@ class ha_rocksdb: public my_core::handler
int index_last_intern(uchar *buf)
__attribute__((__nonnull__, __warn_unused_result__));

enum icp_result check_index_cond() const;
int find_icp_matching_index_rec(const bool &move_forward, uchar* const buf)
__attribute__((__nonnull__, __warn_unused_result__));

Expand Down
59 changes: 52 additions & 7 deletions storage/rocksdb/mysql-test/rocksdb/include/rocksdb_icp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ select * from t2 where kp1< 3 and kp2+1>50000;
select * from t2 where kp1< 3 and kp2+1>50000;

--echo # Try doing backwards scans
--echo # MariaDB: ICP is not supported for reverse scans.

--replace_column 9 #
explain
select * from t2 where kp1 between 1 and 10 and mod(kp2,2)=0 order by kp1 desc;
Expand All @@ -88,17 +90,60 @@ drop table t0,t1,t2,t3;
--echo #
--echo # First, some preparations
--echo #
--echo # in facebook/mysql-5.6, it was:
--echo # select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
--echo #
--echo # In MariaDB, we do:
delimiter |;
create procedure save_read_stats()
select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
into @rr, @rq, @rif, @rin
from information_schema.table_statistics
where table_name='t4' and table_schema=database();
begin
set @rr=(select ROWS_READ
from information_schema.table_statistics
where table_name='t4' and table_schema=database());

set @rif= (select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_read_first');

set @rin=(select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_read_next');

set @icp_attempts=(select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_attempts');

set @icp_matches=(select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_match');
end|

create procedure get_read_stats()
begin
select
ROWS_READ-@rr, ROWS_REQUESTED-@rq, ROWS_INDEX_FIRST-@rif, ROWS_INDEX_NEXT-@rin
from information_schema.table_statistics
where table_name='t4' and table_schema=database();
(select ROWS_READ
from information_schema.table_statistics
where table_name='t4' and table_schema=database()
) - @rr as ROWS_READ_DIFF,

(select VARIABLE_VALUE - @rif
from information_schema.session_status
where VARIABLE_NAME='Handler_read_first') as ROWS_INDEX_FIRST,

(select VARIABLE_VALUE - @rin
from information_schema.session_status
where VARIABLE_NAME='Handler_read_next') as ROWS_INDEX_NEXT,

(select VARIABLE_VALUE - @icp_attempts
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_attempts') as ICP_ATTEMPTS,

(select VARIABLE_VALUE - @icp_matches
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_match') as ICP_MATCHES;
end|

delimiter ;|

eval
create table t4 (
Expand Down
96 changes: 63 additions & 33 deletions storage/rocksdb/mysql-test/rocksdb/r/rocksdb_icp.result
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,17 @@ EXPLAIN
"table": {
"table_name": "t3",
"access_type": "range",
"possible_keys": [
"kp1"
],
"possible_keys": ["kp1"],
"key": "kp1",
"used_key_parts": [
"kp1"
],
"key_length": "5",
"used_key_parts": ["kp1"],
"rows": 1000,
"filtered": 100,
"index_condition": "((`test`.`t3`.`kp1` between 2 and 4) and ((`test`.`t3`.`kp1` % 3) = 0))",
"attached_condition": "(`test`.`t3`.`kp2` like '%foo%')"
"index_condition": "t3.kp1 between 2 and 4 and t3.kp1 % 3 = 0",
"attached_condition": "t3.kp2 like '%foo%'"
}
}
}
Warnings:
Note 1003 /* select#1 */ select `test`.`t3`.`pk` AS `pk`,`test`.`t3`.`kp1` AS `kp1`,`test`.`t3`.`kp2` AS `kp2`,`test`.`t3`.`col1` AS `col1` from `test`.`t3` where ((`test`.`t3`.`kp1` between 2 and 4) and ((`test`.`t3`.`kp1` % 3) = 0) and (`test`.`t3`.`kp2` like '%foo%'))
# Check that we handle the case where out-of-range is encountered sooner
# than matched index condition
explain
Expand All @@ -82,10 +76,11 @@ id select_type table type possible_keys key key_len ref rows Extra
select * from t2 where kp1< 3 and kp2+1>50000;
pk kp1 kp2 col1
# Try doing backwards scans
# MariaDB: ICP is not supported for reverse scans.
explain
select * from t2 where kp1 between 1 and 10 and mod(kp2,2)=0 order by kp1 desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range kp1 kp1 5 NULL # Using index condition
1 SIMPLE t2 range kp1 kp1 5 NULL # Using where
select * from t2 where kp1 between 1 and 10 and mod(kp2,2)=0 order by kp1 desc;
pk kp1 kp2 col1
10 10 10 10
Expand All @@ -96,7 +91,7 @@ pk kp1 kp2 col1
explain
select * from t2 where kp1 >990 and mod(kp2,2)=0 order by kp1 desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range kp1 kp1 5 NULL # Using index condition
1 SIMPLE t2 range kp1 kp1 5 NULL # Using where
select * from t2 where kp1 >990 and mod(kp2,2)=0 order by kp1 desc;
pk kp1 kp2 col1
998 998 998 998
Expand All @@ -106,7 +101,7 @@ pk kp1 kp2 col1
explain
select * from t2 where kp1< 3 and kp2+1>50000 order by kp1 desc;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range kp1 kp1 5 NULL # Using index condition
1 SIMPLE t2 range kp1 kp1 5 NULL # Using where
select * from t2 where kp1< 3 and kp2+1>50000 order by kp1 desc;
pk kp1 kp2 col1
drop table t0,t1,t2,t3;
Expand All @@ -115,16 +110,48 @@ drop table t0,t1,t2,t3;
#
# First, some preparations
#
# in facebook/mysql-5.6, it was:
# select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
#
# In MariaDB, we do:
create procedure save_read_stats()
select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
into @rr, @rq, @rif, @rin
begin
set @rr=(select ROWS_READ
from information_schema.table_statistics
where table_name='t4' and table_schema=database();
where table_name='t4' and table_schema=database());
set @rif= (select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_read_first');
set @rin=(select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_read_next');
set @icp_attempts=(select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_attempts');
set @icp_matches=(select VARIABLE_VALUE
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_match');
end|
create procedure get_read_stats()
begin
select
ROWS_READ-@rr, ROWS_REQUESTED-@rq, ROWS_INDEX_FIRST-@rif, ROWS_INDEX_NEXT-@rin
(select ROWS_READ
from information_schema.table_statistics
where table_name='t4' and table_schema=database();
where table_name='t4' and table_schema=database()
) - @rr as ROWS_READ_DIFF,
(select VARIABLE_VALUE - @rif
from information_schema.session_status
where VARIABLE_NAME='Handler_read_first') as ROWS_INDEX_FIRST,
(select VARIABLE_VALUE - @rin
from information_schema.session_status
where VARIABLE_NAME='Handler_read_next') as ROWS_INDEX_NEXT,
(select VARIABLE_VALUE - @icp_attempts
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_attempts') as ICP_ATTEMPTS,
(select VARIABLE_VALUE - @icp_matches
from information_schema.session_status
where VARIABLE_NAME='Handler_icp_match') as ICP_MATCHES;
end|
create table t4 (
id int,
id1 int,
Expand All @@ -142,8 +169,8 @@ insert into t4 values
#
call save_read_stats();
call get_read_stats();
ROWS_READ-@rr ROWS_REQUESTED-@rq ROWS_INDEX_FIRST-@rif ROWS_INDEX_NEXT-@rin
0 0 0 0
ROWS_READ_DIFF ROWS_INDEX_FIRST ROWS_INDEX_NEXT ICP_ATTEMPTS ICP_MATCHES
0 0 0 0 0
# ============== index-only query ==============
explain
select id1,id2 from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
Expand All @@ -154,10 +181,11 @@ select id1,id2 from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
id1 id2
1 1
call get_read_stats();
ROWS_READ-@rr 10
ROWS_REQUESTED-@rq 11
ROWS_INDEX_FIRST-@rif 1
ROWS_INDEX_NEXT-@rin 9
ROWS_READ_DIFF 10
ROWS_INDEX_FIRST 0
ROWS_INDEX_NEXT 10
ICP_ATTEMPTS 0
ICP_MATCHES 0
# ============== Query without ICP ==============
set optimizer_switch='index_condition_pushdown=off';
explain
Expand All @@ -169,10 +197,11 @@ select * from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
id id1 id2 value value2
1 1 1 1 1
call get_read_stats();
ROWS_READ-@rr 10
ROWS_REQUESTED-@rq 11
ROWS_INDEX_FIRST-@rif 1
ROWS_INDEX_NEXT-@rin 9
ROWS_READ_DIFF 10
ROWS_INDEX_FIRST 0
ROWS_INDEX_NEXT 10
ICP_ATTEMPTS 0
ICP_MATCHES 0
# ============== Query with ICP ==============
set optimizer_switch='index_condition_pushdown=on';
explain
Expand All @@ -184,10 +213,11 @@ select * from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
id id1 id2 value value2
1 1 1 1 1
call get_read_stats();
ROWS_READ-@rr 1
ROWS_REQUESTED-@rq 1
ROWS_INDEX_FIRST-@rif 1
ROWS_INDEX_NEXT-@rin 0
ROWS_READ_DIFF 1
ROWS_INDEX_FIRST 0
ROWS_INDEX_NEXT 1
ICP_ATTEMPTS 10
ICP_MATCHES 1
drop table t4;
drop procedure save_read_stats;
drop procedure get_read_stats;
Expand All @@ -212,7 +242,7 @@ set @count=0;
explain
select * from t1 where key1=1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref key1 key1 9 const # Using index condition
1 SIMPLE t1 ref key1 key1 9 const #
set @count_diff =(select (value - @count) from information_schema.rocksdb_perf_context
where table_schema=database() and table_name='t1' and stat_type='INTERNAL_KEY_SKIPPED_COUNT');
select * from t1 where key1=1;
Expand Down
Loading

0 comments on commit 520d206

Please sign in to comment.