1select ENGINE,COMMENT,TRANSACTIONS,XA,SAVEPOINTS from information_schema.engines where engine = 'rocksdb';
2ENGINE	COMMENT	TRANSACTIONS	XA	SAVEPOINTS
3ROCKSDB	RocksDB storage engine	YES	YES	YES
4drop table if exists t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
5drop table if exists t11,t12,t13,t14,t15,t16,t17,t18,t19,t20;
6drop table if exists t21,t22,t23,t24,t25,t26,t27,t28,t29;
7drop table if exists t30,t31,t32,t33,t34,t35,t36,t37,t38,t39;
8drop table if exists t40,t41,t42,t43,t44,t45,t46,t47,t48,t49;
9SET @ORIG_PAUSE_BACKGROUND_WORK = @@ROCKSDB_PAUSE_BACKGROUND_WORK;
10SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = 1;
11#
12# Issue #1: Don't update indexes if index values have not changed
13#
14create table t1 (
15pk int primary key,
16a int,
17b int,
18key(a)
19) engine=rocksdb;
20insert into t1 values
21(1,1,1), (2,2,2), (3,3,3), (4,4,4);
22set @var1=(select variable_value
23from information_schema.global_status
24where variable_name='rocksdb_number_keys_written');
25# Do an update that doesn't change the key 'a'.
26update t1 set b=3334341 where a=2;
27set @var2=(select variable_value
28from information_schema.global_status
29where variable_name='rocksdb_number_keys_written');
30# The following should produce 1
31select @var2 - @var1;
32@var2 - @var1
331
34# Do an update that sets the key to the same value
35update t1 set a=pk where a=3;
36set @var3=(select variable_value
37from information_schema.global_status
38where variable_name='rocksdb_number_keys_written');
39# We have 'updated' column to the same value, so the following must return 0:
40select @var3 - @var2;
41@var3 - @var2
420
43drop table t1;
44create table t0 (a int primary key) engine=rocksdb;
45show create table t0;
46Table	Create Table
47t0	CREATE TABLE `t0` (
48  `a` int(11) NOT NULL,
49  PRIMARY KEY (`a`)
50) ENGINE=ROCKSDB DEFAULT CHARSET=latin1
51drop table t0;
52create table t1 (a int primary key, b int) engine=rocksdb;
53insert into t1 values (1,1);
54insert into t1 values (2,2);
55select * from t1;
56a	b
571	1
582	2
59# Check that we can create another table and insert there
60create table t2 (a varchar(10) primary key, b varchar(10)) engine=rocksdb;
61insert into t2 value ('abc','def');
62insert into t2 value ('hijkl','mnopq');
63select * from t2;
64a	b
65abc	def
66hijkl	mnopq
67# Select again from t1 to see that records from different tables dont mix
68select * from t1;
69a	b
701	1
712	2
72explain select * from t2 where a='no-such-key';
73id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
741	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE noticed after reading const tables
75explain select * from t2 where a='abc';
76id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
771	SIMPLE	t2	const	PRIMARY	PRIMARY	12	const	#
78select * from t2 where a='abc';
79a	b
80abc	def
81# Try a composite PK
82create table t3 (
83pk1 int,
84pk2 varchar(10),
85col1 varchar(10),
86primary key(pk1, pk2)
87) engine=rocksdb;
88insert into t3 values (2,'two', 'row#2');
89insert into t3 values (3,'three', 'row#3');
90insert into t3 values (1,'one', 'row#1');
91select * from t3;
92pk1	pk2	col1
931	one	row#1
942	two	row#2
953	three	row#3
96select * from t3 where pk1=3 and pk2='three';
97pk1	pk2	col1
983	three	row#3
99drop table t1, t2, t3;
100#
101# Test blob values
102#
103create table t4 (a int primary key, b blob) engine=rocksdb;
104insert into t4 values (1, repeat('quux-quux', 60));
105insert into t4 values (10, repeat('foo-bar', 43));
106insert into t4 values (5, repeat('foo-bar', 200));
107insert into t4 values (2, NULL);
108select
109a,
110(case a
111when 1  then b=repeat('quux-quux', 60)
112when 10 then b=repeat('foo-bar', 43)
113when 5  then b=repeat('foo-bar', 200)
114when 2  then b is null
115else 'IMPOSSIBLE!' end) as CMP
116from t4;
117a	CMP
1181	1
1192	1
1205	1
12110	1
122drop table t4;
123#
124# Test blobs of various sizes
125#
126# TINYBLOB
127create table t5 (a int primary key, b tinyblob) engine=rocksdb;
128insert into t5 values (1, repeat('quux-quux', 6));
129insert into t5 values (10, repeat('foo-bar', 4));
130insert into t5 values (5, repeat('foo-bar', 2));
131select
132a,
133(case a
134when 1  then b=repeat('quux-quux', 6)
135when 10 then b=repeat('foo-bar', 4)
136when 5  then b=repeat('foo-bar', 2)
137else 'IMPOSSIBLE!' end) as CMP
138from t5;
139a	CMP
1401	1
1415	1
14210	1
143drop table t5;
144# MEDIUMBLOB
145create table t6 (a int primary key, b mediumblob) engine=rocksdb;
146insert into t6 values (1, repeat('AB', 65000));
147insert into t6 values (10, repeat('bbb', 40000));
148insert into t6 values (5, repeat('foo-bar', 2));
149select
150a,
151(case a
152when 1  then b=repeat('AB', 65000)
153when 10 then b=repeat('bbb', 40000)
154when 5  then b=repeat('foo-bar', 2)
155else 'IMPOSSIBLE!' end) as CMP
156from t6;
157a	CMP
1581	1
1595	1
16010	1
161drop table t6;
162# LONGBLOB
163create table t7 (a int primary key, b longblob) engine=rocksdb;
164insert into t7 values (1, repeat('AB', 65000));
165insert into t7 values (10, repeat('bbb', 40000));
166insert into t7 values (5, repeat('foo-bar', 2));
167select
168a,
169(case a
170when 1  then b=repeat('AB', 65000)
171when 10 then b=repeat('bbb', 40000)
172when 5  then b=repeat('foo-bar', 2)
173else 'IMPOSSIBLE!' end) as CMP
174from t7;
175a	CMP
1761	1
1775	1
17810	1
179drop table t7;
180#
181# Check if DELETEs work
182#
183create table t8 (a varchar(10) primary key, col1 varchar(12)) engine=rocksdb;
184insert into t8 values
185('one', 'eins'),
186('two', 'zwei'),
187('three', 'drei'),
188('four', 'vier'),
189('five', 'funf');
190# Delete by PK
191explain delete from t8 where a='three';
192id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1931	SIMPLE	t8	range	PRIMARY	PRIMARY	12	NULL	#	Using where
194delete from t8 where a='three';
195select * from t8;
196a	col1
197five	funf
198four	vier
199one	eins
200two	zwei
201# Delete while doing a full table scan
202delete from t8 where col1='eins' or col1='vier';
203select * from t8;
204a	col1
205five	funf
206two	zwei
207# delete w/o WHERE:
208delete from t8;
209select * from t8;
210a	col1
211#
212# Test UPDATEs
213#
214insert into t8 values
215('one', 'eins'),
216('two', 'zwei'),
217('three', 'drei'),
218('four', 'vier'),
219('five', 'funf');
220update t8 set col1='dva' where a='two';
221update t8 set a='fourAAA' where col1='vier';
222select * from t8;
223a	col1
224five	funf
225fourAAA	vier
226one	eins
227three	drei
228two	dva
229delete from t8;
230#
231# Basic transactions tests
232#
233begin;
234insert into t8 values ('trx1-val1', 'data');
235insert into t8 values ('trx1-val2', 'data');
236rollback;
237select * from t8;
238a	col1
239begin;
240insert into t8 values ('trx1-val1', 'data');
241insert into t8 values ('trx1-val2', 'data');
242commit;
243select * from t8;
244a	col1
245trx1-val1	data
246trx1-val2	data
247drop table t8;
248#
249# Check if DROP TABLE works
250#
251create table t8 (a varchar(10) primary key, col1 varchar(12)) engine=rocksdb;
252select * from t8;
253a	col1
254insert into t8 values ('foo','foo');
255drop table t8;
256create table t8 (a varchar(10) primary key, col1 varchar(12)) engine=rocksdb;
257select * from t8;
258a	col1
259drop table t8;
260#
261# MDEV-3961: Assertion ... on creating a TEMPORARY RocksDB table
262#
263CREATE TEMPORARY TABLE t10 (pk INT PRIMARY KEY) ENGINE=RocksDB;
264ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY'
265#
266# MDEV-3963: JOIN or WHERE conditions involving keys on RocksDB tables don't work
267#
268CREATE TABLE t10 (i INT PRIMARY KEY) ENGINE=RocksDB;
269INSERT INTO t10 VALUES (1),(3);
270CREATE TABLE t11 (j INT PRIMARY KEY) ENGINE=RocksDB;
271INSERT INTO t11 VALUES (1),(4);
272select * from t10;
273i
2741
2753
276select * from t11;
277j
2781
2794
280EXPLAIN
281SELECT * FROM t10, t11 WHERE i=j;
282id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2831	SIMPLE	t10	index	PRIMARY	PRIMARY	4	NULL	#	Using index
2841	SIMPLE	t11	eq_ref	PRIMARY	PRIMARY	4	test.t10.i	#	Using index
285SELECT * FROM t10, t11 WHERE i=j;
286i	j
2871	1
288DROP TABLE t10,t11;
289#
290# MDEV-3962: SELECT with ORDER BY causes "ERROR 1030 (HY000): Got error 122
291#
292CREATE TABLE t12 (pk INT PRIMARY KEY) ENGINE=RocksDB;
293INSERT INTO t12 VALUES (2),(1);
294SELECT * FROM t12 ORDER BY pk;
295pk
2961
2972
298DROP TABLE t12;
299#
300# MDEV-3964: Assertion `!pk_descr' fails in ha_rocksdb::open on adding partitions ...
301#
302create table t14 (pk int primary key) engine=RocksDB partition by hash(pk) partitions 2;
303drop table t14;
304#
305# MDEV-3960: Server crashes on running DISCARD TABLESPACE on a RocksDB table
306#
307create table t9 (i int primary key) engine=rocksdb;
308alter table t9 discard tablespace;
309ERROR HY000: Storage engine ROCKSDB of the table `test`.`t9` doesn't have this option
310drop table t9;
311#
312# MDEV-3959: Assertion `slice->size() == table->s->reclength' fails ...
313#   on accessing a table after ALTER
314#
315CREATE TABLE t15 (a INT, rocksdb_pk INT PRIMARY KEY) ENGINE=RocksDB;
316INSERT INTO t15 VALUES (1,1),(5,2);
317ALTER TABLE t15 DROP COLUMN a;
318DROP TABLE t15;
319#
320# MDEV-3968: UPDATE produces a wrong result while modifying a PK on a RocksDB table
321#
322create table t16 (pk int primary key, a char(8)) engine=RocksDB;
323insert into t16 values (1,'a'),(2,'b'),(3,'c'),(4,'d');
324update t16 set pk=100, a = 'updated' where a in ('b','c');
325ERROR 23000: Duplicate entry '100' for key 'PRIMARY'
326select * from t16;
327pk	a
3281	a
3292	b
3303	c
3314	d
332drop table t16;
333#
334# MDEV-3970: A set of assorted crashes on inserting a row into a RocksDB table
335#
336drop table if exists t_very_long_table_name;
337CREATE TABLE `t_very_long_table_name` (
338`c` char(1) NOT NULL,
339`c0` char(0) NOT NULL,
340`c1` char(1) NOT NULL,
341`c20` char(20) NOT NULL,
342`c255` char(255) NOT NULL,
343PRIMARY KEY (`c255`)
344) ENGINE=RocksDB DEFAULT CHARSET=latin1;
345INSERT INTO t_very_long_table_name VALUES ('a', '', 'c', REPEAT('a',20), REPEAT('x',255));
346drop table t_very_long_table_name;
347#
348# Test table locking and read-before-write checks.
349#
350create table t17 (pk varchar(12) primary key, col1 varchar(12)) engine=rocksdb;
351insert into t17 values ('row1', 'val1');
352insert into t17 values ('row1', 'val1-try2');
353ERROR 23000: Duplicate entry 'row1' for key 'PRIMARY'
354insert into t17 values ('ROW1', 'val1-try2');
355ERROR 23000: Duplicate entry 'ROW1' for key 'PRIMARY'
356insert into t17 values ('row2', 'val2');
357insert into t17 values ('row3', 'val3');
358# This is ok
359update t17 set pk='row4' where pk='row1';
360# This will try to overwrite another row:
361update t17 set pk='row3' where pk='row2';
362ERROR 23000: Duplicate entry 'row3' for key 'PRIMARY'
363select * from t17;
364pk	col1
365row2	val2
366row3	val3
367row4	val1
368#
369# Locking tests
370#
371connect  con1,localhost,root,,;
372# First, make sure there's no locking when transactions update different rows
373connection con1;
374set autocommit=0;
375update t17 set col1='UPD1' where pk='row2';
376connection default;
377update t17 set col1='UPD2' where pk='row3';
378connection con1;
379commit;
380connection default;
381select * from t17;
382pk	col1
383row2	UPD1
384row3	UPD2
385row4	val1
386# Check the variable
387show variables like 'rocksdb_lock_wait_timeout';
388Variable_name	Value
389rocksdb_lock_wait_timeout	1
390set rocksdb_lock_wait_timeout=2;
391show variables like 'rocksdb_lock_wait_timeout';
392Variable_name	Value
393rocksdb_lock_wait_timeout	2
394# Try updating the same row from two transactions
395connection con1;
396begin;
397update t17 set col1='UPD2-AA' where pk='row2';
398connection default;
399update t17 set col1='UPD2-BB' where pk='row2';
400ERROR HY000: Lock wait timeout exceeded; try restarting transaction
401set rocksdb_lock_wait_timeout=1000;
402update t17 set col1='UPD2-CC' where pk='row2';
403connection con1;
404rollback;
405connection default;
406select * from t17 where pk='row2';
407pk	col1
408row2	UPD2-CC
409drop table t17;
410disconnect con1;
411#
412#  MDEV-4035: RocksDB: SELECT produces different results inside a transaction (read is not repeatable)
413#
414create table t18 (pk int primary key, i int) engine=RocksDB;
415begin;
416select * from t18;
417pk	i
418select * from t18 where pk = 1;
419pk	i
420connect  con1,localhost,root,,;
421insert into t18 values (1,100);
422connection default;
423select * from t18;
424pk	i
425select * from t18 where pk = 1;
426pk	i
427commit;
428drop table t18;
429#
430# MDEV-4036: RocksDB: INSERT .. ON DUPLICATE KEY UPDATE does not work, produces ER_DUP_KEY
431#
432create table t19 (pk int primary key, i int) engine=RocksDB;
433insert into t19 values (1,1);
434insert into t19 values (1,100) on duplicate key update i = 102;
435select * from t19;
436pk	i
4371	102
438drop table t19;
439# MDEV-4037: RocksDB: REPLACE doesn't work, produces ER_DUP_KEY
440create table t20 (pk int primary key, i int) engine=RocksDB;
441insert into t20 values (1,1);
442replace into t20 values (1,100);
443select * from t20;
444pk	i
4451	100
446drop table t20;
447#
448# MDEV-4041: Server crashes in Primary_key_comparator::get_hashnr on INSERT
449#
450create table t21 (v varbinary(16) primary key, i int) engine=RocksDB;
451insert into t21 values ('a',1);
452select * from t21;
453v	i
454a	1
455drop table t21;
456#
457# MDEV-4047: RocksDB: Assertion `0' fails in Protocol::end_statement() on multi-table INSERT IGNORE
458#
459CREATE TABLE t22 (a int primary key) ENGINE=RocksDB;
460INSERT INTO t22 VALUES (1),(2);
461CREATE TABLE t23 (b int primary key) ENGINE=RocksDB;
462INSERT INTO t23 SELECT * FROM t22;
463DELETE IGNORE t22.*, t23.* FROM t22, t23 WHERE b < a;
464DROP TABLE t22,t23;
465#
466# MDEV-4046: RocksDB: Multi-table DELETE locks itself and ends with ER_LOCK_WAIT_TIMEOUT
467#
468CREATE TABLE t24 (pk int primary key) ENGINE=RocksDB;
469INSERT INTO t24 VALUES (1),(2);
470CREATE TABLE t25 LIKE t24;
471INSERT INTO t25 SELECT * FROM t24;
472DELETE t25.* FROM t24, t25;
473DROP TABLE t24,t25;
474#
475# MDEV-4044: RocksDB: UPDATE or DELETE with ORDER BY locks itself
476#
477create table t26 (pk int primary key, c char(1)) engine=RocksDB;
478insert into t26 values (1,'a'),(2,'b');
479update t26 set c = 'x' order by pk limit 1;
480delete from t26 order by pk limit 1;
481select * from t26;
482pk	c
4832	b
484drop table t26;
485#
486# Test whether SELECT ... FOR UPDATE puts locks
487#
488create table t27(pk varchar(10) primary key, col1 varchar(20)) engine=RocksDB;
489insert into t27 values
490('row1', 'row1data'),
491('row2', 'row2data'),
492('row3', 'row3data');
493connection con1;
494begin;
495select * from t27 where pk='row3' for update;
496pk	col1
497row3	row3data
498connection default;
499set rocksdb_lock_wait_timeout=1;
500update t27 set col1='row2-modified' where pk='row3';
501ERROR HY000: Lock wait timeout exceeded; try restarting transaction
502connection con1;
503rollback;
504connection default;
505disconnect con1;
506drop table t27;
507#
508# MDEV-4060: RocksDB: Assertion `! trx->batch' fails in
509#
510create table t28 (pk int primary key, a int) engine=RocksDB;
511insert into t28 values (1,10),(2,20);
512begin;
513update t28 set a = 100 where pk = 3;
514rollback;
515select * from t28;
516pk	a
5171	10
5182	20
519drop table t28;
520#
521# Secondary indexes
522#
523create table t30 (
524pk varchar(16) not null primary key,
525key1 varchar(16) not null,
526col1 varchar(16) not null,
527key(key1)
528) engine=rocksdb;
529insert into t30 values ('row1', 'row1-key', 'row1-data');
530insert into t30 values ('row2', 'row2-key', 'row2-data');
531insert into t30 values ('row3', 'row3-key', 'row3-data');
532explain
533select * from t30 where key1='row2-key';
534id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5351	SIMPLE	t30	ref	key1	key1	18	const	#	Using index condition
536select * from t30 where key1='row2-key';
537pk	key1	col1
538row2	row2-key	row2-data
539explain
540select * from t30 where key1='row1';
541id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5421	SIMPLE	t30	ref	key1	key1	18	const	#	Using index condition
543# This will produce nothing:
544select * from t30 where key1='row1';
545pk	key1	col1
546explain
547select key1 from t30;
548id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5491	SIMPLE	t30	index	NULL	key1	18	NULL	#	Using index
550select key1 from t30;
551key1
552row1-key
553row2-key
554row3-key
555# Create a duplicate record
556insert into t30 values ('row2a', 'row2-key', 'row2a-data');
557# Can we see it?
558select * from t30 where key1='row2-key';
559pk	key1	col1
560row2	row2-key	row2-data
561row2a	row2-key	row2a-data
562delete from t30 where pk='row2';
563select * from t30 where key1='row2-key';
564pk	key1	col1
565row2a	row2-key	row2a-data
566#
567# Range scans on secondary index
568#
569delete from t30;
570insert into t30 values
571('row1', 'row1-key', 'row1-data'),
572('row2', 'row2-key', 'row2-data'),
573('row3', 'row3-key', 'row3-data'),
574('row4', 'row4-key', 'row4-data'),
575('row5', 'row5-key', 'row5-data');
576explain
577select * from t30 where key1 <='row3-key';
578id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5791	SIMPLE	t30	range	key1	key1	18	NULL	#	Using index condition
580select * from t30 where key1 <='row3-key';
581pk	key1	col1
582row1	row1-key	row1-data
583row2	row2-key	row2-data
584row3	row3-key	row3-data
585explain
586select * from t30 where key1 between 'row2-key' and 'row4-key';
587id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5881	SIMPLE	t30	range	key1	key1	18	NULL	#	Using index condition
589select * from t30 where key1 between 'row2-key' and 'row4-key';
590pk	key1	col1
591row2	row2-key	row2-data
592row3	row3-key	row3-data
593row4	row4-key	row4-data
594explain
595select * from t30 where key1 in ('row2-key','row4-key');
596id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5971	SIMPLE	t30	range	key1	key1	18	NULL	#	Using index condition
598select * from t30 where key1 in ('row2-key','row4-key');
599pk	key1	col1
600row2	row2-key	row2-data
601row4	row4-key	row4-data
602explain
603select key1 from t30 where key1 in ('row2-key','row4-key');
604id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6051	SIMPLE	t30	range	key1	key1	18	NULL	#	Using where; Using index
606select key1 from t30 where key1 in ('row2-key','row4-key');
607key1
608row2-key
609row4-key
610explain
611select * from t30 where key1 > 'row1-key' and key1 < 'row4-key';
612id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6131	SIMPLE	t30	range	key1	key1	18	NULL	#	Using index condition
614select * from t30 where key1 > 'row1-key' and key1 < 'row4-key';
615pk	key1	col1
616row2	row2-key	row2-data
617row3	row3-key	row3-data
618explain
619select * from t30 order by key1 limit 3;
620id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6211	SIMPLE	t30	index	NULL	key1	18	NULL	#
622select * from t30 order by key1 limit 3;
623pk	key1	col1
624row1	row1-key	row1-data
625row2	row2-key	row2-data
626row3	row3-key	row3-data
627explain
628select * from t30 order by key1 desc limit 3;
629id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6301	SIMPLE	t30	index	NULL	key1	18	NULL	#
631select * from t30 order by key1 desc limit 3;
632pk	key1	col1
633row5	row5-key	row5-data
634row4	row4-key	row4-data
635row3	row3-key	row3-data
636#
637# Range scans on primary key
638#
639explain
640select * from t30 where pk <='row3';
641id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6421	SIMPLE	t30	range	PRIMARY	PRIMARY	18	NULL	#	Using where
643select * from t30 where pk <='row3';
644pk	key1	col1
645row1	row1-key	row1-data
646row2	row2-key	row2-data
647row3	row3-key	row3-data
648explain
649select * from t30 where pk between 'row2' and 'row4';
650id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6511	SIMPLE	t30	range	PRIMARY	PRIMARY	18	NULL	#	Using where
652select * from t30 where pk between 'row2' and 'row4';
653pk	key1	col1
654row2	row2-key	row2-data
655row3	row3-key	row3-data
656row4	row4-key	row4-data
657explain
658select * from t30 where pk in ('row2','row4');
659id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6601	SIMPLE	t30	range	PRIMARY	PRIMARY	18	NULL	#	Using where
661select * from t30 where pk in ('row2','row4');
662pk	key1	col1
663row2	row2-key	row2-data
664row4	row4-key	row4-data
665explain
666select * from t30 order by pk limit 3;
667id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6681	SIMPLE	t30	index	NULL	PRIMARY	18	NULL	#
669select * from t30 order by pk limit 3;
670pk	key1	col1
671row1	row1-key	row1-data
672row2	row2-key	row2-data
673row3	row3-key	row3-data
674drop table t30;
675#
676# MDEV-3841: RocksDB: Reading by PK prefix does not work
677#
678create table t31 (i int, j int, k int, primary key(i,j,k)) engine=RocksDB;
679insert into t31 values (1,10,100),(2,20,200);
680select * from t31 where i = 1;
681i	j	k
6821	10	100
683select * from t31 where j = 10;
684i	j	k
6851	10	100
686select * from t31 where k = 100;
687i	j	k
6881	10	100
689select * from t31 where i = 1 and j = 10;
690i	j	k
6911	10	100
692select * from t31 where i = 1 and k = 100;
693i	j	k
6941	10	100
695select * from t31 where j = 10 and k = 100;
696i	j	k
6971	10	100
698select * from t31 where i = 1 and j = 10 and k = 100;
699i	j	k
7001	10	100
701drop table t31;
702#
703# MDEV-4055: RocksDB: UPDATE/DELETE by a multi-part PK does not work
704#
705create table t32 (i int, j int, k int, primary key(i,j,k), a varchar(8)) engine=RocksDB;
706insert into t32 values
707(1,10,100,''),
708(2,20,200,'');
709select * from t32 where i = 1 and j = 10 and k = 100;
710i	j	k	a
7111	10	100
712update t32 set a = 'updated' where i = 1 and j = 10 and k = 100;
713select * from t32;
714i	j	k	a
7151	10	100	updated
7162	20	200
717drop table t32;
718#
719# MDEV-3841: RocksDB: Assertion `0' fails in ha_rocksdb::index_read_map on range select with ORDER BY .. DESC
720#
721CREATE TABLE t33 (pk INT PRIMARY KEY, a CHAR(1)) ENGINE=RocksDB;
722INSERT INTO t33 VALUES (1,'a'),(2,'b');
723SELECT * FROM t33 WHERE pk <= 10 ORDER BY pk DESC;
724pk	a
7252	b
7261	a
727DROP TABLE t33;
728#
729# MDEV-4081: RocksDB throws error 122 on an attempt to create a table with unique index
730#
731#  Unique indexes can be created, but uniqueness won't be enforced
732create table t33 (pk int primary key, u int, unique index(u)) engine=RocksDB;
733drop table t33;
734#
735# MDEV-4077: RocksDB: Wrong result (duplicate row) on select with range
736#
737CREATE TABLE t34 (pk INT PRIMARY KEY) ENGINE=RocksDB;
738INSERT INTO t34 VALUES (10),(11);
739SELECT pk FROM t34 WHERE pk > 5 AND pk < 15;
740pk
74110
74211
743SELECT pk FROM t34 WHERE pk BETWEEN 5 AND 15;
744pk
74510
74611
747SELECT pk FROM t34 WHERE pk > 5;
748pk
74910
75011
751SELECT pk FROM t34 WHERE pk < 15;
752pk
75310
75411
755drop table t34;
756#
757# MDEV-4086: RocksDB does not allow a query with multi-part pk and index and ORDER BY .. DEC
758#
759create table t35 (a int, b int, c int, d int, e int, primary key (a,b,c), key (a,c,d,e)) engine=RocksDB;
760insert into t35 values (1,1,1,1,1),(2,2,2,2,2);
761select * from t35 where a = 1 and c = 1 and d = 1 order by e desc;
762a	b	c	d	e
7631	1	1	1	1
764drop table t35;
765#
766# MDEV-4084: RocksDB: Wrong result on IN subquery with index
767#
768CREATE TABLE t36 (pk INT PRIMARY KEY, a INT, KEY(a)) ENGINE=RocksDB;
769INSERT INTO t36 VALUES (1,10),(2,20);
770SELECT 3 IN ( SELECT a FROM t36 );
7713 IN ( SELECT a FROM t36 )
7720
773drop table t36;
774#
775# MDEV-4084: RocksDB: Wrong result on IN subquery with index
776#
777CREATE TABLE t37 (pk INT PRIMARY KEY, a INT, b CHAR(1), KEY(a), KEY(a,b))
778ENGINE=RocksDB;
779INSERT INTO t37 VALUES (1,10,'x'), (2,20,'y');
780SELECT MAX(a) FROM t37 WHERE a < 100;
781MAX(a)
78220
783DROP TABLE t37;
784#
785# MDEV-4090: RocksDB: Wrong result (duplicate rows) on range access with secondary key and ORDER BY DESC
786#
787CREATE TABLE t38 (pk INT PRIMARY KEY, i INT, KEY(i)) ENGINE=RocksDB;
788INSERT INTO t38 VALUES (1,10), (2,20);
789SELECT i FROM t38 WHERE i NOT IN (8) ORDER BY i DESC;
790i
79120
79210
793drop table t38;
794#
795# MDEV-4092: RocksDB: Assertion `in_table(pa, a_len)' fails in Rdb_key_def::cmp_full_keys
796#            with a multi-part key and ORDER BY .. DESC
797#
798CREATE TABLE t40 (pk1 INT PRIMARY KEY, a INT, b VARCHAR(1), KEY(b,a)) ENGINE=RocksDB;
799INSERT INTO t40 VALUES (1, 7,'x'),(2,8,'y');
800CREATE TABLE t41 (pk2 INT PRIMARY KEY) ENGINE=RocksDB;
801INSERT INTO t41 VALUES (1),(2);
802SELECT * FROM t40, t41 WHERE pk1 = pk2 AND b = 'o' ORDER BY a DESC;
803pk1	a	b	pk2
804DROP TABLE t40,t41;
805#
806# MDEV-4093: RocksDB: IN subquery by secondary key with NULL among values returns true instead of NULL
807#
808CREATE TABLE t42 (pk INT PRIMARY KEY, a INT, KEY(a)) ENGINE=RocksDB;
809INSERT INTO t42 VALUES (1, NULL),(2, 8);
810SELECT ( 3 ) NOT IN ( SELECT a FROM t42 );
811( 3 ) NOT IN ( SELECT a FROM t42 )
812NULL
813DROP TABLE t42;
814#
815# MDEV-4094: RocksDB: Wrong result on SELECT and ER_KEY_NOT_FOUND on
816#            DELETE with search by NULL-able secondary key ...
817#
818CREATE TABLE t43 (pk INT PRIMARY KEY, a INT, b CHAR(1), KEY(a)) ENGINE=RocksDB;
819INSERT INTO t43 VALUES (1,8,'g'),(2,9,'x');
820UPDATE t43 SET pk = 10 WHERE a = 8;
821REPLACE INTO t43 ( a ) VALUES ( 8 );
822Warnings:
823Warning	1364	Field 'pk' doesn't have a default value
824REPLACE INTO t43 ( b ) VALUES ( 'y' );
825Warnings:
826Warning	1364	Field 'pk' doesn't have a default value
827SELECT * FROM t43 WHERE a = 8;
828pk	a	b
82910	8	g
830DELETE FROM t43 WHERE a = 8;
831DROP TABLE t43;
832#
833# Basic AUTO_INCREMENT tests
834#
835create table t44(pk int primary key auto_increment, col1 varchar(12)) engine=rocksdb;
836insert into t44 (col1) values ('row1');
837insert into t44 (col1) values ('row2');
838insert into t44 (col1) values ('row3');
839select * from t44;
840pk	col1
8411	row1
8422	row2
8433	row3
844drop table t44;
845#
846# ALTER TABLE tests
847#
848create table t45 (pk int primary key, col1 varchar(12)) engine=rocksdb;
849insert into t45 values (1, 'row1');
850insert into t45 values (2, 'row2');
851alter table t45 rename t46;
852select * from t46;
853pk	col1
8541	row1
8552	row2
856drop table t46;
857drop table t45;
858ERROR 42S02: Unknown table 'test.t45'
859#
860# Check Bulk loading
861# Bulk loading used to overwrite existing data
862# Now it fails if there is data overlap with what
863# already exists
864#
865show variables
866where
867variable_name like 'rocksdb%' and
868variable_name not like 'rocksdb_max_open_files' and
869variable_name not like 'rocksdb_supported_compression_types';
870Variable_name	Value
871rocksdb_access_hint_on_compaction_start	1
872rocksdb_advise_random_on_open	ON
873rocksdb_allow_concurrent_memtable_write	OFF
874rocksdb_allow_mmap_reads	OFF
875rocksdb_allow_mmap_writes	OFF
876rocksdb_allow_to_start_after_corruption	OFF
877rocksdb_blind_delete_primary_key	OFF
878rocksdb_block_cache_size	536870912
879rocksdb_block_restart_interval	16
880rocksdb_block_size	4096
881rocksdb_block_size_deviation	10
882rocksdb_bulk_load	OFF
883rocksdb_bulk_load_allow_sk	OFF
884rocksdb_bulk_load_allow_unsorted	OFF
885rocksdb_bulk_load_size	1000
886rocksdb_bytes_per_sync	0
887rocksdb_cache_dump	ON
888rocksdb_cache_high_pri_pool_ratio	0.000000
889rocksdb_cache_index_and_filter_blocks	ON
890rocksdb_cache_index_and_filter_with_high_priority	ON
891rocksdb_checksums_pct	100
892rocksdb_collect_sst_properties	ON
893rocksdb_commit_in_the_middle	OFF
894rocksdb_commit_time_batch_for_recovery	ON
895rocksdb_compact_cf
896rocksdb_compaction_readahead_size	0
897rocksdb_compaction_sequential_deletes	0
898rocksdb_compaction_sequential_deletes_count_sd	OFF
899rocksdb_compaction_sequential_deletes_file_size	0
900rocksdb_compaction_sequential_deletes_window	0
901rocksdb_create_checkpoint
902rocksdb_create_if_missing	ON
903rocksdb_create_missing_column_families	OFF
904rocksdb_datadir	./#rocksdb
905rocksdb_db_write_buffer_size	0
906rocksdb_deadlock_detect	OFF
907rocksdb_deadlock_detect_depth	50
908rocksdb_debug_manual_compaction_delay	0
909rocksdb_debug_optimizer_no_zero_cardinality	ON
910rocksdb_debug_ttl_ignore_pk	OFF
911rocksdb_debug_ttl_read_filter_ts	0
912rocksdb_debug_ttl_rec_ts	0
913rocksdb_debug_ttl_snapshot_ts	0
914rocksdb_default_cf_options
915rocksdb_delayed_write_rate	0
916rocksdb_delete_cf
917rocksdb_delete_obsolete_files_period_micros	21600000000
918rocksdb_enable_2pc	ON
919rocksdb_enable_bulk_load_api	ON
920rocksdb_enable_insert_with_update_caching	ON
921rocksdb_enable_thread_tracking	ON
922rocksdb_enable_ttl	ON
923rocksdb_enable_ttl_read_filtering	ON
924rocksdb_enable_write_thread_adaptive_yield	OFF
925rocksdb_error_if_exists	OFF
926rocksdb_error_on_suboptimal_collation	ON
927rocksdb_flush_log_at_trx_commit	0
928rocksdb_force_compute_memtable_stats	ON
929rocksdb_force_compute_memtable_stats_cachetime	0
930rocksdb_force_flush_memtable_and_lzero_now	OFF
931rocksdb_force_flush_memtable_now	OFF
932rocksdb_force_index_records_in_range	0
933rocksdb_git_hash	#
934rocksdb_hash_index_allow_collision	ON
935rocksdb_ignore_datadic_errors	0
936rocksdb_ignore_unknown_options	ON
937rocksdb_index_type	kBinarySearch
938rocksdb_info_log_level	error_level
939rocksdb_io_write_timeout	0
940rocksdb_is_fd_close_on_exec	ON
941rocksdb_keep_log_file_num	1000
942rocksdb_large_prefix	OFF
943rocksdb_lock_scanned_rows	OFF
944rocksdb_lock_wait_timeout	1
945rocksdb_log_file_time_to_roll	0
946rocksdb_manifest_preallocation_size	4194304
947rocksdb_manual_compaction_threads	0
948rocksdb_manual_wal_flush	ON
949rocksdb_master_skip_tx_api	OFF
950rocksdb_max_background_jobs	2
951rocksdb_max_latest_deadlocks	5
952rocksdb_max_log_file_size	0
953rocksdb_max_manifest_file_size	1073741824
954rocksdb_max_manual_compactions	10
955rocksdb_max_row_locks	1048576
956rocksdb_max_subcompactions	1
957rocksdb_max_total_wal_size	0
958rocksdb_merge_buf_size	67108864
959rocksdb_merge_combine_read_size	1073741824
960rocksdb_merge_tmp_file_removal_delay_ms	0
961rocksdb_new_table_reader_for_compaction_inputs	OFF
962rocksdb_no_block_cache	OFF
963rocksdb_override_cf_options
964rocksdb_paranoid_checks	ON
965rocksdb_pause_background_work	ON
966rocksdb_perf_context_level	0
967rocksdb_persistent_cache_path
968rocksdb_persistent_cache_size_mb	0
969rocksdb_pin_l0_filter_and_index_blocks_in_cache	ON
970rocksdb_print_snapshot_conflict_queries	OFF
971rocksdb_rate_limiter_bytes_per_sec	0
972rocksdb_records_in_range	50
973rocksdb_remove_mariabackup_checkpoint	OFF
974rocksdb_reset_stats	OFF
975rocksdb_rollback_on_timeout	OFF
976rocksdb_seconds_between_stat_computes	3600
977rocksdb_signal_drop_index_thread	OFF
978rocksdb_sim_cache_size	0
979rocksdb_skip_bloom_filter_on_read	OFF
980rocksdb_skip_fill_cache	OFF
981rocksdb_skip_unique_check_tables	.*
982rocksdb_sst_mgr_rate_bytes_per_sec	0
983rocksdb_stats_dump_period_sec	600
984rocksdb_stats_level	0
985rocksdb_stats_recalc_rate	0
986rocksdb_store_row_debug_checksums	OFF
987rocksdb_strict_collation_check	OFF
988rocksdb_strict_collation_exceptions
989rocksdb_table_cache_numshardbits	6
990rocksdb_table_stats_sampling_pct	10
991rocksdb_tmpdir
992rocksdb_trace_sst_api	OFF
993rocksdb_two_write_queues	ON
994rocksdb_unsafe_for_binlog	OFF
995rocksdb_update_cf_options
996rocksdb_use_adaptive_mutex	OFF
997rocksdb_use_clock_cache	OFF
998rocksdb_use_direct_io_for_flush_and_compaction	OFF
999rocksdb_use_direct_reads	OFF
1000rocksdb_use_fsync	OFF
1001rocksdb_validate_tables	1
1002rocksdb_verify_row_debug_checksums	OFF
1003rocksdb_wal_bytes_per_sync	0
1004rocksdb_wal_dir
1005rocksdb_wal_recovery_mode	1
1006rocksdb_wal_size_limit_mb	0
1007rocksdb_wal_ttl_seconds	0
1008rocksdb_whole_key_filtering	ON
1009rocksdb_write_batch_max_bytes	0
1010rocksdb_write_disable_wal	OFF
1011rocksdb_write_ignore_missing_column_families	OFF
1012rocksdb_write_policy	write_committed
1013create table t47 (pk int primary key, col1 varchar(12)) engine=rocksdb;
1014insert into t47 values (1, 'row1');
1015insert into t47 values (2, 'row2');
1016set rocksdb_bulk_load=1;
1017insert into t47 values (3, 'row3'),(4, 'row4');
1018set rocksdb_bulk_load=0;
1019connect  con1,localhost,root,,;
1020set rocksdb_bulk_load=1;
1021insert into t47 values (10, 'row10'),(11, 'row11');
1022connection default;
1023set rocksdb_bulk_load=1;
1024insert into t47 values (100, 'row100'),(101, 'row101');
1025disconnect con1;
1026connection default;
1027set rocksdb_bulk_load=0;
1028select * from t47;
1029pk	col1
10301	row1
10312	row2
10323	row3
10334	row4
103410	row10
103511	row11
1036100	row100
1037101	row101
1038drop table t47;
1039#
1040# Fix TRUNCATE over empty table (transaction is committed when it wasn't
1041# started)
1042#
1043create table t48(pk int primary key auto_increment, col1 varchar(12)) engine=rocksdb;
1044set autocommit=0;
1045truncate table t48;
1046set autocommit=1;
1047drop table t48;
1048#
1049# MDEV-4059: RocksDB: query waiting for a lock cannot be killed until query timeout exceeded
1050#
1051create table t49 (pk int primary key, a int) engine=RocksDB;
1052insert into t49 values (1,10),(2,20);
1053begin;
1054update t49 set a = 100 where pk = 1;
1055connect  con1,localhost,root,,;
1056set rocksdb_lock_wait_timeout=60;
1057set @var1= to_seconds(now());
1058update t49 set a = 1000 where pk = 1;
1059connect  con2,localhost,root,,;
1060kill query $con1_id;
1061connection con1;
1062ERROR 70100: Query execution was interrupted
1063set @var2= to_seconds(now());
1064select if ((@var2 - @var1) < 60, "passed", (@var2 - @var1)) as 'result';
1065result
1066passed
1067connection default;
1068disconnect con1;
1069commit;
1070drop table t49;
1071#
1072# Index-only tests for INT-based columns
1073#
1074create table t1 (pk int primary key, key1 int, col1 int, key(key1)) engine=rocksdb;
1075insert into t1 values (1,1,1);
1076insert into t1 values (2,2,2);
1077insert into t1 values (-5,-5,-5);
1078# INT column uses index-only:
1079explain
1080select key1 from t1 where key1=2;
1081id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
10821	SIMPLE	t1	ref	key1	key1	5	const	#	Using index
1083select key1 from t1 where key1=2;
1084key1
10852
1086select key1 from t1 where key1=-5;
1087key1
1088-5
1089drop table t1;
1090create table t2 (pk int primary key, key1 int unsigned, col1 int, key(key1)) engine=rocksdb;
1091insert into t2 values (1,1,1), (2,2,2);
1092# INT UNSIGNED column uses index-only:
1093explain
1094select key1 from t2 where key1=2;
1095id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
10961	SIMPLE	t2	ref	key1	key1	5	const	#	Using index
1097select key1 from t2 where key1=2;
1098key1
10992
1100drop table t2;
1101create table t3 (pk bigint primary key, key1 bigint, col1 int, key(key1)) engine=rocksdb;
1102insert into t3 values (1,1,1), (2,2,2);
1103# BIGINT uses index-only:
1104explain
1105select key1 from t3 where key1=2;
1106id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11071	SIMPLE	t3	ref	key1	key1	9	const	#	Using index
1108select key1 from t3 where key1=2;
1109key1
11102
1111drop table t3;
1112#
1113# Index-only reads for string columns
1114#
1115create table t1 (
1116pk int primary key,
1117key1 char(10) character set binary,
1118col1 int,
1119key (key1)
1120) engine=rocksdb;
1121insert into t1 values(1, 'one',11), (2,'two',22);
1122explain
1123select key1 from t1 where key1='one';
1124id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11251	SIMPLE	t1	ref	key1	key1	11	const	#	Using where; Using index
1126# The following will produce no rows. This looks like a bug,
1127#  but it is actually correct behavior. Binary strings are end-padded
1128#  with \0 character (and not space).  Comparison does not ignore
1129#   the tail of \0.
1130select key1 from t1 where key1='one';
1131key1
1132explain
1133select hex(key1) from t1 where key1='one\0\0\0\0\0\0\0';
1134id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11351	SIMPLE	t1	ref	key1	key1	11	const	#	Using where; Using index
1136select hex(key1) from t1 where key1='one\0\0\0\0\0\0\0';
1137hex(key1)
11386F6E6500000000000000
1139drop table t1;
1140create table t2 (
1141pk int primary key,
1142key1 char(10) collate latin1_bin,
1143col1 int,
1144key (key1)
1145) engine=rocksdb;
1146insert into t2 values(1, 'one',11), (2,'two',22);
1147explain
1148select key1 from t2 where key1='one';
1149id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11501	SIMPLE	t2	ref	key1	key1	11	const	#	Using where; Using index
1151select key1 from t2 where key1='one';
1152key1
1153one
1154drop table t2;
1155create table t3 (
1156pk int primary key,
1157key1 char(10) collate utf8_bin,
1158col1 int,
1159key (key1)
1160) engine=rocksdb;
1161insert into t3 values(1, 'one',11), (2,'two',22);
1162explain
1163select key1 from t3 where key1='one';
1164id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11651	SIMPLE	t3	ref	key1	key1	31	const	#	Using where; Using index
1166select key1 from t3 where key1='one';
1167key1
1168one
1169drop table t3;
1170# a VARCHAR column
1171create table t4 (
1172pk int primary key,
1173key1 varchar(10) collate latin1_bin,
1174key(key1)
1175) engine=rocksdb;
1176insert into t4 values(1, 'one'), (2,'two'),(3,'threee'),(55,'fifty-five');
1177explain
1178select key1 from t4 where key1='two';
1179id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11801	SIMPLE	t4	ref	key1	key1	13	const	#	Using where; Using index
1181select key1 from t4 where key1='two';
1182key1
1183two
1184select key1 from t4 where key1='fifty-five';
1185key1
1186fifty-five
1187explain
1188select key1 from t4 where key1 between 's' and 'u';
1189id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11901	SIMPLE	t4	range	key1	key1	13	NULL	#	Using where; Using index
1191select key1 from t4 where key1 between 's' and 'u';
1192key1
1193threee
1194two
1195drop table t4;
1196#
1197# MDEV-4305: RocksDB: Assertion `((keypart_map + 1) & keypart_map) == 0' fails in calculate_key_len
1198#
1199CREATE TABLE t1 (pk1 INT, pk2 CHAR(32), i INT, PRIMARY KEY(pk1,pk2), KEY(i)) ENGINE=RocksDB;
1200INSERT INTO t1 VALUES (1,'test1',6),(2,'test2',8);
1201SELECT * FROM t1 WHERE i != 3 OR  pk1 > 9;
1202pk1	pk2	i
12031	test1	6
12042	test2	8
1205DROP TABLE t1;
1206#
1207# MDEV-4298: RocksDB: Assertion `thd->is_error() || kill_errno' fails in ha_rows filesort
1208#
1209call mtr.add_suppression("Sort aborted");
1210CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, KEY(i)) ENGINE=RocksDB;
1211INSERT INTO t1 VALUES (1,1),(2,2);
1212BEGIN;
1213UPDATE t1 SET i = 100;
1214connect  con1,localhost,root,,test;
1215DELETE IGNORE FROM t1 ORDER BY i;
1216ERROR HY000: Lock wait timeout exceeded; try restarting transaction
1217disconnect con1;
1218connection default;
1219COMMIT;
1220DROP TABLE t1;
1221#
1222# MDEV-4324: RocksDB: Valgrind "Use of uninitialised value" warnings on inserting value into varchar field
1223#  (testcase only)
1224#
1225CREATE TABLE t1 (pk INT PRIMARY KEY, c VARCHAR(4)) ENGINE=RocksDB;
1226INSERT INTO t1 VALUES (1,'foo'), (2,'bar');
1227DROP TABLE t1;
1228#
1229# MDEV-4304: RocksDB: Index-only scan by a field with utf8_bin collation returns garbage symbols
1230#
1231CREATE TABLE t1 (pk INT PRIMARY KEY, c1 CHAR(1), c2 CHAR(1), KEY(c1)) ENGINE=RocksDB CHARSET utf8 COLLATE utf8_bin;
1232INSERT INTO t1 VALUES (1,'h','h');
1233SELECT * FROM t1;
1234pk	c1	c2
12351	h	h
1236SELECT c1 FROM t1;
1237c1
1238h
1239DROP TABLE t1;
1240#
1241# MDEV-4300: RocksDB: Server crashes in inline_mysql_mutex_lock on SELECT .. FOR UPDATE
1242#
1243CREATE TABLE t2 (pk INT PRIMARY KEY, i INT, KEY (i)) ENGINE=RocksDB;
1244INSERT INTO t2 VALUES (1,4),(2,5);
1245SELECT 1 FROM t2 WHERE i < 0 FOR UPDATE;
12461
1247DROP TABLE t2;
1248#
1249# MDEV-4301: RocksDB: Assertion `pack_info != __null' fails in Rdb_key_def::unpack_record
1250#
1251CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, c CHAR(1), KEY(c,i)) ENGINE=RocksDB;
1252INSERT INTO t1 VALUES (1,4,'d'),(2,8,'e');
1253SELECT MAX( pk ) FROM t1 WHERE i = 105 AND c = 'h';
1254MAX( pk )
1255NULL
1256DROP TABLE t1;
1257#
1258# MDEV-4337: RocksDB: Inconsistent results comparing a char field with an int field
1259#
1260create table t1 (c char(1), i int, primary key(c), key(i)) engine=RocksDB;
1261insert into t1 values ('2',2),('6',6);
1262select * from t1 where c = i;
1263c	i
12642	2
12656	6
1266select * from t1 ignore index (i) where c = i;
1267c	i
12682	2
12696	6
1270drop table t1;
1271#
1272# Test statement rollback inside a transaction
1273#
1274create table t1 (pk varchar(12) primary key) engine=rocksdb;
1275insert into t1 values ('old-val1'),('old-val2');
1276create table t2 (pk varchar(12) primary key) engine=rocksdb;
1277insert into t2 values ('new-val2'),('old-val1');
1278begin;
1279insert into t1 values ('new-val1');
1280insert into t1 select * from t2;
1281ERROR 23000: Duplicate entry 'old-val1' for key 'PRIMARY'
1282commit;
1283select * from t1;
1284pk
1285new-val1
1286old-val1
1287old-val2
1288drop table t1, t2;
1289#
1290# MDEV-4383: RocksDB: Wrong result of DELETE .. ORDER BY .. LIMIT:
1291#   rows that should be deleted remain in the table
1292#
1293CREATE TABLE t2 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=RocksDB;
1294CREATE TABLE t1 (pk INT AUTO_INCREMENT PRIMARY KEY) ENGINE=RocksDB;
1295INSERT INTO t1 (pk) VALUES (NULL),(NULL);
1296BEGIN;
1297INSERT INTO t2 (pk) VALUES (NULL),(NULL);
1298INSERT INTO t1 (pk) VALUES (NULL),(NULL),(NULL),(NULL),(NULL),(NULL);
1299SELECT * FROM t1 ORDER BY pk LIMIT 9;
1300pk
13011
13022
13033
13044
13055
13066
13077
13088
1309affected rows: 8
1310DELETE FROM t1 ORDER BY pk LIMIT 9;
1311affected rows: 8
1312SELECT * FROM t1 ORDER BY pk LIMIT 9;
1313pk
1314affected rows: 0
1315DROP TABLE t1,t2;
1316#
1317# MDEV-4374: RocksDB: Valgrind warnings 'Use of uninitialised value' on
1318#   inserting into a varchar column
1319#
1320CREATE TABLE t1 (pk INT PRIMARY KEY, a VARCHAR(32)) ENGINE=RocksDB;
1321INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
1322DROP TABLE t1;
1323#
1324# MDEV-4061: RocksDB: Changes from an interrupted query are still applied
1325#
1326create table t1 (pk int primary key, a int) engine=RocksDB;
1327insert into t1 values (1,10),(2,20);
1328set autocommit = 1;
1329update t1 set a = sleep(100) where pk = 1;
1330connect  con1,localhost,root,,;
1331kill query $con_id;
1332connection default;
1333ERROR 70100: Query execution was interrupted
1334select * from t1;
1335pk	a
13361	10
13372	20
1338disconnect con1;
1339drop table t1;
1340#
1341# MDEV-4099: RocksDB: Wrong results with index and range access after INSERT IGNORE or REPLACE
1342#
1343CREATE TABLE t1 (pk INT PRIMARY KEY, a SMALLINT, b INT, KEY (a)) ENGINE=RocksDB;
1344INSERT IGNORE INTO t1 VALUES (1, 157, 0), (2, 1898, -504403), (1, -14659,  0);
1345Warnings:
1346Warning	1062	Duplicate entry '1' for key 'PRIMARY'
1347SELECT * FROM t1;
1348pk	a	b
13491	157	0
13502	1898	-504403
1351SELECT pk FROM t1;
1352pk
13531
13542
1355SELECT * FROM t1 WHERE a != 97;
1356pk	a	b
13571	157	0
13582	1898	-504403
1359DROP TABLE t1;
1360#
1361# Test @@rocksdb_max_row_locks
1362#
1363CREATE TABLE t1 (pk INT PRIMARY KEY, a int) ENGINE=RocksDB;
1364set @a=-1;
1365insert into t1 select (@a:=@a+1), 1234 from information_schema.session_variables limit 100;
1366set @tmp1= @@rocksdb_max_row_locks;
1367set rocksdb_max_row_locks= 20;
1368update t1 set a=a+10;
1369ERROR HY000: Got error 10 'Operation aborted: Failed to acquire lock due to rocksdb_max_row_locks limit' from ROCKSDB
1370DROP TABLE t1;
1371#
1372# Test AUTO_INCREMENT behavior problem,
1373#  "explicit insert into an auto-inc column is not noticed by RocksDB"
1374#
1375create table t1 (i int primary key auto_increment) engine=RocksDB;
1376insert into t1 values (null);
1377insert into t1 values (null);
1378select * from t1;
1379i
13801
13812
1382drop table t1;
1383create table t2 (i int primary key auto_increment) engine=RocksDB;
1384insert into t2 values (1);
1385select * from t2;
1386i
13871
1388# this fails (ie. used to fail), RocksDB engine did not notice use of '1' above
1389insert into t2 values (null);
1390select * from t2;
1391i
13921
13932
1394# but then this succeeds, so previous statement must have incremented next number counter
1395insert into t2 values (null);
1396select * from t2;
1397i
13981
13992
14003
1401drop table t2;
1402#
1403# Fix Issue#2: AUTO_INCREMENT value doesn't survive server shutdown
1404#
1405create table t1 (i int primary key auto_increment) engine=RocksDB;
1406insert into t1 values (null);
1407insert into t1 values (null);
1408SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = @ORIG_PAUSE_BACKGROUND_WORK;
1409SET @ORIG_PAUSE_BACKGROUND_WORK = @@ROCKSDB_PAUSE_BACKGROUND_WORK;
1410SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = 1;
1411insert into t1 values (null);
1412select * from t1;
1413i
14141
14152
14163
1417drop table t1;
1418#
1419# Fix Issue #3: SHOW TABLE STATUS shows Auto_increment=0
1420#
1421create table t1 (i int primary key auto_increment) engine=RocksDB;
1422insert into t1 values (null),(null);
1423show table status like 't1';
1424Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment	Max_index_length	Temporary
1425t1	ROCKSDB	10	Fixed	1000	0	#	0	0	0	3	#	#	NULL	latin1_swedish_ci	NULL			0	N
1426drop table t1;
1427#
1428# Fix Issue #4: Crash when using pseudo-unique keys
1429#
1430CREATE TABLE t1 (
1431i INT,
1432t TINYINT,
1433s SMALLINT,
1434m MEDIUMINT,
1435b BIGINT,
1436pk MEDIUMINT AUTO_INCREMENT PRIMARY KEY,
1437UNIQUE KEY b_t (b,t)
1438) ENGINE=rocksdb;
1439INSERT INTO t1 (i,t,s,m,b) VALUES (1,2,3,4,5),(1000,100,10000,1000000,1000000000000000000),(5,100,10000,1000000,100000000000000000),(2,3,4,5,6),(3,4,5,6,7),(101,102,103,104,105),(10001,103,10002,10003,10004),(10,11,12,13,14),(11,12,13,14,15),(12,13,14,15,16);
1440SELECT b+t FROM t1 WHERE (b,t) IN ( SELECT b, t FROM t1 WHERE i>1 ) ORDER BY b+t;
1441b+t
14429
144311
144425
144527
144629
1447207
144810107
1449100000000000000100
14501000000000000000100
1451DROP TABLE t1;
1452#
1453# Fix issue #5: Transaction rollback doesn't undo all changes.
1454#
1455create table t0 (a int) engine=myisam;
1456insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1457create table t1 (id int auto_increment primary key, value int) engine=rocksdb;
1458set autocommit=0;
1459begin;
1460set @a:=0;
1461insert into t1 select @a:=@a+1, @a from t0 A, t0 B, t0 C, t0 D where D.a<4;
1462insert into t1 select @a:=@a+1, @a from t0 A, t0 B, t0 C, t0 D where D.a<4;
1463insert into t1 select @a:=@a+1, @a from t0 A, t0 B, t0 C, t0 D where D.a<4;
1464rollback;
1465select count(*) from t1;
1466count(*)
14670
1468set autocommit=1;
1469drop table t0, t1;
1470#
1471# Check status variables
1472# NOTE: We exclude rocksdb_num_get_for_update_calls because it's a debug only status var
1473#
1474show status where variable_name like 'rocksdb%' and variable_name not like '%num_get_for_update%';
1475Variable_name	Value
1476Rocksdb_rows_deleted	#
1477Rocksdb_rows_inserted	#
1478Rocksdb_rows_read	#
1479Rocksdb_rows_updated	#
1480Rocksdb_rows_deleted_blind	#
1481Rocksdb_rows_expired	#
1482Rocksdb_rows_filtered	#
1483Rocksdb_system_rows_deleted	#
1484Rocksdb_system_rows_inserted	#
1485Rocksdb_system_rows_read	#
1486Rocksdb_system_rows_updated	#
1487Rocksdb_memtable_total	#
1488Rocksdb_memtable_unflushed	#
1489Rocksdb_queries_point	#
1490Rocksdb_queries_range	#
1491Rocksdb_covered_secondary_key_lookups	#
1492Rocksdb_block_cache_add	#
1493Rocksdb_block_cache_add_failures	#
1494Rocksdb_block_cache_bytes_read	#
1495Rocksdb_block_cache_bytes_write	#
1496Rocksdb_block_cache_data_add	#
1497Rocksdb_block_cache_data_bytes_insert	#
1498Rocksdb_block_cache_data_hit	#
1499Rocksdb_block_cache_data_miss	#
1500Rocksdb_block_cache_filter_add	#
1501Rocksdb_block_cache_filter_bytes_evict	#
1502Rocksdb_block_cache_filter_bytes_insert	#
1503Rocksdb_block_cache_filter_hit	#
1504Rocksdb_block_cache_filter_miss	#
1505Rocksdb_block_cache_hit	#
1506Rocksdb_block_cache_index_add	#
1507Rocksdb_block_cache_index_bytes_evict	#
1508Rocksdb_block_cache_index_bytes_insert	#
1509Rocksdb_block_cache_index_hit	#
1510Rocksdb_block_cache_index_miss	#
1511Rocksdb_block_cache_miss	#
1512Rocksdb_block_cachecompressed_hit	#
1513Rocksdb_block_cachecompressed_miss	#
1514Rocksdb_bloom_filter_full_positive	#
1515Rocksdb_bloom_filter_full_true_positive	#
1516Rocksdb_bloom_filter_prefix_checked	#
1517Rocksdb_bloom_filter_prefix_useful	#
1518Rocksdb_bloom_filter_useful	#
1519Rocksdb_bytes_read	#
1520Rocksdb_bytes_written	#
1521Rocksdb_compact_read_bytes	#
1522Rocksdb_compact_write_bytes	#
1523Rocksdb_compaction_key_drop_new	#
1524Rocksdb_compaction_key_drop_obsolete	#
1525Rocksdb_compaction_key_drop_user	#
1526Rocksdb_flush_write_bytes	#
1527Rocksdb_get_hit_l0	#
1528Rocksdb_get_hit_l1	#
1529Rocksdb_get_hit_l2_and_up	#
1530Rocksdb_getupdatessince_calls	#
1531Rocksdb_iter_bytes_read	#
1532Rocksdb_manual_compactions_processed	#
1533Rocksdb_manual_compactions_running	#
1534Rocksdb_memtable_hit	#
1535Rocksdb_memtable_miss	#
1536Rocksdb_no_file_closes	#
1537Rocksdb_no_file_errors	#
1538Rocksdb_no_file_opens	#
1539Rocksdb_num_iterators	#
1540Rocksdb_number_block_not_compressed	#
1541Rocksdb_number_db_next	#
1542Rocksdb_number_db_next_found	#
1543Rocksdb_number_db_prev	#
1544Rocksdb_number_db_prev_found	#
1545Rocksdb_number_db_seek	#
1546Rocksdb_number_db_seek_found	#
1547Rocksdb_number_deletes_filtered	#
1548Rocksdb_number_keys_read	#
1549Rocksdb_number_keys_updated	#
1550Rocksdb_number_keys_written	#
1551Rocksdb_number_merge_failures	#
1552Rocksdb_number_multiget_bytes_read	#
1553Rocksdb_number_multiget_get	#
1554Rocksdb_number_multiget_keys_read	#
1555Rocksdb_number_reseeks_iteration	#
1556Rocksdb_number_sst_entry_delete	#
1557Rocksdb_number_sst_entry_merge	#
1558Rocksdb_number_sst_entry_other	#
1559Rocksdb_number_sst_entry_put	#
1560Rocksdb_number_sst_entry_singledelete	#
1561Rocksdb_number_superversion_acquires	#
1562Rocksdb_number_superversion_cleanups	#
1563Rocksdb_number_superversion_releases	#
1564Rocksdb_row_lock_deadlocks	#
1565Rocksdb_row_lock_wait_timeouts	#
1566Rocksdb_snapshot_conflict_errors	#
1567Rocksdb_stall_l0_file_count_limit_slowdowns	#
1568Rocksdb_stall_locked_l0_file_count_limit_slowdowns	#
1569Rocksdb_stall_l0_file_count_limit_stops	#
1570Rocksdb_stall_locked_l0_file_count_limit_stops	#
1571Rocksdb_stall_pending_compaction_limit_stops	#
1572Rocksdb_stall_pending_compaction_limit_slowdowns	#
1573Rocksdb_stall_memtable_limit_stops	#
1574Rocksdb_stall_memtable_limit_slowdowns	#
1575Rocksdb_stall_total_stops	#
1576Rocksdb_stall_total_slowdowns	#
1577Rocksdb_stall_micros	#
1578Rocksdb_wal_bytes	#
1579Rocksdb_wal_group_syncs	#
1580Rocksdb_wal_synced	#
1581Rocksdb_write_other	#
1582Rocksdb_write_self	#
1583Rocksdb_write_timedout	#
1584Rocksdb_write_wal	#
1585select VARIABLE_NAME from INFORMATION_SCHEMA.global_status where VARIABLE_NAME LIKE 'rocksdb%' and VARIABLE_NAME NOT LIKE '%num_get_for_update%';
1586VARIABLE_NAME
1587ROCKSDB_ROWS_DELETED
1588ROCKSDB_ROWS_INSERTED
1589ROCKSDB_ROWS_READ
1590ROCKSDB_ROWS_UPDATED
1591ROCKSDB_ROWS_DELETED_BLIND
1592ROCKSDB_ROWS_EXPIRED
1593ROCKSDB_ROWS_FILTERED
1594ROCKSDB_SYSTEM_ROWS_DELETED
1595ROCKSDB_SYSTEM_ROWS_INSERTED
1596ROCKSDB_SYSTEM_ROWS_READ
1597ROCKSDB_SYSTEM_ROWS_UPDATED
1598ROCKSDB_MEMTABLE_TOTAL
1599ROCKSDB_MEMTABLE_UNFLUSHED
1600ROCKSDB_QUERIES_POINT
1601ROCKSDB_QUERIES_RANGE
1602ROCKSDB_COVERED_SECONDARY_KEY_LOOKUPS
1603ROCKSDB_BLOCK_CACHE_ADD
1604ROCKSDB_BLOCK_CACHE_ADD_FAILURES
1605ROCKSDB_BLOCK_CACHE_BYTES_READ
1606ROCKSDB_BLOCK_CACHE_BYTES_WRITE
1607ROCKSDB_BLOCK_CACHE_DATA_ADD
1608ROCKSDB_BLOCK_CACHE_DATA_BYTES_INSERT
1609ROCKSDB_BLOCK_CACHE_DATA_HIT
1610ROCKSDB_BLOCK_CACHE_DATA_MISS
1611ROCKSDB_BLOCK_CACHE_FILTER_ADD
1612ROCKSDB_BLOCK_CACHE_FILTER_BYTES_EVICT
1613ROCKSDB_BLOCK_CACHE_FILTER_BYTES_INSERT
1614ROCKSDB_BLOCK_CACHE_FILTER_HIT
1615ROCKSDB_BLOCK_CACHE_FILTER_MISS
1616ROCKSDB_BLOCK_CACHE_HIT
1617ROCKSDB_BLOCK_CACHE_INDEX_ADD
1618ROCKSDB_BLOCK_CACHE_INDEX_BYTES_EVICT
1619ROCKSDB_BLOCK_CACHE_INDEX_BYTES_INSERT
1620ROCKSDB_BLOCK_CACHE_INDEX_HIT
1621ROCKSDB_BLOCK_CACHE_INDEX_MISS
1622ROCKSDB_BLOCK_CACHE_MISS
1623ROCKSDB_BLOCK_CACHECOMPRESSED_HIT
1624ROCKSDB_BLOCK_CACHECOMPRESSED_MISS
1625ROCKSDB_BLOOM_FILTER_FULL_POSITIVE
1626ROCKSDB_BLOOM_FILTER_FULL_TRUE_POSITIVE
1627ROCKSDB_BLOOM_FILTER_PREFIX_CHECKED
1628ROCKSDB_BLOOM_FILTER_PREFIX_USEFUL
1629ROCKSDB_BLOOM_FILTER_USEFUL
1630ROCKSDB_BYTES_READ
1631ROCKSDB_BYTES_WRITTEN
1632ROCKSDB_COMPACT_READ_BYTES
1633ROCKSDB_COMPACT_WRITE_BYTES
1634ROCKSDB_COMPACTION_KEY_DROP_NEW
1635ROCKSDB_COMPACTION_KEY_DROP_OBSOLETE
1636ROCKSDB_COMPACTION_KEY_DROP_USER
1637ROCKSDB_FLUSH_WRITE_BYTES
1638ROCKSDB_GET_HIT_L0
1639ROCKSDB_GET_HIT_L1
1640ROCKSDB_GET_HIT_L2_AND_UP
1641ROCKSDB_GETUPDATESSINCE_CALLS
1642ROCKSDB_ITER_BYTES_READ
1643ROCKSDB_MANUAL_COMPACTIONS_PROCESSED
1644ROCKSDB_MANUAL_COMPACTIONS_RUNNING
1645ROCKSDB_MEMTABLE_HIT
1646ROCKSDB_MEMTABLE_MISS
1647ROCKSDB_NO_FILE_CLOSES
1648ROCKSDB_NO_FILE_ERRORS
1649ROCKSDB_NO_FILE_OPENS
1650ROCKSDB_NUM_ITERATORS
1651ROCKSDB_NUMBER_BLOCK_NOT_COMPRESSED
1652ROCKSDB_NUMBER_DB_NEXT
1653ROCKSDB_NUMBER_DB_NEXT_FOUND
1654ROCKSDB_NUMBER_DB_PREV
1655ROCKSDB_NUMBER_DB_PREV_FOUND
1656ROCKSDB_NUMBER_DB_SEEK
1657ROCKSDB_NUMBER_DB_SEEK_FOUND
1658ROCKSDB_NUMBER_DELETES_FILTERED
1659ROCKSDB_NUMBER_KEYS_READ
1660ROCKSDB_NUMBER_KEYS_UPDATED
1661ROCKSDB_NUMBER_KEYS_WRITTEN
1662ROCKSDB_NUMBER_MERGE_FAILURES
1663ROCKSDB_NUMBER_MULTIGET_BYTES_READ
1664ROCKSDB_NUMBER_MULTIGET_GET
1665ROCKSDB_NUMBER_MULTIGET_KEYS_READ
1666ROCKSDB_NUMBER_RESEEKS_ITERATION
1667ROCKSDB_NUMBER_SST_ENTRY_DELETE
1668ROCKSDB_NUMBER_SST_ENTRY_MERGE
1669ROCKSDB_NUMBER_SST_ENTRY_OTHER
1670ROCKSDB_NUMBER_SST_ENTRY_PUT
1671ROCKSDB_NUMBER_SST_ENTRY_SINGLEDELETE
1672ROCKSDB_NUMBER_SUPERVERSION_ACQUIRES
1673ROCKSDB_NUMBER_SUPERVERSION_CLEANUPS
1674ROCKSDB_NUMBER_SUPERVERSION_RELEASES
1675ROCKSDB_ROW_LOCK_DEADLOCKS
1676ROCKSDB_ROW_LOCK_WAIT_TIMEOUTS
1677ROCKSDB_SNAPSHOT_CONFLICT_ERRORS
1678ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_SLOWDOWNS
1679ROCKSDB_STALL_LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS
1680ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_STOPS
1681ROCKSDB_STALL_LOCKED_L0_FILE_COUNT_LIMIT_STOPS
1682ROCKSDB_STALL_PENDING_COMPACTION_LIMIT_STOPS
1683ROCKSDB_STALL_PENDING_COMPACTION_LIMIT_SLOWDOWNS
1684ROCKSDB_STALL_MEMTABLE_LIMIT_STOPS
1685ROCKSDB_STALL_MEMTABLE_LIMIT_SLOWDOWNS
1686ROCKSDB_STALL_TOTAL_STOPS
1687ROCKSDB_STALL_TOTAL_SLOWDOWNS
1688ROCKSDB_STALL_MICROS
1689ROCKSDB_WAL_BYTES
1690ROCKSDB_WAL_GROUP_SYNCS
1691ROCKSDB_WAL_SYNCED
1692ROCKSDB_WRITE_OTHER
1693ROCKSDB_WRITE_SELF
1694ROCKSDB_WRITE_TIMEDOUT
1695ROCKSDB_WRITE_WAL
1696# RocksDB-SE's status variables are global internally
1697#  but they are shown as both session and global, like InnoDB's status vars.
1698select VARIABLE_NAME from INFORMATION_SCHEMA.session_status where VARIABLE_NAME LIKE 'rocksdb%' and VARIABLE_NAME NOT LIKE '%num_get_for_update%';
1699VARIABLE_NAME
1700ROCKSDB_ROWS_DELETED
1701ROCKSDB_ROWS_INSERTED
1702ROCKSDB_ROWS_READ
1703ROCKSDB_ROWS_UPDATED
1704ROCKSDB_ROWS_DELETED_BLIND
1705ROCKSDB_ROWS_EXPIRED
1706ROCKSDB_ROWS_FILTERED
1707ROCKSDB_SYSTEM_ROWS_DELETED
1708ROCKSDB_SYSTEM_ROWS_INSERTED
1709ROCKSDB_SYSTEM_ROWS_READ
1710ROCKSDB_SYSTEM_ROWS_UPDATED
1711ROCKSDB_MEMTABLE_TOTAL
1712ROCKSDB_MEMTABLE_UNFLUSHED
1713ROCKSDB_QUERIES_POINT
1714ROCKSDB_QUERIES_RANGE
1715ROCKSDB_COVERED_SECONDARY_KEY_LOOKUPS
1716ROCKSDB_BLOCK_CACHE_ADD
1717ROCKSDB_BLOCK_CACHE_ADD_FAILURES
1718ROCKSDB_BLOCK_CACHE_BYTES_READ
1719ROCKSDB_BLOCK_CACHE_BYTES_WRITE
1720ROCKSDB_BLOCK_CACHE_DATA_ADD
1721ROCKSDB_BLOCK_CACHE_DATA_BYTES_INSERT
1722ROCKSDB_BLOCK_CACHE_DATA_HIT
1723ROCKSDB_BLOCK_CACHE_DATA_MISS
1724ROCKSDB_BLOCK_CACHE_FILTER_ADD
1725ROCKSDB_BLOCK_CACHE_FILTER_BYTES_EVICT
1726ROCKSDB_BLOCK_CACHE_FILTER_BYTES_INSERT
1727ROCKSDB_BLOCK_CACHE_FILTER_HIT
1728ROCKSDB_BLOCK_CACHE_FILTER_MISS
1729ROCKSDB_BLOCK_CACHE_HIT
1730ROCKSDB_BLOCK_CACHE_INDEX_ADD
1731ROCKSDB_BLOCK_CACHE_INDEX_BYTES_EVICT
1732ROCKSDB_BLOCK_CACHE_INDEX_BYTES_INSERT
1733ROCKSDB_BLOCK_CACHE_INDEX_HIT
1734ROCKSDB_BLOCK_CACHE_INDEX_MISS
1735ROCKSDB_BLOCK_CACHE_MISS
1736ROCKSDB_BLOCK_CACHECOMPRESSED_HIT
1737ROCKSDB_BLOCK_CACHECOMPRESSED_MISS
1738ROCKSDB_BLOOM_FILTER_FULL_POSITIVE
1739ROCKSDB_BLOOM_FILTER_FULL_TRUE_POSITIVE
1740ROCKSDB_BLOOM_FILTER_PREFIX_CHECKED
1741ROCKSDB_BLOOM_FILTER_PREFIX_USEFUL
1742ROCKSDB_BLOOM_FILTER_USEFUL
1743ROCKSDB_BYTES_READ
1744ROCKSDB_BYTES_WRITTEN
1745ROCKSDB_COMPACT_READ_BYTES
1746ROCKSDB_COMPACT_WRITE_BYTES
1747ROCKSDB_COMPACTION_KEY_DROP_NEW
1748ROCKSDB_COMPACTION_KEY_DROP_OBSOLETE
1749ROCKSDB_COMPACTION_KEY_DROP_USER
1750ROCKSDB_FLUSH_WRITE_BYTES
1751ROCKSDB_GET_HIT_L0
1752ROCKSDB_GET_HIT_L1
1753ROCKSDB_GET_HIT_L2_AND_UP
1754ROCKSDB_GETUPDATESSINCE_CALLS
1755ROCKSDB_ITER_BYTES_READ
1756ROCKSDB_MANUAL_COMPACTIONS_PROCESSED
1757ROCKSDB_MANUAL_COMPACTIONS_RUNNING
1758ROCKSDB_MEMTABLE_HIT
1759ROCKSDB_MEMTABLE_MISS
1760ROCKSDB_NO_FILE_CLOSES
1761ROCKSDB_NO_FILE_ERRORS
1762ROCKSDB_NO_FILE_OPENS
1763ROCKSDB_NUM_ITERATORS
1764ROCKSDB_NUMBER_BLOCK_NOT_COMPRESSED
1765ROCKSDB_NUMBER_DB_NEXT
1766ROCKSDB_NUMBER_DB_NEXT_FOUND
1767ROCKSDB_NUMBER_DB_PREV
1768ROCKSDB_NUMBER_DB_PREV_FOUND
1769ROCKSDB_NUMBER_DB_SEEK
1770ROCKSDB_NUMBER_DB_SEEK_FOUND
1771ROCKSDB_NUMBER_DELETES_FILTERED
1772ROCKSDB_NUMBER_KEYS_READ
1773ROCKSDB_NUMBER_KEYS_UPDATED
1774ROCKSDB_NUMBER_KEYS_WRITTEN
1775ROCKSDB_NUMBER_MERGE_FAILURES
1776ROCKSDB_NUMBER_MULTIGET_BYTES_READ
1777ROCKSDB_NUMBER_MULTIGET_GET
1778ROCKSDB_NUMBER_MULTIGET_KEYS_READ
1779ROCKSDB_NUMBER_RESEEKS_ITERATION
1780ROCKSDB_NUMBER_SST_ENTRY_DELETE
1781ROCKSDB_NUMBER_SST_ENTRY_MERGE
1782ROCKSDB_NUMBER_SST_ENTRY_OTHER
1783ROCKSDB_NUMBER_SST_ENTRY_PUT
1784ROCKSDB_NUMBER_SST_ENTRY_SINGLEDELETE
1785ROCKSDB_NUMBER_SUPERVERSION_ACQUIRES
1786ROCKSDB_NUMBER_SUPERVERSION_CLEANUPS
1787ROCKSDB_NUMBER_SUPERVERSION_RELEASES
1788ROCKSDB_ROW_LOCK_DEADLOCKS
1789ROCKSDB_ROW_LOCK_WAIT_TIMEOUTS
1790ROCKSDB_SNAPSHOT_CONFLICT_ERRORS
1791ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_SLOWDOWNS
1792ROCKSDB_STALL_LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS
1793ROCKSDB_STALL_L0_FILE_COUNT_LIMIT_STOPS
1794ROCKSDB_STALL_LOCKED_L0_FILE_COUNT_LIMIT_STOPS
1795ROCKSDB_STALL_PENDING_COMPACTION_LIMIT_STOPS
1796ROCKSDB_STALL_PENDING_COMPACTION_LIMIT_SLOWDOWNS
1797ROCKSDB_STALL_MEMTABLE_LIMIT_STOPS
1798ROCKSDB_STALL_MEMTABLE_LIMIT_SLOWDOWNS
1799ROCKSDB_STALL_TOTAL_STOPS
1800ROCKSDB_STALL_TOTAL_SLOWDOWNS
1801ROCKSDB_STALL_MICROS
1802ROCKSDB_WAL_BYTES
1803ROCKSDB_WAL_GROUP_SYNCS
1804ROCKSDB_WAL_SYNCED
1805ROCKSDB_WRITE_OTHER
1806ROCKSDB_WRITE_SELF
1807ROCKSDB_WRITE_TIMEDOUT
1808ROCKSDB_WRITE_WAL
1809#
1810# Fix issue #9: HA_ERR_INTERNAL_ERROR when running linkbench
1811#
1812create table t0 (a int) engine=myisam;
1813insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1814create table t1 (
1815pk int primary key,
1816col1 varchar(255),
1817key(col1)
1818) engine=rocksdb;
1819insert into t1 select a, repeat('123456789ABCDEF-', 15) from t0;
1820select * from t1 where pk=3;
1821pk	col1
18223	123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-
1823drop table t0, t1;
1824#
1825# Fix issue #10: Segfault in Rdb_key_def::get_primary_key_tuple
1826#
1827create table t0 (a int) engine=myisam;
1828insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1829CREATE TABLE t1 (
1830id1 bigint(20) unsigned NOT NULL DEFAULT '0',
1831id2 bigint(20) unsigned NOT NULL DEFAULT '0',
1832link_type bigint(20) unsigned NOT NULL DEFAULT '0',
1833visibility tinyint(3) NOT NULL DEFAULT '0',
1834data varchar(255) NOT NULL DEFAULT '',
1835time bigint(20) unsigned NOT NULL DEFAULT '0',
1836version int(11) unsigned NOT NULL DEFAULT '0',
1837PRIMARY KEY (link_type,id1,id2)
1838) engine=rocksdb;
1839insert into t1 select a,a,a,1,a,a,a from t0;
1840alter table t1 add index id1_type (id1,link_type,visibility,time,version,data);
1841select * from t1 where id1 = 3;
1842id1	id2	link_type	visibility	data	time	version
18433	3	3	1	3	3	3
1844drop table t0,t1;
1845#
1846# Test column families
1847#
1848create table t1 (
1849pk int primary key,
1850col1 int,
1851col2 int,
1852key(col1) comment 'cf3',
1853key(col2) comment 'cf4'
1854) engine=rocksdb;
1855insert into t1 values (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5);
1856explain
1857select * from t1 where col1=2;
1858id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
18591	SIMPLE	t1	ref	col1	col1	5	const	#
1860select * from t1 where col1=2;
1861pk	col1	col2
18622	2	2
1863explain
1864select * from t1 where col2=3;
1865id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
18661	SIMPLE	t1	ref	col2	col2	5	const	#
1867select * from t1 where col2=3;
1868pk	col1	col2
18693	3	3
1870select * from t1 where pk=4;
1871pk	col1	col2
18724	4	4
1873drop table t1;
1874#
1875# Try primary key in a non-default CF:
1876#
1877create table t1 (
1878pk int,
1879col1 int,
1880col2 int,
1881key(col1) comment 'cf3',
1882key(col2) comment 'cf4',
1883primary key (pk) comment 'cf5'
1884) engine=rocksdb;
1885insert into t1 values (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5);
1886explain
1887select * from t1 where col1=2;
1888id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
18891	SIMPLE	t1	ref	col1	col1	5	const	#
1890select * from t1 where col1=2;
1891pk	col1	col2
18922	2	2
1893select * from t1 where pk=4;
1894pk	col1	col2
18954	4	4
1896drop table t1;
1897#
1898# Issue #15: SIGSEGV from reading in blob data
1899#
1900CREATE TABLE t1 (
1901id int not null,
1902blob_col text,
1903PRIMARY KEY (id)
1904) ENGINE=ROCKSDB CHARSET=latin1;
1905INSERT INTO t1 SET id=123, blob_col=repeat('z',64000) ON DUPLICATE KEY UPDATE blob_col=VALUES(blob_col);
1906INSERT INTO t1 SET id=123, blob_col=''                ON DUPLICATE KEY UPDATE blob_col=VALUES(blob_col);
1907DROP TABLE t1;
1908#
1909# Issue #17: Automatic per-index column families
1910# (Now deprecated)
1911#
1912create table t1 (
1913id int not null,
1914key1 int,
1915PRIMARY KEY (id),
1916index (key1) comment '$per_index_cf'
1917) engine=rocksdb;
1918ERROR HY000: The per-index column family option has been deprecated
1919#
1920# Issue #22: SELECT ... FOR UPDATE takes a long time
1921#
1922create table t0 (a int) engine=myisam;
1923insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1924create table t1 (
1925id1 int,
1926id2 int,
1927value1 int,
1928value2 int,
1929primary key(id1, id2) COMMENT 'new_column_family',
1930key(id2)
1931) engine=rocksdb default charset=latin1 collate=latin1_bin;
1932insert into t1 select A.a, B.a, 31, 1234 from t0 A, t0 B;
1933explain
1934select * from t1 where id1=30 and value1=30 for update;
1935id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
19361	SIMPLE	t1	ref	PRIMARY	PRIMARY	4	const	#	Using where
1937set @var1=(select variable_value
1938from information_schema.global_status
1939where variable_name='rocksdb_number_keys_read');
1940select * from t1 where id1=3 and value1=3 for update;
1941id1	id2	value1	value2
1942set @var2=(select variable_value
1943from information_schema.global_status
1944where variable_name='rocksdb_number_keys_read');
1945# The following must return true (before the fix, the difference was 70):
1946select if((@var2 - @var1) < 30, 1, @var2-@var1);
1947if((@var2 - @var1) < 30, 1, @var2-@var1)
19481
1949drop table t0,t1;
1950#
1951# Issue #33: SELECT ... FROM rocksdb_table ORDER BY primary_key uses sorting
1952#
1953create table t1 (id int primary key, value int) engine=rocksdb;
1954insert into t1 values (1,1),(2,2),(3,3);
1955# The following must not use 'Using filesort':
1956explain select * from t1 ORDER BY id;
1957id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
19581	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	#
1959drop table t1;
1960#
1961# Issue #26: Index-only scans for DATETIME and TIMESTAMP
1962#
1963create table t0 (a int) engine=myisam;
1964insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1965# Try a DATETIME column:
1966create table t1 (
1967pk int auto_increment primary key,
1968kp1 datetime,
1969kp2 int,
1970col1 int,
1971key(kp1, kp2)
1972) engine=rocksdb;
1973insert into t1 (kp1,kp2)
1974select date_add('2015-01-01 12:34:56', interval a day), a from t0;
1975select * from t1;
1976pk	kp1	kp2	col1
19771	2015-01-01 12:34:56	0	NULL
19782	2015-01-02 12:34:56	1	NULL
19793	2015-01-03 12:34:56	2	NULL
19804	2015-01-04 12:34:56	3	NULL
19815	2015-01-05 12:34:56	4	NULL
19826	2015-01-06 12:34:56	5	NULL
19837	2015-01-07 12:34:56	6	NULL
19848	2015-01-08 12:34:56	7	NULL
19859	2015-01-09 12:34:56	8	NULL
198610	2015-01-10 12:34:56	9	NULL
1987# This must show 'Using index'
1988explain
1989select kp1,kp2 from t1 force index (kp1)
1990where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
1991id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
19921	SIMPLE	t1	range	kp1	kp1	6	NULL	#	Using where; Using index
1993select kp1,kp2 from t1 force index (kp1)
1994where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
1995kp1	kp2
19962015-01-01 12:34:56	0
19972015-01-02 12:34:56	1
19982015-01-03 12:34:56	2
19992015-01-04 12:34:56	3
20002015-01-05 12:34:56	4
2001# Now, the same with NOT NULL column
2002create table t2 (
2003pk int auto_increment primary key,
2004kp1 datetime not null,
2005kp2 int,
2006col1 int,
2007key(kp1, kp2)
2008) engine=rocksdb;
2009insert into t2 select * from t1;
2010# This must show 'Using index'
2011explain
2012select kp1,kp2 from t2 force index (kp1)
2013where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2014id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
20151	SIMPLE	t2	range	kp1	kp1	5	NULL	#	Using where; Using index
2016select kp1,kp2 from t2 force index (kp1)
2017where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2018kp1	kp2
20192015-01-01 12:34:56	0
20202015-01-02 12:34:56	1
20212015-01-03 12:34:56	2
20222015-01-04 12:34:56	3
20232015-01-05 12:34:56	4
2024drop table t1,t2;
2025# Try a DATE column:
2026create table t1 (
2027pk int auto_increment primary key,
2028kp1 date,
2029kp2 int,
2030col1 int,
2031key(kp1, kp2)
2032) engine=rocksdb;
2033insert into t1 (kp1,kp2)
2034select date_add('2015-01-01', interval a day), a from t0;
2035select * from t1;
2036pk	kp1	kp2	col1
20371	2015-01-01	0	NULL
20382	2015-01-02	1	NULL
20393	2015-01-03	2	NULL
20404	2015-01-04	3	NULL
20415	2015-01-05	4	NULL
20426	2015-01-06	5	NULL
20437	2015-01-07	6	NULL
20448	2015-01-08	7	NULL
20459	2015-01-09	8	NULL
204610	2015-01-10	9	NULL
2047# This must show 'Using index'
2048explain
2049select kp1,kp2 from t1 force index (kp1)
2050where kp1 between '2015-01-01' and '2015-01-05';
2051id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
20521	SIMPLE	t1	range	kp1	kp1	4	NULL	#	Using where; Using index
2053select kp1,kp2 from t1 force index (kp1)
2054where kp1 between '2015-01-01' and '2015-01-05';
2055kp1	kp2
20562015-01-01	0
20572015-01-02	1
20582015-01-03	2
20592015-01-04	3
20602015-01-05	4
2061# Now, the same with NOT NULL column
2062create table t2 (
2063pk int auto_increment primary key,
2064kp1 date not null,
2065kp2 int,
2066col1 int,
2067key(kp1, kp2)
2068) engine=rocksdb;
2069insert into t2 select * from t1;
2070# This must show 'Using index'
2071explain
2072select kp1,kp2 from t2 force index (kp1)
2073where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2074id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
20751	SIMPLE	t2	range	kp1	kp1	3	NULL	#	Using where; Using index
2076select kp1,kp2 from t2 force index (kp1)
2077where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2078kp1	kp2
20792015-01-01	0
20802015-01-02	1
20812015-01-03	2
20822015-01-04	3
20832015-01-05	4
2084drop table t1,t2;
2085#
2086# Try a TIMESTAMP column:
2087#
2088create table t1 (
2089pk int auto_increment primary key,
2090kp1 timestamp,
2091kp2 int,
2092col1 int,
2093key(kp1, kp2)
2094) engine=rocksdb;
2095insert into t1 (kp1,kp2)
2096select date_add('2015-01-01 12:34:56', interval a day), a from t0;
2097select * from t1;
2098pk	kp1	kp2	col1
20991	2015-01-01 12:34:56	0	NULL
21002	2015-01-02 12:34:56	1	NULL
21013	2015-01-03 12:34:56	2	NULL
21024	2015-01-04 12:34:56	3	NULL
21035	2015-01-05 12:34:56	4	NULL
21046	2015-01-06 12:34:56	5	NULL
21057	2015-01-07 12:34:56	6	NULL
21068	2015-01-08 12:34:56	7	NULL
21079	2015-01-09 12:34:56	8	NULL
210810	2015-01-10 12:34:56	9	NULL
2109# This must show 'Using index'
2110explain
2111select kp1,kp2 from t1 force index (kp1)
2112where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2113id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
21141	SIMPLE	t1	range	kp1	kp1	5	NULL	#	Using where; Using index
2115select kp1,kp2 from t1 force index (kp1)
2116where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2117kp1	kp2
21182015-01-01 12:34:56	0
21192015-01-02 12:34:56	1
21202015-01-03 12:34:56	2
21212015-01-04 12:34:56	3
21222015-01-05 12:34:56	4
2123# Now, the same with NOT NULL column
2124create table t2 (
2125pk int auto_increment primary key,
2126kp1 timestamp not null,
2127kp2 int,
2128col1 int,
2129key(kp1, kp2)
2130) engine=rocksdb;
2131insert into t2 select * from t1;
2132# This must show 'Using index'
2133explain
2134select kp1,kp2 from t2 force index (kp1)
2135where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2136id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
21371	SIMPLE	t2	range	kp1	kp1	4	NULL	#	Using where; Using index
2138select kp1,kp2 from t2 force index (kp1)
2139where kp1 between '2015-01-01 00:00:00' and '2015-01-05 23:59:59';
2140kp1	kp2
21412015-01-01 12:34:56	0
21422015-01-02 12:34:56	1
21432015-01-03 12:34:56	2
21442015-01-04 12:34:56	3
21452015-01-05 12:34:56	4
2146drop table t1,t2;
2147#
2148# Try a TIME column:
2149#
2150create table t1 (
2151pk int auto_increment primary key,
2152kp1 time,
2153kp2 int,
2154col1 int,
2155key(kp1, kp2)
2156) engine=rocksdb;
2157insert into t1 (kp1,kp2)
2158select date_add('2015-01-01 09:00:00', interval a minute), a from t0;
2159select * from t1;
2160pk	kp1	kp2	col1
21611	09:00:00	0	NULL
21622	09:01:00	1	NULL
21633	09:02:00	2	NULL
21644	09:03:00	3	NULL
21655	09:04:00	4	NULL
21666	09:05:00	5	NULL
21677	09:06:00	6	NULL
21688	09:07:00	7	NULL
21699	09:08:00	8	NULL
217010	09:09:00	9	NULL
2171# This must show 'Using index'
2172explain
2173select kp1,kp2 from t1 force index (kp1)
2174where kp1 between '09:01:00' and '09:05:00';
2175id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
21761	SIMPLE	t1	range	kp1	kp1	4	NULL	#	Using where; Using index
2177select kp1,kp2 from t1 force index (kp1)
2178where kp1 between '09:01:00' and '09:05:00';
2179kp1	kp2
218009:01:00	1
218109:02:00	2
218209:03:00	3
218309:04:00	4
218409:05:00	5
2185# Now, the same with NOT NULL column
2186create table t2 (
2187pk int auto_increment primary key,
2188kp1 time not null,
2189kp2 int,
2190col1 int,
2191key(kp1, kp2)
2192) engine=rocksdb;
2193insert into t2 select * from t1;
2194# This must show 'Using index'
2195explain
2196select kp1,kp2 from t2 force index (kp1)
2197where kp1 between '09:01:00' and '09:05:00';
2198id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
21991	SIMPLE	t2	range	kp1	kp1	3	NULL	#	Using where; Using index
2200select kp1,kp2 from t2 force index (kp1)
2201where kp1 between '09:01:00' and '09:05:00';
2202kp1	kp2
220309:01:00	1
220409:02:00	2
220509:03:00	3
220609:04:00	4
220709:05:00	5
2208drop table t1,t2;
2209#
2210# Try a YEAR column:
2211#
2212create table t1 (
2213pk int auto_increment primary key,
2214kp1 year,
2215kp2 int,
2216col1 int,
2217key(kp1, kp2)
2218) engine=rocksdb;
2219insert into t1 (kp1,kp2) select 2015+a, a from t0;
2220select * from t1;
2221pk	kp1	kp2	col1
22221	2015	0	NULL
22232	2016	1	NULL
22243	2017	2	NULL
22254	2018	3	NULL
22265	2019	4	NULL
22276	2020	5	NULL
22287	2021	6	NULL
22298	2022	7	NULL
22309	2023	8	NULL
223110	2024	9	NULL
2232# This must show 'Using index'
2233explain
2234select kp1,kp2 from t1 force index (kp1)
2235where kp1 between '2016' and '2020';
2236id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
22371	SIMPLE	t1	range	kp1	kp1	2	NULL	#	Using where; Using index
2238select kp1,kp2 from t1 force index (kp1)
2239where kp1 between '2016' and '2020';
2240kp1	kp2
22412016	1
22422017	2
22432018	3
22442019	4
22452020	5
2246# Now, the same with NOT NULL column
2247create table t2 (
2248pk int auto_increment primary key,
2249kp1 year not null,
2250kp2 int,
2251col1 int,
2252key(kp1, kp2)
2253) engine=rocksdb;
2254insert into t2 select * from t1;
2255# This must show 'Using index'
2256explain
2257select kp1,kp2 from t2 force index (kp1)
2258where kp1 between '2016' and '2020';
2259id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
22601	SIMPLE	t2	range	kp1	kp1	1	NULL	#	Using where; Using index
2261select kp1,kp2 from t2 force index (kp1)
2262where kp1 between '2016' and '2020';
2263kp1	kp2
22642016	1
22652017	2
22662018	3
22672019	4
22682020	5
2269drop table t1,t2;
2270#
2271# Issue #57: Release row locks on statement errors
2272#
2273create table t1 (id int primary key) engine=rocksdb;
2274insert into t1 values (1), (2), (3);
2275begin;
2276insert into t1 values (4), (5), (6);
2277insert into t1 values (7), (8), (2), (9);
2278ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
2279select * from t1;
2280id
22811
22822
22833
22844
22855
22866
2287begin;
2288select * from t1 where id=4 for update;
2289ERROR HY000: Lock wait timeout exceeded; try restarting transaction
2290select * from t1 where id=7 for update;
2291id
2292select * from t1 where id=9 for update;
2293id
2294drop table t1;
2295#Index on blob column
2296SET @old_mode = @@sql_mode;
2297SET sql_mode = 'strict_all_tables';
2298create table t1 (a int, b text, c varchar(400), Primary Key(a), Key(c, b(255))) engine=rocksdb;
2299drop table t1;
2300set global rocksdb_large_prefix=1;
2301create table t1 (a int, b text, c varchar(400), Primary Key(a), Key(b(1255))) engine=rocksdb;
2302set global rocksdb_large_prefix=0;
2303insert into t1 values (1, '1abcde', '1abcde'), (2, '2abcde', '2abcde'), (3, '3abcde', '3abcde');
2304select * from t1;
2305a	b	c
23061	1abcde	1abcde
23072	2abcde	2abcde
23083	3abcde	3abcde
2309explain select * from t1 where b like '1%';
2310id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
23111	SIMPLE	t1	range	b	b	1258	NULL	#	Using where
2312explain select b, a from t1 where b like '1%';
2313id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
23141	SIMPLE	t1	range	b	b	1258	NULL	#	Using where
2315update t1 set b= '12345' where b = '2abcde';
2316select * from t1;
2317a	b	c
23181	1abcde	1abcde
23192	12345	2abcde
23203	3abcde	3abcde
2321drop table t1;
2322create table t1 (a int, b text, c varchar(400), Primary Key(a), Key(b(2255))) engine=rocksdb;
2323Warnings:
2324Note	1071	Specified key was too long; max key length is 767 bytes
2325drop table t1;
2326SET sql_mode = @old_mode;
2327drop table t0;
2328#
2329# Fix assertion failure (attempt to overrun the key buffer) for prefix indexes
2330#
2331create table t1 (
2332pk int primary key,
2333col1 varchar(100),
2334key (col1(10))
2335) engine=rocksdb;
2336insert into t1 values (1, repeat('0123456789', 9));
2337drop table t1;
2338#
2339# Issue #76: Assertion `buf == table->record[0]' fails in virtual int ha_rocksdb::delete_row(const uchar*)
2340#
2341CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT) ENGINE=RocksDB;
2342CREATE TABLE t2 (pk INT PRIMARY KEY, f1 INT) ENGINE=RocksDB;
2343CREATE TRIGGER tr AFTER DELETE ON t1 FOR EACH ROW DELETE FROM t2 WHERE pk = old.pk;
2344INSERT INTO t1 VALUES (1,1);
2345REPLACE INTO t1 VALUES (1,2);
2346SELECT * FROM t1;
2347pk	f1
23481	2
2349DROP TABLE t1, t2;
2350#
2351# Issue #99: UPDATE for table with VARCHAR pk gives "Can't find record" error
2352#
2353create table t1(a int primary key);
2354insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
2355create table t2 (
2356a varchar(32) primary key,
2357col1 int
2358) engine=rocksdb;
2359insert into t2
2360select concat('v-', 100 + A.a*100 + B.a), 12345 from t1 A, t1 B;
2361update t2 set a=concat('x-', a) where a between 'v-1002' and 'v-1004';
2362drop table t1,t2;
2363#
2364# Issue #131: Assertion `v->cfd_->internal_comparator().Compare(start, end) <= 0' failed
2365#
2366CREATE TABLE t2(c1 INTEGER UNSIGNED NOT NULL, c2 INTEGER NULL, c3 TINYINT, c4 SMALLINT , c5 MEDIUMINT, c6 INT, c7 BIGINT, PRIMARY KEY(c1,c6)) ENGINE=RocksDB;
2367INSERT INTO t2 VALUES (1,1,1,1,1,1,1);
2368SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6;
2369c1	c2	c3	c4	c5	c6	c7
2370EXPLAIN SELECT * FROM t2 WHERE c1 > 4294967295 ORDER BY c1,c6;
2371id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
23721	SIMPLE	t2	range	PRIMARY	PRIMARY	4	NULL	50	Using where
2373drop table t2;
2374#
2375# Issue #135: register transaction was not being called for statement
2376#
2377DROP DATABASE IF EXISTS test_db;
2378CREATE DATABASE test_db;
2379CREATE TABLE test_db.t1(c1 INT PRIMARY KEY);
2380LOCK TABLES test_db.t1 READ;
2381SET AUTOCOMMIT=0;
2382SELECT c1 FROM test_db.t1;
2383c1
2384START TRANSACTION WITH CONSISTENT SNAPSHOT, READ ONLY;
2385DROP DATABASE test_db;
2386#
2387# Issue #143: Split rocksdb_bulk_load option into two
2388#
2389CREATE TABLE t1 (id int primary key, value int) engine=RocksDB;
2390SET unique_checks=0;
2391INSERT INTO t1 VALUES(1, 1);
2392INSERT INTO t1 VALUES(1, 2);
2393INSERT INTO t1 VALUES(1, 3);
2394SELECT * FROM t1;
2395id	value
23961	3
2397REPLACE INTO t1 VALUES(4, 4);
2398ERROR HY000: When unique checking is disabled in MyRocks, INSERT,UPDATE,LOAD statements with clauses that update or replace the key (i.e. INSERT ON DUPLICATE KEY UPDATE, REPLACE) are not allowed. Query: REPLACE INTO t1 VALUES(4, 4)
2399INSERT INTO t1 VALUES(5, 5) ON DUPLICATE KEY UPDATE value=value+1;
2400ERROR HY000: When unique checking is disabled in MyRocks, INSERT,UPDATE,LOAD statements with clauses that update or replace the key (i.e. INSERT ON DUPLICATE KEY UPDATE, REPLACE) are not allowed. Query: INSERT INTO t1 VALUES(5, 5) ON DUPLICATE KEY UPDATE value=value+1
2401TRUNCATE TABLE t1;
2402SET @save_rocksdb_bulk_load_size= @@rocksdb_bulk_load_size;
2403SET unique_checks=1;
2404SET rocksdb_commit_in_the_middle=1;
2405SET rocksdb_bulk_load_size=10;
2406BEGIN;
2407INSERT INTO t1 (id) VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),
2408(11),(12),(13),(14),(15),(16),(17),(18),(19);
2409ROLLBACK;
2410SELECT * FROM t1;
2411id	value
24121	NULL
24132	NULL
24143	NULL
24154	NULL
24165	NULL
24176	NULL
24187	NULL
24198	NULL
24209	NULL
242110	NULL
2422INSERT INTO t1 (id) VALUES (11),(12),(13),(14),(15);
2423BEGIN;
2424UPDATE t1 SET value=100;
2425ROLLBACK;
2426SELECT * FROM t1;
2427id	value
24281	100
24292	100
24303	100
24314	100
24325	100
24336	100
24347	100
24358	100
24369	100
243710	100
243811	NULL
243912	NULL
244013	NULL
244114	NULL
244215	NULL
2443BEGIN;
2444DELETE FROM t1;
2445ROLLBACK;
2446SELECT * FROM t1;
2447id	value
244811	NULL
244912	NULL
245013	NULL
245114	NULL
245215	NULL
2453SET rocksdb_commit_in_the_middle=0;
2454SET rocksdb_bulk_load_size= @save_rocksdb_bulk_load_size;
2455DROP TABLE t1;
2456#
2457# Issue #185 Assertion `BaseValid()' failed in void rocksdb::BaseDeltaIterator::Advance()
2458#
2459CREATE TABLE t2(id INT NOT NULL PRIMARY KEY, data INT) Engine=MEMORY;
2460INSERT INTO t2 VALUES (100,NULL),(150,"long varchar"),(200,"varchar"),(250,"long long long varchar");
2461Warnings:
2462Warning	1366	Incorrect integer value: 'long varchar' for column `test`.`t2`.`data` at row 2
2463Warning	1366	Incorrect integer value: 'varchar' for column `test`.`t2`.`data` at row 3
2464Warning	1366	Incorrect integer value: 'long long long varchar' for column `test`.`t2`.`data` at row 4
2465create TABLE t1 (a int not null, b int not null, primary key(a,b));
2466INSERT INTO t1  VALUES (1,1);
2467SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4));
2468a
24691
24701
24711
24721
2473DROP TABLE t1, t2;
2474#
2475# Issue #189 ha_rocksdb::load_auto_incr_value() creates implicit snapshot and doesn't release
2476#
2477create table r1 (id int auto_increment primary key, value int);
2478insert into r1 (id) values (null), (null), (null), (null), (null);
2479create table r2 like r1;
2480show create table r2;
2481Table	Create Table
2482r2	CREATE TABLE `r2` (
2483  `id` int(11) NOT NULL AUTO_INCREMENT,
2484  `value` int(11) DEFAULT NULL,
2485  PRIMARY KEY (`id`)
2486) ENGINE=ROCKSDB DEFAULT CHARSET=latin1
2487begin;
2488insert into r1 values (10, 1);
2489commit;
2490begin;
2491select * from r1;
2492id	value
24931	NULL
24942	NULL
24953	NULL
24964	NULL
24975	NULL
249810	1
2499commit;
2500drop table r1, r2;
2501create table r1 (id int auto_increment, value int, index i(id));
2502insert into r1 (id) values (null), (null), (null), (null), (null);
2503create table r2 like r1;
2504show create table r2;
2505Table	Create Table
2506r2	CREATE TABLE `r2` (
2507  `id` int(11) NOT NULL AUTO_INCREMENT,
2508  `value` int(11) DEFAULT NULL,
2509  KEY `i` (`id`)
2510) ENGINE=ROCKSDB DEFAULT CHARSET=latin1
2511begin;
2512insert into r1 values (10, 1);
2513commit;
2514begin;
2515select * from r1;
2516id	value
25171	NULL
25182	NULL
25193	NULL
25204	NULL
25215	NULL
252210	1
2523commit;
2524drop table r1, r2;
2525#
2526# Issue#211 Crash on LOCK TABLES + START TRANSACTION WITH CONSISTENT SNAPSHOT
2527#
2528CREATE TABLE t1(c1 INT);
2529lock TABLE t1 read local;
2530SELECT 1 FROM t1 GROUP BY TRIM(LEADING RAND()FROM'');
25311
2532set AUTOCOMMIT=0;
2533start transaction with consistent snapshot;
2534SELECT * FROM t1;
2535c1
2536COMMIT;
2537UNLOCK TABLES;
2538DROP TABLE t1;
2539#
2540# Issue#213 Crash on LOCK TABLES + partitions
2541#
2542CREATE TABLE t1(a INT,b INT,KEY (b)) engine=rocksdb PARTITION BY HASH(a) PARTITIONS 2;
2543INSERT INTO t1(a)VALUES (20010101101010.999949);
2544Warnings:
2545Warning	1264	Out of range value for column 'a' at row 1
2546lock tables t1 write,t1 as t0 write,t1 as t2 write;
2547SELECT a FROM t1 ORDER BY a;
2548a
25492147483647
2550truncate t1;
2551INSERT INTO t1 VALUES(X'042000200020',X'042000200020'),(X'200400200020',X'200400200020');
2552Warnings:
2553Warning	1366	Incorrect integer value: '\x04 \x00 \x00 ' for column `test`.`t1`.`a` at row 1
2554Warning	1366	Incorrect integer value: '\x04 \x00 \x00 ' for column `test`.`t1`.`b` at row 1
2555Warning	1366	Incorrect integer value: ' \x04\x00 \x00 ' for column `test`.`t1`.`a` at row 2
2556Warning	1366	Incorrect integer value: ' \x04\x00 \x00 ' for column `test`.`t1`.`b` at row 2
2557UNLOCK TABLES;
2558DROP TABLE t1;
2559#
2560# Issue#250: MyRocks/Innodb different output from query with order by on table with index and decimal type
2561#  (the test was changed to use VARCHAR, because DECIMAL now supports index-only, and this issue
2562#   needs a datype that doesn't support index-inly)
2563#
2564CREATE TABLE t1(
2565c1 varchar(10) character set utf8 collate utf8_general_ci NOT NULL,
2566c2 varchar(10) character set utf8 collate utf8_general_ci,
2567c3 INT,
2568INDEX idx(c1,c2)
2569);
2570INSERT INTO t1 VALUES ('c1-val1','c2-val1',5);
2571INSERT INTO t1 VALUES ('c1-val2','c2-val3',6);
2572INSERT INTO t1 VALUES ('c1-val3','c2-val3',7);
2573SELECT * FROM t1 force index(idx) WHERE c1 <> 'c1-val2' ORDER BY c1 DESC;
2574c1	c2	c3
2575c1-val3	c2-val3	7
2576c1-val1	c2-val1	5
2577explain SELECT * FROM t1  force index(idx) WHERE c1 <> '1' ORDER BY c1 DESC;
2578id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
25791	SIMPLE	t1	range	idx	idx	32	NULL	#	Using where
2580drop table t1;
2581#
2582# Issue#267: MyRocks issue with no matching min/max row and count(*)
2583#
2584CREATE TABLE t1(c1 INT UNSIGNED, c2 INT SIGNED, INDEX idx2(c2));
2585INSERT INTO t1 VALUES(1,null);
2586INSERT INTO t1 VALUES(2,null);
2587SELECT count(*) as total_rows, min(c2) as min_value FROM t1;
2588total_rows	min_value
25892	NULL
2590DROP TABLE t1;
2591#
2592# Issue#263: MyRocks auto_increment skips values if you insert a negative value
2593#
2594CREATE TABLE t1(a INT AUTO_INCREMENT KEY);
2595INSERT INTO t1 VALUES(0),(-1),(0);
2596SHOW TABLE STATUS LIKE 't1';
2597Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment	Max_index_length	Temporary
2598t1	ROCKSDB	10	Fixed	1000	0	0	0	0	0	3	#	#	NULL	latin1_swedish_ci	NULL			0	N
2599SELECT * FROM t1;
2600a
2601-1
26021
26032
2604DROP TABLE t1;
2605CREATE TABLE t1(a INT AUTO_INCREMENT KEY);
2606INSERT INTO t1 VALUES(0),(10),(0);
2607SHOW TABLE STATUS LIKE 't1';
2608Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment	Max_index_length	Temporary
2609t1	ROCKSDB	10	Fixed	1000	0	0	0	0	0	12	#	#	NULL	latin1_swedish_ci	NULL			0	N
2610SELECT * FROM t1;
2611a
26121
261310
261411
2615DROP TABLE t1;
2616#
2617# Issue #411: Setting rocksdb_commit_in_the_middle commits transaction
2618# without releasing iterator
2619#
2620CREATE TABLE t1 (id1 bigint(20),
2621id2 bigint(20),
2622id3 bigint(20),
2623PRIMARY KEY (id1, id2, id3))
2624DEFAULT CHARSET=latin1;
2625CREATE TABLE t2 (id1 bigint(20),
2626id2 bigint(20),
2627PRIMARY KEY (id1, id2))
2628DEFAULT CHARSET=latin1;
2629set rocksdb_commit_in_the_middle=1;
2630SET @save_rocksdb_bulk_load_size= @@rocksdb_bulk_load_size;
2631set rocksdb_bulk_load_size = 100;
2632DELETE t2, t1 FROM t2 LEFT JOIN t1 ON t2.id2 = t1.id2 AND t2.id1 = t1.id1 WHERE t2.id1 = 0;
2633SET rocksdb_bulk_load_size= @save_rocksdb_bulk_load_size;
2634SET rocksdb_commit_in_the_middle=0;
2635DROP TABLE t1, t2;
2636SET GLOBAL ROCKSDB_PAUSE_BACKGROUND_WORK = @ORIG_PAUSE_BACKGROUND_WORK;
2637