Skip to content

Commit

Permalink
Refactoring index covering check to match MyRocks and add non-coverin…
Browse files Browse the repository at this point in the history
…g SK tests and rocksdb_covering_secondary_key stats

Summary:
When considering when a secondary key is covering, we need to also consider lookup bitmap for some special cases like using covering bitmap w/ prefix keys. This isn't much of an issue with 5.6 today because we don't actually enable covering bitmap format in prod but in 8.0 it might be an issue. Either way this refactors the covering check to be exactly the same as MyRocks does. Also adds more tests for covering / non covering prefix tests.

Also in order to catch cases where we incorrectly consider covering secondary keys to be non-covering, I've added rocksdb_covering_secondary_key_count support into bypass (should've done that earlier) and added checks in secondary range key tests to ensure covering check is done correctly.

Reviewed By: Pushapgl

Differential Revision: D26091555

fbshipit-source-id: 0f86e8284ef
  • Loading branch information
yizhang82 authored and facebook-github-bot committed Feb 19, 2021
1 parent f1dfd5a commit 30e9039
Show file tree
Hide file tree
Showing 21 changed files with 2,371 additions and 2,048 deletions.
42 changes: 42 additions & 0 deletions mysql-test/suite/rocksdb/include/bypass_create_table.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--disable_query_log
CREATE TABLE `link_table` (
`id1` bigint(20) unsigned NOT NULL DEFAULT '0' ,
`id1_type` int(10) unsigned NOT NULL DEFAULT '0' ,
Expand Down Expand Up @@ -344,3 +345,44 @@ insert into link_table4 values ('a1', "rk4", 5, 2, 1, 1, 'data15', 1, 1);
insert into link_table4 values ('b1', "rk5", 1, 2, 1, 1, 'data21', 1, 1);
insert into link_table4 values ('b1', "rk6", 2, 2, 1, 1, 'data22', 1, 1);
insert into link_table4 values ('b1', "rk7", 3, 2, 1, 1, 'data32', 1, 1);

CREATE TABLE `link_text` (
`id1` bigint(20) unsigned NOT NULL DEFAULT '0',
`id1_type` int(10) unsigned NOT NULL DEFAULT '0',
`id2` bigint(20) unsigned NOT NULL DEFAULT '0',
`id2_type` int(10) unsigned NOT NULL DEFAULT '0',
`link_type` bigint(20) unsigned NOT NULL DEFAULT '0',
`visibility` tinyint(4) NOT NULL DEFAULT '0',
`data` text COLLATE latin1_bin NOT NULL,
`time` int(10) unsigned NOT NULL DEFAULT '0',
`version` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`link_type`,`id1`,`id2`, `data`(255)) COMMENT 'cf_link',
KEY `id1_type` (`id1`,`link_type`,`visibility`,`time`,`id2`,`version`,
`data`(255))COMMENT 'rev:cf_link_id1_type'
) ENGINE=RocksDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

insert into link_text values (1, 1, 1, 2, 3, 4, 'a', 10, 125);
insert into link_text values (1, 1, 2, 2, 3, 4, 'aaaaaa', 10, 125);
insert into link_text values (1, 1, 3, 2, 3, 4, repeat('a', 255), 10, 125);
insert into link_text values (1, 1, 4, 2, 3, 4, repeat('a', 500), 10, 125);

CREATE TABLE `link_varchar` (
`id1` bigint(20) unsigned NOT NULL DEFAULT '0',
`id1_type` int(10) unsigned NOT NULL DEFAULT '0',
`id2` bigint(20) unsigned NOT NULL DEFAULT '0',
`id2_type` int(10) unsigned NOT NULL DEFAULT '0',
`link_type` bigint(20) unsigned NOT NULL DEFAULT '0',
`visibility` tinyint(4) NOT NULL DEFAULT '0',
`data` varchar(1000) COLLATE latin1_bin NOT NULL,
`time` int(10) unsigned NOT NULL DEFAULT '0',
`version` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`link_type`,`id1`,`id2`, `data`(255)) COMMENT 'cf_link',
KEY `id1_type` (`id1`,`link_type`,`visibility`,`time`,`id2`,`version`,
`data`(255)) COMMENT 'rev:cf_link_id1_type'
) ENGINE=RocksDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin
ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;

insert into link_varchar select * from link_text;

--enable_query_log
14 changes: 14 additions & 0 deletions mysql-test/suite/rocksdb/include/bypass_drop_table.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--disable_query_log
DROP TABLE count_table;
DROP TABLE link_table;
DROP TABLE link_table3;
DROP TABLE link_table2;
DROP TABLE id_table;
DROP TABLE node_table;
DROP TABLE link_table5;
DROP TABLE link_table5_rev;
DROP TABLE link_table6;
DROP TABLE link_table4;
DROP TABLE link_text;
DROP TABLE link_varchar;
--enable_query_log
17 changes: 17 additions & 0 deletions mysql-test/suite/rocksdb/include/verify_bypass_query.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# Parameters
# $bypass_query
# Bypass query to run
# $bypass_covering_sk
# Bypass query uses cover SK

--disable_query_log
SELECT @@rocksdb_select_bypass_policy INTO @__rocksdb_select_bypass_policy;
Expand All @@ -19,6 +21,9 @@ variable_name="rows_sent";
SELECT variable_value INTO @bypass_executed_0 FROM
information_schema.global_status WHERE
variable_name="rocksdb_select_bypass_executed";
SELECT variable_value INTO @bypass_covered_sk_0 FROM
information_schema.global_status WHERE
variable_name="rocksdb_covered_secondary_key_lookups";

--echo ========== Verifying Bypass Query ==========
--echo WITH BYPASS:
Expand All @@ -38,9 +43,14 @@ variable_name="rows_sent";
SELECT variable_value INTO @bypass_executed_1 FROM
information_schema.global_status WHERE
variable_name="rocksdb_select_bypass_executed";
SELECT variable_value INTO @bypass_covered_sk_1 FROM
information_schema.global_status WHERE
variable_name="rocksdb_covered_secondary_key_lookups";

--let rows_read_bypass=`SELECT @bypass_rows_read_1 - @bypass_rows_read_0`
SELECT @bypass_rows_read_1 - @bypass_rows_read_0 AS ROWS_READ;
--let cover_sk_bypass=`SELECT @bypass_covered_sk_1 - @bypass_covered_sk_0`
SELECT @bypass_covered_sk_1 - @bypass_covered_sk_0 AS COVERED_SK_LOOKUP;

--let $assert_cond= @bypass_executed_1 - @bypass_executed_0 = 1
--let $assert_text = Verify executed in bypass
Expand Down Expand Up @@ -98,4 +108,11 @@ let $assert_cond= @bypass_rows_sent_3 - @bypass_rows_sent_2 =
--let $assert_text = Verify bypass reads no more than regular query
--source include/assert.inc

if ($bypass_covering_sk == 1)
{
--let $assert_cond= $cover_sk_bypass = $rows_read_bypass
--let $assert_text = Verify bypass query uses covering SK
--source include/assert.inc
}

--enable_query_log
Loading

0 comments on commit 30e9039

Please sign in to comment.