Skip to content

Commit 520d206

Browse files
committed
MariaRocks port: get rocksdb.rocksdb_icp[_rev] to work
- 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.
1 parent 93d3a39 commit 520d206

File tree

7 files changed

+181
-112
lines changed

7 files changed

+181
-112
lines changed

storage/rocksdb/ha_rocksdb.cc

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6795,7 +6795,7 @@ int ha_rocksdb::find_icp_matching_index_rec(const bool &move_forward,
67956795
return HA_ERR_INTERNAL_ERROR;
67966796
}
67976797

6798-
const enum icp_result icp_status= check_index_cond();
6798+
const enum icp_result icp_status= handler_index_cond_check(this);
67996799
if (icp_status == ICP_NO_MATCH)
68006800
{
68016801
if (move_forward)
@@ -6804,7 +6804,7 @@ int ha_rocksdb::find_icp_matching_index_rec(const bool &move_forward,
68046804
m_scan_it->Prev();
68056805
continue; /* Get the next (or prev) index tuple */
68066806
}
6807-
else if (icp_status == ICP_OUT_OF_RANGE)
6807+
else if (icp_status == ICP_OUT_OF_RANGE || icp_status == ICP_ABORTED_BY_USER)
68086808
{
68096809
/* We have walked out of range we are scanning */
68106810
table->status= STATUS_NOT_FOUND;
@@ -9951,41 +9951,6 @@ class Item* ha_rocksdb::idx_cond_push(uint keyno, class Item* const idx_cond)
99519951
}
99529952

99539953

9954-
/*
9955-
@brief
9956-
Check the index condition.
9957-
9958-
@detail
9959-
Check the index condition. (The caller has unpacked all needed index
9960-
columns into table->record[0])
9961-
9962-
@return
9963-
ICP_NO_MATCH - Condition not satisfied (caller should continue
9964-
scanning)
9965-
OUT_OF_RANGE - We've left the range we're scanning (caller should
9966-
stop scanning and return HA_ERR_END_OF_FILE)
9967-
9968-
ICP_MATCH - Condition is satisfied (caller should fetch the record
9969-
and return it)
9970-
*/
9971-
9972-
enum icp_result ha_rocksdb::check_index_cond() const
9973-
{
9974-
DBUG_ASSERT(pushed_idx_cond);
9975-
DBUG_ASSERT(pushed_idx_cond_keyno != MAX_KEY);
9976-
9977-
// MARIAROCKS_NOT_YET: MariaRocks todo: switch to using
9978-
// handler_index_cond_check() call?
9979-
if (end_range && compare_key2(end_range) > 0)
9980-
{
9981-
/* caller should return HA_ERR_END_OF_FILE already */
9982-
return ICP_OUT_OF_RANGE;
9983-
}
9984-
9985-
return pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH;
9986-
}
9987-
9988-
99899954
/**
99909955
Checking if an index is used for ascending scan or not
99919956

storage/rocksdb/ha_rocksdb.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,6 @@ class ha_rocksdb: public my_core::handler
855855
int index_last_intern(uchar *buf)
856856
__attribute__((__nonnull__, __warn_unused_result__));
857857

858-
enum icp_result check_index_cond() const;
859858
int find_icp_matching_index_rec(const bool &move_forward, uchar* const buf)
860859
__attribute__((__nonnull__, __warn_unused_result__));
861860

storage/rocksdb/mysql-test/rocksdb/include/rocksdb_icp.inc

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ select * from t2 where kp1< 3 and kp2+1>50000;
6666
select * from t2 where kp1< 3 and kp2+1>50000;
6767

6868
--echo # Try doing backwards scans
69+
--echo # MariaDB: ICP is not supported for reverse scans.
70+
6971
--replace_column 9 #
7072
explain
7173
select * from t2 where kp1 between 1 and 10 and mod(kp2,2)=0 order by kp1 desc;
@@ -88,17 +90,60 @@ drop table t0,t1,t2,t3;
8890
--echo #
8991
--echo # First, some preparations
9092
--echo #
93+
--echo # in facebook/mysql-5.6, it was:
94+
--echo # select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
95+
--echo #
96+
--echo # In MariaDB, we do:
97+
delimiter |;
9198
create procedure save_read_stats()
92-
select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
93-
into @rr, @rq, @rif, @rin
94-
from information_schema.table_statistics
95-
where table_name='t4' and table_schema=database();
99+
begin
100+
set @rr=(select ROWS_READ
101+
from information_schema.table_statistics
102+
where table_name='t4' and table_schema=database());
103+
104+
set @rif= (select VARIABLE_VALUE
105+
from information_schema.session_status
106+
where VARIABLE_NAME='Handler_read_first');
107+
108+
set @rin=(select VARIABLE_VALUE
109+
from information_schema.session_status
110+
where VARIABLE_NAME='Handler_read_next');
111+
112+
set @icp_attempts=(select VARIABLE_VALUE
113+
from information_schema.session_status
114+
where VARIABLE_NAME='Handler_icp_attempts');
115+
116+
set @icp_matches=(select VARIABLE_VALUE
117+
from information_schema.session_status
118+
where VARIABLE_NAME='Handler_icp_match');
119+
end|
96120

97121
create procedure get_read_stats()
122+
begin
98123
select
99-
ROWS_READ-@rr, ROWS_REQUESTED-@rq, ROWS_INDEX_FIRST-@rif, ROWS_INDEX_NEXT-@rin
100-
from information_schema.table_statistics
101-
where table_name='t4' and table_schema=database();
124+
(select ROWS_READ
125+
from information_schema.table_statistics
126+
where table_name='t4' and table_schema=database()
127+
) - @rr as ROWS_READ_DIFF,
128+
129+
(select VARIABLE_VALUE - @rif
130+
from information_schema.session_status
131+
where VARIABLE_NAME='Handler_read_first') as ROWS_INDEX_FIRST,
132+
133+
(select VARIABLE_VALUE - @rin
134+
from information_schema.session_status
135+
where VARIABLE_NAME='Handler_read_next') as ROWS_INDEX_NEXT,
136+
137+
(select VARIABLE_VALUE - @icp_attempts
138+
from information_schema.session_status
139+
where VARIABLE_NAME='Handler_icp_attempts') as ICP_ATTEMPTS,
140+
141+
(select VARIABLE_VALUE - @icp_matches
142+
from information_schema.session_status
143+
where VARIABLE_NAME='Handler_icp_match') as ICP_MATCHES;
144+
end|
145+
146+
delimiter ;|
102147

103148
eval
104149
create table t4 (

storage/rocksdb/mysql-test/rocksdb/r/rocksdb_icp.result

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,17 @@ EXPLAIN
5050
"table": {
5151
"table_name": "t3",
5252
"access_type": "range",
53-
"possible_keys": [
54-
"kp1"
55-
],
53+
"possible_keys": ["kp1"],
5654
"key": "kp1",
57-
"used_key_parts": [
58-
"kp1"
59-
],
6055
"key_length": "5",
56+
"used_key_parts": ["kp1"],
6157
"rows": 1000,
6258
"filtered": 100,
63-
"index_condition": "((`test`.`t3`.`kp1` between 2 and 4) and ((`test`.`t3`.`kp1` % 3) = 0))",
64-
"attached_condition": "(`test`.`t3`.`kp2` like '%foo%')"
59+
"index_condition": "t3.kp1 between 2 and 4 and t3.kp1 % 3 = 0",
60+
"attached_condition": "t3.kp2 like '%foo%'"
6561
}
6662
}
6763
}
68-
Warnings:
69-
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%'))
7064
# Check that we handle the case where out-of-range is encountered sooner
7165
# than matched index condition
7266
explain
@@ -82,10 +76,11 @@ id select_type table type possible_keys key key_len ref rows Extra
8276
select * from t2 where kp1< 3 and kp2+1>50000;
8377
pk kp1 kp2 col1
8478
# Try doing backwards scans
79+
# MariaDB: ICP is not supported for reverse scans.
8580
explain
8681
select * from t2 where kp1 between 1 and 10 and mod(kp2,2)=0 order by kp1 desc;
8782
id select_type table type possible_keys key key_len ref rows Extra
88-
1 SIMPLE t2 range kp1 kp1 5 NULL # Using index condition
83+
1 SIMPLE t2 range kp1 kp1 5 NULL # Using where
8984
select * from t2 where kp1 between 1 and 10 and mod(kp2,2)=0 order by kp1 desc;
9085
pk kp1 kp2 col1
9186
10 10 10 10
@@ -96,7 +91,7 @@ pk kp1 kp2 col1
9691
explain
9792
select * from t2 where kp1 >990 and mod(kp2,2)=0 order by kp1 desc;
9893
id select_type table type possible_keys key key_len ref rows Extra
99-
1 SIMPLE t2 range kp1 kp1 5 NULL # Using index condition
94+
1 SIMPLE t2 range kp1 kp1 5 NULL # Using where
10095
select * from t2 where kp1 >990 and mod(kp2,2)=0 order by kp1 desc;
10196
pk kp1 kp2 col1
10297
998 998 998 998
@@ -106,7 +101,7 @@ pk kp1 kp2 col1
106101
explain
107102
select * from t2 where kp1< 3 and kp2+1>50000 order by kp1 desc;
108103
id select_type table type possible_keys key key_len ref rows Extra
109-
1 SIMPLE t2 range kp1 kp1 5 NULL # Using index condition
104+
1 SIMPLE t2 range kp1 kp1 5 NULL # Using where
110105
select * from t2 where kp1< 3 and kp2+1>50000 order by kp1 desc;
111106
pk kp1 kp2 col1
112107
drop table t0,t1,t2,t3;
@@ -115,16 +110,48 @@ drop table t0,t1,t2,t3;
115110
#
116111
# First, some preparations
117112
#
113+
# in facebook/mysql-5.6, it was:
114+
# select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
115+
#
116+
# In MariaDB, we do:
118117
create procedure save_read_stats()
119-
select ROWS_READ, ROWS_REQUESTED, ROWS_INDEX_FIRST, ROWS_INDEX_NEXT
120-
into @rr, @rq, @rif, @rin
118+
begin
119+
set @rr=(select ROWS_READ
121120
from information_schema.table_statistics
122-
where table_name='t4' and table_schema=database();
121+
where table_name='t4' and table_schema=database());
122+
set @rif= (select VARIABLE_VALUE
123+
from information_schema.session_status
124+
where VARIABLE_NAME='Handler_read_first');
125+
set @rin=(select VARIABLE_VALUE
126+
from information_schema.session_status
127+
where VARIABLE_NAME='Handler_read_next');
128+
set @icp_attempts=(select VARIABLE_VALUE
129+
from information_schema.session_status
130+
where VARIABLE_NAME='Handler_icp_attempts');
131+
set @icp_matches=(select VARIABLE_VALUE
132+
from information_schema.session_status
133+
where VARIABLE_NAME='Handler_icp_match');
134+
end|
123135
create procedure get_read_stats()
136+
begin
124137
select
125-
ROWS_READ-@rr, ROWS_REQUESTED-@rq, ROWS_INDEX_FIRST-@rif, ROWS_INDEX_NEXT-@rin
138+
(select ROWS_READ
126139
from information_schema.table_statistics
127-
where table_name='t4' and table_schema=database();
140+
where table_name='t4' and table_schema=database()
141+
) - @rr as ROWS_READ_DIFF,
142+
(select VARIABLE_VALUE - @rif
143+
from information_schema.session_status
144+
where VARIABLE_NAME='Handler_read_first') as ROWS_INDEX_FIRST,
145+
(select VARIABLE_VALUE - @rin
146+
from information_schema.session_status
147+
where VARIABLE_NAME='Handler_read_next') as ROWS_INDEX_NEXT,
148+
(select VARIABLE_VALUE - @icp_attempts
149+
from information_schema.session_status
150+
where VARIABLE_NAME='Handler_icp_attempts') as ICP_ATTEMPTS,
151+
(select VARIABLE_VALUE - @icp_matches
152+
from information_schema.session_status
153+
where VARIABLE_NAME='Handler_icp_match') as ICP_MATCHES;
154+
end|
128155
create table t4 (
129156
id int,
130157
id1 int,
@@ -142,8 +169,8 @@ insert into t4 values
142169
#
143170
call save_read_stats();
144171
call get_read_stats();
145-
ROWS_READ-@rr ROWS_REQUESTED-@rq ROWS_INDEX_FIRST-@rif ROWS_INDEX_NEXT-@rin
146-
0 0 0 0
172+
ROWS_READ_DIFF ROWS_INDEX_FIRST ROWS_INDEX_NEXT ICP_ATTEMPTS ICP_MATCHES
173+
0 0 0 0 0
147174
# ============== index-only query ==============
148175
explain
149176
select id1,id2 from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
@@ -154,10 +181,11 @@ select id1,id2 from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
154181
id1 id2
155182
1 1
156183
call get_read_stats();
157-
ROWS_READ-@rr 10
158-
ROWS_REQUESTED-@rq 11
159-
ROWS_INDEX_FIRST-@rif 1
160-
ROWS_INDEX_NEXT-@rin 9
184+
ROWS_READ_DIFF 10
185+
ROWS_INDEX_FIRST 0
186+
ROWS_INDEX_NEXT 10
187+
ICP_ATTEMPTS 0
188+
ICP_MATCHES 0
161189
# ============== Query without ICP ==============
162190
set optimizer_switch='index_condition_pushdown=off';
163191
explain
@@ -169,10 +197,11 @@ select * from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
169197
id id1 id2 value value2
170198
1 1 1 1 1
171199
call get_read_stats();
172-
ROWS_READ-@rr 10
173-
ROWS_REQUESTED-@rq 11
174-
ROWS_INDEX_FIRST-@rif 1
175-
ROWS_INDEX_NEXT-@rin 9
200+
ROWS_READ_DIFF 10
201+
ROWS_INDEX_FIRST 0
202+
ROWS_INDEX_NEXT 10
203+
ICP_ATTEMPTS 0
204+
ICP_MATCHES 0
176205
# ============== Query with ICP ==============
177206
set optimizer_switch='index_condition_pushdown=on';
178207
explain
@@ -184,10 +213,11 @@ select * from t4 force index (id1_id2) where id1=1 and id2 % 10 = 1;
184213
id id1 id2 value value2
185214
1 1 1 1 1
186215
call get_read_stats();
187-
ROWS_READ-@rr 1
188-
ROWS_REQUESTED-@rq 1
189-
ROWS_INDEX_FIRST-@rif 1
190-
ROWS_INDEX_NEXT-@rin 0
216+
ROWS_READ_DIFF 1
217+
ROWS_INDEX_FIRST 0
218+
ROWS_INDEX_NEXT 1
219+
ICP_ATTEMPTS 10
220+
ICP_MATCHES 1
191221
drop table t4;
192222
drop procedure save_read_stats;
193223
drop procedure get_read_stats;
@@ -212,7 +242,7 @@ set @count=0;
212242
explain
213243
select * from t1 where key1=1;
214244
id select_type table type possible_keys key key_len ref rows Extra
215-
1 SIMPLE t1 ref key1 key1 9 const # Using index condition
245+
1 SIMPLE t1 ref key1 key1 9 const #
216246
set @count_diff =(select (value - @count) from information_schema.rocksdb_perf_context
217247
where table_schema=database() and table_name='t1' and stat_type='INTERNAL_KEY_SKIPPED_COUNT');
218248
select * from t1 where key1=1;

0 commit comments

Comments
 (0)