1--source include/have_rocksdb.inc
2
3--source include/restart_mysqld.inc
4
5CREATE TABLE `linktable` (
6  `id1` bigint(20) unsigned NOT NULL DEFAULT '0',
7  `id1_type` int(10) unsigned NOT NULL DEFAULT '0',
8  `id2` bigint(20) unsigned NOT NULL DEFAULT '0',
9  `id2_type` int(10) unsigned NOT NULL DEFAULT '0',
10  `link_type` bigint(20) unsigned NOT NULL DEFAULT '0',
11  `visibility` tinyint(3) NOT NULL DEFAULT '0',
12  `data` varchar(255) NOT NULL DEFAULT '',
13  `time` bigint(20) unsigned NOT NULL DEFAULT '0',
14  `version` int(11) unsigned NOT NULL DEFAULT '0',
15  PRIMARY KEY (link_type, `id1`,`id2`) COMMENT 'cf_link_pk',
16  KEY `id1_type` (`id1`,`link_type`,`visibility`,`time`,`version`,`data`) COMMENT 'rev:cf_link_id1_type',
17  KEY `id1_type2` (`id1`,`link_type`,`time`,`version`,`data`,`visibility`) COMMENT 'rev:cf_link_id1_type2',
18  KEY `id1_type3` (`id1`,`visibility`,`time`,`version`,`data`,`link_type`) COMMENT 'rev:cf_link_id1_type3'
19) ENGINE=ROCKSDB DEFAULT COLLATE=latin1_bin;
20
21--disable_query_log
22call mtr.add_suppression("LibRocksDB");
23let $i = 1;
24while ($i <= 10000) {
25  let $insert = INSERT INTO linktable VALUES($i, $i, $i, $i, 1, 1, $i, $i, $i);
26  eval $insert;
27  inc $i;
28}
29--enable_query_log
30
31## HA_READ_PREFIX_LAST_OR_PREV
32# BF len 21
33select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
34select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type`)  where id1 = 100 and link_type = 1 and time >= 0 and time <= 9223372036854775807 and visibility = 1 order by time desc;
35select case when variable_value-@c > 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
36
37# BF len 20
38select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
39select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type2`)  where id1 = 100 and link_type = 1 and time >= 0 and time <= 9223372036854775807 order by time desc;
40select case when variable_value-@c > 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
41
42# BF len 13
43select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
44select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type3`)  where id1 = 100 and time >= 0 and time <= 9223372036854775807 and visibility = 1 order by time desc;
45select case when variable_value-@c = 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
46
47## HA_READ_PREFIX_LAST_OR_PREV (no end range)
48# BF len 20
49select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
50select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type`)  where id1 = 100 and link_type = 1 and visibility = 1 and time >= 0 order by time desc;
51select case when variable_value-@c > 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
52
53# BF len 19
54select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
55select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type2`)  where id1 = 100 and link_type = 1 and time >= 0 order by time desc;
56select case when variable_value-@c = 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
57
58--echo ## HA_READ_PREFIX_LAST
59--echo # BF len 20
60select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
61select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type`)  where id1 = 100 and link_type = 1 and visibility = 1 order by time desc;
62select case when variable_value-@c > 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
63
64--echo # BF len 19
65select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
66select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type2`)  where id1 = 100 and link_type = 1 order by time desc;
67select case when variable_value-@c = 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
68
69--echo # BF len 12
70select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
71select id1, id2, link_type, visibility, data, time, version from linktable FORCE INDEX(`id1_type3`)  where id1 = 100 and visibility = 1 order by time desc;
72select case when variable_value-@c = 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
73
74
75DROP TABLE linktable;
76--source include/restart_mysqld.inc
77
78--echo #
79--echo # bloom filter prefix is 20 byte
80--echo #  Create a key which is longer than that, so that we see that
81--echo #       eq_cond_len= slice.size() - 1;
82--echo #  doesnt work.
83--echo #
84--echo #   indexnr   4
85--echo #   kp0     + 4 =  8
86--echo #   kp1     + 8 = 16
87--echo #   kp2     + 8 = 24    24>20 byte length prefix
88--echo #   kp3     + 8 = 28
89
90create table t1 (
91  pk int primary key,
92  kp0 int not null,
93  kp1 bigint not null,
94  kp2 bigint not null,
95  kp3 bigint not null,
96  key kp12(kp0, kp1, kp2, kp3) comment 'rev:x1'
97) engine=rocksdb;
98
99insert into t1 values (1, 1,1,         1,1);
100insert into t1 values (10,1,1,0x12FFFFFFFFFF,1);
101insert into t1 values (11,1,1,0x12FFFFFFFFFF,1);
102insert into t1 values (20,2,2,0x12FFFFFFFFFF,1);
103insert into t1 values (21,2,2,0x12FFFFFFFFFF,1);
104
105--source include/restart_mysqld.inc
106
107--replace_column 10 #
108explain
109select * from t1 where kp0=1 and kp1=1 and kp2=0x12FFFFFFFFFF order by kp3 desc;
110show status like '%rocksdb_bloom_filter_prefix%';
111
112select variable_value into @c from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
113select * from t1 where kp0=1 and kp1=1 and kp2=0x12FFFFFFFFFF order by kp3 desc;
114show status like '%rocksdb_bloom_filter_prefix%';
115--echo # The following MUST show TRUE:
116select case when variable_value-@c = 0 then 'true' else 'false' end from performance_schema.global_status where variable_name='rocksdb_bloom_filter_prefix_checked';
117
118drop table t1;
119# Key length is 4 + 8 + 8 = 20
120