summaryrefslogtreecommitdiff
path: root/storage/rocksdb/mysql-test/rocksdb/r/type_varchar.result
blob: 4c5ef47590a5cba0f90f339d46b420cef76b728c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
#
# A basic test whether endspace-aware variable length encoding 
# works when in PK
#
create table t1 ( pk varchar(10) primary key, col1 int not null) ;
insert into t1 values ('a', 1);
select * from t1;
pk	col1
a	1
drop table t1;
DROP TABLE IF EXISTS t1, t2;
CREATE TABLE t1 (
v0 VARCHAR(0) ,
v1 VARCHAR(1) ,
v64 VARCHAR(64) ,
v65000 VARCHAR(65000) ,
PRIMARY KEY (v64)
) ENGINE=rocksdb;
SHOW COLUMNS IN t1;
Field	Type	Null	Key	Default	Extra
v0	varchar(0)	YES		NULL	
v1	varchar(1)	YES		NULL	
v64	varchar(64)	NO	PRI	NULL	
v65000	varchar(65000)	YES		NULL	
CREATE TABLE t2 (v VARCHAR(65532), PRIMARY KEY (v(255))) ENGINE=rocksdb;
SHOW COLUMNS IN t2;
Field	Type	Null	Key	Default	Extra
v	varchar(65532)	NO	PRI	NULL	
INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','','','');
INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('','y','Once there, double check that an article doesn\'t already exist','Here is a list of recommended books on MariaDB and MySQL. We\'ve provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off.

  If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment.
  For developers who want to code on MariaDB or MySQL

      * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB.
            o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB!
            o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. 
      * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings
            o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! 

  For MariaDB / MySQL end users

      * MariaDB Crash Course by Ben Forta
            o First MariaDB book!
            o For people who want to learn SQL and the basics of MariaDB.
            o Now shipping. Purchase at Amazon.com or your favorite bookseller. 

      * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer.
            o Everything you wanted to know about the SQL 99 standard. Excellent reference book!
            o Free to read in the Knowledgebase! 

      * MySQL (4th Edition) by Paul DuBois
            o The \'default\' book to read if you wont to learn to use MySQL / MariaDB. 

      * MySQL Cookbook by Paul DuBois
            o A lot of examples of how to use MySQL. As with all of Paul\'s books, it\'s worth its weight in gold and even enjoyable reading for such a \'dry\' subject. 

      * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al.
            o \"High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL\'s full power.\" (From the book description at O\'Reilly) 

      * MySQL Admin Cookbook
            o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration 

      * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen
            o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. ');
SELECT v0,v1,v64,v65000 FROM t1;
v0	v1	v64	v65000










			
	y	Once there, double check that an article doesn't already exist	Here is a list of recommended books on MariaDB and MySQL. We've provided links to Amazon.com here for convenience, but they can be found at many other bookstores, both online and off.
            o "High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity. Learn advanced techniques in depth so you can bring out MySQL's full power." (From the book description at O'Reilly) 
            o A lot of examples of how to use MySQL. As with all of Paul's books, it's worth its weight in gold and even enjoyable reading for such a 'dry' subject. 
            o A must read for anyone wanting to write a plugin for MariaDB, written by the Sergei who designed the plugin interface for MySQL and MariaDB! 
            o A quick step-by-step guide for MySQL users and database administrators to tackle real-world challenges with MySQL configuration and administration 
            o Everything you wanted to know about the SQL 99 standard. Excellent reference book!
            o First MariaDB book!
            o For people who want to learn SQL and the basics of MariaDB.
            o Free to read in the Knowledgebase! 
            o Not all topics are covered and some parts are slightly outdated, but still the best book on this topic. 
            o Now shipping. Purchase at Amazon.com or your favorite bookseller. 
            o The 'default' book to read if you wont to learn to use MySQL / MariaDB. 
            o This is the official guide to cover the passing of the two MySQL Certification examinations. It is valid till version 5.0 of the server, so while it misses all the features available in MySQL 5.1 and greater (including MariaDB 5.1 and greater), it provides a good basic understanding of MySQL for the end-user. 
            o This is the only book we know about that describes the internals of MariaDB / MySQL. A must have for anyone who wants to understand and develop on MariaDB!
      * High Performance MySQL, Second Edition, By Baron Schwartz, Peter Zaitsev, Vadim Tkachenko, Jeremy D. Zawodny, Arjen Lentz, Derek J. Balling, et al.
      * MariaDB Crash Course by Ben Forta
      * MySQL (4th Edition) by Paul DuBois
      * MySQL 5.0 Certification Study Guide, By Paul DuBois, Stefan Hinz, Carsten Pedersen
      * MySQL 5.1 Plugin Development by Sergei Golubchik and Andrew Hutchings
      * MySQL Admin Cookbook
      * MySQL Cookbook by Paul DuBois
      * SQL-99 Complete, Really by Peter Gulutzan & Trudy Pelzer.
      * Understanding MySQL Internals by Sasha Pachev, former MySQL developer at MySQL AB.
  For MariaDB / MySQL end users
  For developers who want to code on MariaDB or MySQL
  If you want to have your favorite MySQL / MariaDB book listed here, please leave a comment.
INSERT INTO t1 (v0,v1,v64,v65000) VALUES ('y', 'yy', REPEAT('c',65), REPEAT('abcdefghi ',6501));
Warnings:
Warning	1265	Data truncated for column 'v0' at row 1
Warning	1265	Data truncated for column 'v1' at row 1
Warning	1265	Data truncated for column 'v64' at row 1
Warning	1265	Data truncated for column 'v65000' at row 1
INSERT INTO t1 (v0,v1,v64,v65000) SELECT v65000, v65000, CONCAT('a',v65000), CONCAT(v65000,v1) FROM t1;
Warnings:
Warning	1265	Data truncated for column 'v0' at row 5
Warning	1265	Data truncated for column 'v1' at row 5
Warning	1265	Data truncated for column 'v64' at row 5
Warning	1265	Data truncated for column 'v65000' at row 5
Warning	1265	Data truncated for column 'v0' at row 6
Warning	1265	Data truncated for column 'v1' at row 6
Warning	1265	Data truncated for column 'v64' at row 6
SELECT v0, v1, v64, LENGTH(v65000) FROM t1;
v0	v1	v64	LENGTH(v65000)
			0
		a	0
	H	aHere is a list of recommended books on MariaDB and MySQL. We've	2966
	a	aabcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abc	65000
	y	Once there, double check that an article doesn't already exist	2965
	y	cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc	65000
ALTER TABLE t1 ADD COLUMN v65536 VARCHAR(65536) ;
Warnings:
Note	1246	Converting column 'v65536' from VARCHAR to TEXT
SHOW COLUMNS IN t1;
Field	Type	Null	Key	Default	Extra
v0	varchar(0)	YES		NULL	
v1	varchar(1)	YES		NULL	
v64	varchar(64)	NO	PRI	NULL	
v65000	varchar(65000)	YES		NULL	
v65536	mediumtext	YES		NULL	
DROP TABLE t1, t2;
#
# Endspace-comparison tests: 
#
#
# Issue 257: Sort order for varchars is different between
#            MyISAM/InnoDB vs MyRocks
#
create table t1 (
pk varchar(64) CHARACTER SET latin1 COLLATE latin1_bin,
col1 varchar(64),
primary key (pk)
);
insert into t1 values ('a','a');
insert into t1 values ('a ', 'a-space');
ERROR 23000: Duplicate entry 'a ' for key 'PRIMARY'
insert into t1 values('b  ', 'b-2x-space');
insert into t1 values ('b', 'b');
ERROR 23000: Duplicate entry 'b' for key 'PRIMARY'
select pk, hex(pk), col1 from t1;
pk	hex(pk)	col1
a	61	a
b  	622020	b-2x-space
insert into t1 values ('a\t', 'a-tab');
insert into t1 values ('a \t', 'a-space-tab');
select pk, hex(pk), col1 from t1 order by pk;
pk	hex(pk)	col1
a		6109	a-tab
a 		612009	a-space-tab
a	61	a
b  	622020	b-2x-space
# Try longer values
insert into t1 values (concat('a', repeat(' ',10)), 'a-10-x-space');
ERROR 23000: Duplicate entry 'a          ' for key 'PRIMARY'
insert into t1 values (concat('c', repeat(' ',10)), 'c-10-x-space');
select * from t1;
pk	col1
a		a-tab
a 		a-space-tab
a	a
b  	b-2x-space
c          	c-10-x-space
drop table t1;
# Secondary index
create table t1 (
pk int not null primary key,
col1 varchar(64) CHARACTER SET latin1 COLLATE latin1_bin,
col2 varchar(64),
key (col1)
);
insert into t1 values (0, 'ab', 'a-b');
insert into t1 values (1, 'a ', 'a-space');
insert into t1 values (2, 'a',  'a');
insert into t1 values (3, 'a  \t', 'a-tab');
analyze table t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	NULL	col1	67	NULL	#	Using index
select col1, hex(col1) from t1;
col1	hex(col1)
a  		61202009
a 	6120
a	61
ab	6162
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	col1	col1	67	NULL	#	Using where; Using index
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
col1	hex(col1)
a  		61202009
a 	6120
a	61
ab	6162
delete from t1;
insert into t1 values(10, '', 'empty');
insert into t1 values(11, repeat(' ', 8), '8x-space');
insert into t1 values(12, repeat(' ', 16), '16x-space');
insert into t1 values(13, repeat(' ', 24), '24x-space');
insert into t1 values(14, concat(repeat(' ', 16),'a'), '16x-space-a');
insert into t1 values(21, repeat(' ', 9), '9x-space');
insert into t1 values(22, repeat(' ',17), '17x-space');
insert into t1 values(23, repeat(' ',18), '18x-space');
explain
select pk, col1, hex(col1), length(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	NULL	col1	67	NULL	#	Using index
select pk, col1, hex(col1), length(col1) from t1;
pk	col1	hex(col1)	length(col1)
10			0
11	        	2020202020202020	8
12	                	20202020202020202020202020202020	16
13	                        	202020202020202020202020202020202020202020202020	24
21	         	202020202020202020	9
22	                 	2020202020202020202020202020202020	17
23	                  	202020202020202020202020202020202020	18
14	                a	2020202020202020202020202020202061	17
drop table t1;
create table t1 (pk int primary key, a varchar(512), key(a)) engine=rocksdb;
insert into t1 values (1, concat('a', repeat(' ', 300)));
insert into t1 values (2, concat('b', repeat(' ', 300)));
select pk,length(a) from t1 force index(a) where a < 'zz';
pk	length(a)
1	301
2	301
select pk,length(a),rtrim(a) from t1 force index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
select pk,length(a),rtrim(a) from t1 ignore index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
drop table t1;
#
# Issue 257: Sort order for varchars is different between
#            MyISAM/InnoDB vs MyRocks
#
create table t1 (
pk varchar(64) CHARACTER SET utf8 COLLATE utf8_bin,
col1 varchar(64),
primary key (pk)
);
insert into t1 values ('a','a');
insert into t1 values ('a ', 'a-space');
ERROR 23000: Duplicate entry 'a ' for key 'PRIMARY'
insert into t1 values('b  ', 'b-2x-space');
insert into t1 values ('b', 'b');
ERROR 23000: Duplicate entry 'b' for key 'PRIMARY'
select pk, hex(pk), col1 from t1;
pk	hex(pk)	col1
a	61	a
b  	622020	b-2x-space
insert into t1 values ('a\t', 'a-tab');
insert into t1 values ('a \t', 'a-space-tab');
select pk, hex(pk), col1 from t1 order by pk;
pk	hex(pk)	col1
a		6109	a-tab
a 		612009	a-space-tab
a	61	a
b  	622020	b-2x-space
# Try longer values
insert into t1 values (concat('a', repeat(' ',10)), 'a-10-x-space');
ERROR 23000: Duplicate entry 'a          ' for key 'PRIMARY'
insert into t1 values (concat('c', repeat(' ',10)), 'c-10-x-space');
select * from t1;
pk	col1
a		a-tab
a 		a-space-tab
a	a
b  	b-2x-space
c          	c-10-x-space
drop table t1;
# Secondary index
create table t1 (
pk int not null primary key,
col1 varchar(64) CHARACTER SET utf8 COLLATE utf8_bin,
col2 varchar(64),
key (col1)
);
insert into t1 values (0, 'ab', 'a-b');
insert into t1 values (1, 'a ', 'a-space');
insert into t1 values (2, 'a',  'a');
insert into t1 values (3, 'a  \t', 'a-tab');
analyze table t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	NULL	col1	195	NULL	#	Using index
select col1, hex(col1) from t1;
col1	hex(col1)
a  		61202009
a 	6120
a	61
ab	6162
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	col1	col1	195	NULL	#	Using where; Using index
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
col1	hex(col1)
a  		61202009
a 	6120
a	61
ab	6162
delete from t1;
insert into t1 values(10, '', 'empty');
insert into t1 values(11, repeat(' ', 8), '8x-space');
insert into t1 values(12, repeat(' ', 16), '16x-space');
insert into t1 values(13, repeat(' ', 24), '24x-space');
insert into t1 values(14, concat(repeat(' ', 16),'a'), '16x-space-a');
insert into t1 values(21, repeat(' ', 9), '9x-space');
insert into t1 values(22, repeat(' ',17), '17x-space');
insert into t1 values(23, repeat(' ',18), '18x-space');
explain
select pk, col1, hex(col1), length(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	NULL	col1	195	NULL	#	Using index
select pk, col1, hex(col1), length(col1) from t1;
pk	col1	hex(col1)	length(col1)
10			0
11	        	2020202020202020	8
12	                	20202020202020202020202020202020	16
13	                        	202020202020202020202020202020202020202020202020	24
21	         	202020202020202020	9
22	                 	2020202020202020202020202020202020	17
23	                  	202020202020202020202020202020202020	18
14	                a	2020202020202020202020202020202061	17
drop table t1;
create table t1 (pk int primary key, a varchar(512), key(a)) engine=rocksdb;
insert into t1 values (1, concat('a', repeat(' ', 300)));
insert into t1 values (2, concat('b', repeat(' ', 300)));
select pk,length(a) from t1 force index(a) where a < 'zz';
pk	length(a)
1	301
2	301
select pk,length(a),rtrim(a) from t1 force index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
select pk,length(a),rtrim(a) from t1 ignore index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
drop table t1;
#
# Issue 257: Sort order for varchars is different between
#            MyISAM/InnoDB vs MyRocks
#
create table t1 (
pk varchar(64) CHARACTER SET ucs2 COLLATE ucs2_bin,
col1 varchar(64),
primary key (pk)
);
insert into t1 values ('a','a');
insert into t1 values ('a ', 'a-space');
ERROR 23000: Duplicate entry 'a ' for key 'PRIMARY'
insert into t1 values('b  ', 'b-2x-space');
insert into t1 values ('b', 'b');
ERROR 23000: Duplicate entry 'b' for key 'PRIMARY'
select pk, hex(pk), col1 from t1;
pk	hex(pk)	col1
a	0061	a
b  	006200200020	b-2x-space
insert into t1 values ('a\t', 'a-tab');
insert into t1 values ('a \t', 'a-space-tab');
select pk, hex(pk), col1 from t1 order by pk;
pk	hex(pk)	col1
a		00610009	a-tab
a 		006100200009	a-space-tab
a	0061	a
b  	006200200020	b-2x-space
# Try longer values
insert into t1 values (concat('a', repeat(' ',10)), 'a-10-x-space');
ERROR 23000: Duplicate entry 'a          ' for key 'PRIMARY'
insert into t1 values (concat('c', repeat(' ',10)), 'c-10-x-space');
select * from t1;
pk	col1
a		a-tab
a 		a-space-tab
a	a
b  	b-2x-space
c          	c-10-x-space
drop table t1;
# Secondary index
create table t1 (
pk int not null primary key,
col1 varchar(64) CHARACTER SET ucs2 COLLATE ucs2_bin,
col2 varchar(64),
key (col1)
);
insert into t1 values (0, 'ab', 'a-b');
insert into t1 values (1, 'a ', 'a-space');
insert into t1 values (2, 'a',  'a');
insert into t1 values (3, 'a  \t', 'a-tab');
analyze table t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	#	
select col1, hex(col1) from t1;
col1	hex(col1)
ab	00610062
a 	00610020
a	0061
a  		0061002000200009
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	col1	col1	131	NULL	#	Using where
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
col1	hex(col1)
a  		0061002000200009
a 	00610020
a	0061
ab	00610062
delete from t1;
insert into t1 values(10, '', 'empty');
insert into t1 values(11, repeat(' ', 8), '8x-space');
insert into t1 values(12, repeat(' ', 16), '16x-space');
insert into t1 values(13, repeat(' ', 24), '24x-space');
insert into t1 values(14, concat(repeat(' ', 16),'a'), '16x-space-a');
insert into t1 values(21, repeat(' ', 9), '9x-space');
insert into t1 values(22, repeat(' ',17), '17x-space');
insert into t1 values(23, repeat(' ',18), '18x-space');
explain
select pk, col1, hex(col1), length(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	NULL	NULL	NULL	NULL	#	
select pk, col1, hex(col1), length(col1) from t1;
pk	col1	hex(col1)	length(col1)
10			0
11	        	00200020002000200020002000200020	16
12	                	0020002000200020002000200020002000200020002000200020002000200020	32
13	                        	002000200020002000200020002000200020002000200020002000200020002000200020002000200020002000200020	48
14	                a	00200020002000200020002000200020002000200020002000200020002000200061	34
21	         	002000200020002000200020002000200020	18
22	                 	00200020002000200020002000200020002000200020002000200020002000200020	34
23	                  	002000200020002000200020002000200020002000200020002000200020002000200020	36
drop table t1;
create table t1 (pk int primary key, a varchar(512), key(a)) engine=rocksdb;
insert into t1 values (1, concat('a', repeat(' ', 300)));
insert into t1 values (2, concat('b', repeat(' ', 300)));
select pk,length(a) from t1 force index(a) where a < 'zz';
pk	length(a)
1	301
2	301
select pk,length(a),rtrim(a) from t1 force index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
select pk,length(a),rtrim(a) from t1 ignore index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
drop table t1;
#
# Issue 257: Sort order for varchars is different between
#            MyISAM/InnoDB vs MyRocks
#
create table t1 (
pk varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
col1 varchar(64),
primary key (pk)
);
insert into t1 values ('a','a');
insert into t1 values ('a ', 'a-space');
ERROR 23000: Duplicate entry 'a ' for key 'PRIMARY'
insert into t1 values('b  ', 'b-2x-space');
insert into t1 values ('b', 'b');
ERROR 23000: Duplicate entry 'b' for key 'PRIMARY'
select pk, hex(pk), col1 from t1;
pk	hex(pk)	col1
a	61	a
b  	622020	b-2x-space
insert into t1 values ('a\t', 'a-tab');
insert into t1 values ('a \t', 'a-space-tab');
select pk, hex(pk), col1 from t1 order by pk;
pk	hex(pk)	col1
a		6109	a-tab
a 		612009	a-space-tab
a	61	a
b  	622020	b-2x-space
# Try longer values
insert into t1 values (concat('a', repeat(' ',10)), 'a-10-x-space');
ERROR 23000: Duplicate entry 'a          ' for key 'PRIMARY'
insert into t1 values (concat('c', repeat(' ',10)), 'c-10-x-space');
select * from t1;
pk	col1
a		a-tab
a 		a-space-tab
a	a
b  	b-2x-space
c          	c-10-x-space
drop table t1;
# Secondary index
create table t1 (
pk int not null primary key,
col1 varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin,
col2 varchar(64),
key (col1)
);
insert into t1 values (0, 'ab', 'a-b');
insert into t1 values (1, 'a ', 'a-space');
insert into t1 values (2, 'a',  'a');
insert into t1 values (3, 'a  \t', 'a-tab');
analyze table t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	#	
select col1, hex(col1) from t1;
col1	hex(col1)
ab	6162
a 	6120
a	61
a  		61202009
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	col1	col1	259	NULL	#	Using where
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
col1	hex(col1)
a  		61202009
a 	6120
a	61
ab	6162
delete from t1;
insert into t1 values(10, '', 'empty');
insert into t1 values(11, repeat(' ', 8), '8x-space');
insert into t1 values(12, repeat(' ', 16), '16x-space');
insert into t1 values(13, repeat(' ', 24), '24x-space');
insert into t1 values(14, concat(repeat(' ', 16),'a'), '16x-space-a');
insert into t1 values(21, repeat(' ', 9), '9x-space');
insert into t1 values(22, repeat(' ',17), '17x-space');
insert into t1 values(23, repeat(' ',18), '18x-space');
explain
select pk, col1, hex(col1), length(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	NULL	NULL	NULL	NULL	#	
select pk, col1, hex(col1), length(col1) from t1;
pk	col1	hex(col1)	length(col1)
10			0
11	        	2020202020202020	8
12	                	20202020202020202020202020202020	16
13	                        	202020202020202020202020202020202020202020202020	24
14	                a	2020202020202020202020202020202061	17
21	         	202020202020202020	9
22	                 	2020202020202020202020202020202020	17
23	                  	202020202020202020202020202020202020	18
drop table t1;
create table t1 (pk int primary key, a varchar(512), key(a)) engine=rocksdb;
insert into t1 values (1, concat('a', repeat(' ', 300)));
insert into t1 values (2, concat('b', repeat(' ', 300)));
select pk,length(a) from t1 force index(a) where a < 'zz';
pk	length(a)
1	301
2	301
select pk,length(a),rtrim(a) from t1 force index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
select pk,length(a),rtrim(a) from t1 ignore index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
drop table t1;
#
# Issue 257: Sort order for varchars is different between
#            MyISAM/InnoDB vs MyRocks
#
create table t1 (
pk varchar(64) CHARACTER SET utf16 COLLATE utf16_bin,
col1 varchar(64),
primary key (pk)
);
insert into t1 values ('a','a');
insert into t1 values ('a ', 'a-space');
ERROR 23000: Duplicate entry 'a ' for key 'PRIMARY'
insert into t1 values('b  ', 'b-2x-space');
insert into t1 values ('b', 'b');
ERROR 23000: Duplicate entry 'b' for key 'PRIMARY'
select pk, hex(pk), col1 from t1;
pk	hex(pk)	col1
a	0061	a
b  	006200200020	b-2x-space
insert into t1 values ('a\t', 'a-tab');
insert into t1 values ('a \t', 'a-space-tab');
select pk, hex(pk), col1 from t1 order by pk;
pk	hex(pk)	col1
a		00610009	a-tab
a 		006100200009	a-space-tab
a	0061	a
b  	006200200020	b-2x-space
# Try longer values
insert into t1 values (concat('a', repeat(' ',10)), 'a-10-x-space');
ERROR 23000: Duplicate entry 'a          ' for key 'PRIMARY'
insert into t1 values (concat('c', repeat(' ',10)), 'c-10-x-space');
select * from t1;
pk	col1
a		a-tab
a 		a-space-tab
a	a
b  	b-2x-space
c          	c-10-x-space
drop table t1;
# Secondary index
create table t1 (
pk int not null primary key,
col1 varchar(64) CHARACTER SET utf16 COLLATE utf16_bin,
col2 varchar(64),
key (col1)
);
insert into t1 values (0, 'ab', 'a-b');
insert into t1 values (1, 'a ', 'a-space');
insert into t1 values (2, 'a',  'a');
insert into t1 values (3, 'a  \t', 'a-tab');
analyze table t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	Engine-independent statistics collected
test.t1	analyze	status	OK
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	#	
select col1, hex(col1) from t1;
col1	hex(col1)
ab	00610062
a 	00610020
a	0061
a  		0061002000200009
# Must show 'using index' for latin1_bin and utf8_bin:
explain
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	col1	col1	259	NULL	#	Using where
select col1, hex(col1) from t1 force index(col1) where col1 < 'b';
col1	hex(col1)
a  		0061002000200009
a 	00610020
a	0061
ab	00610062
delete from t1;
insert into t1 values(10, '', 'empty');
insert into t1 values(11, repeat(' ', 8), '8x-space');
insert into t1 values(12, repeat(' ', 16), '16x-space');
insert into t1 values(13, repeat(' ', 24), '24x-space');
insert into t1 values(14, concat(repeat(' ', 16),'a'), '16x-space-a');
insert into t1 values(21, repeat(' ', 9), '9x-space');
insert into t1 values(22, repeat(' ',17), '17x-space');
insert into t1 values(23, repeat(' ',18), '18x-space');
explain
select pk, col1, hex(col1), length(col1) from t1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	#	NULL	NULL	NULL	NULL	#	
select pk, col1, hex(col1), length(col1) from t1;
pk	col1	hex(col1)	length(col1)
10			0
11	        	00200020002000200020002000200020	16
12	                	0020002000200020002000200020002000200020002000200020002000200020	32
13	                        	002000200020002000200020002000200020002000200020002000200020002000200020002000200020002000200020	48
14	                a	00200020002000200020002000200020002000200020002000200020002000200061	34
21	         	002000200020002000200020002000200020	18
22	                 	00200020002000200020002000200020002000200020002000200020002000200020	34
23	                  	002000200020002000200020002000200020002000200020002000200020002000200020	36
drop table t1;
create table t1 (pk int primary key, a varchar(512), key(a)) engine=rocksdb;
insert into t1 values (1, concat('a', repeat(' ', 300)));
insert into t1 values (2, concat('b', repeat(' ', 300)));
select pk,length(a) from t1 force index(a) where a < 'zz';
pk	length(a)
1	301
2	301
select pk,length(a),rtrim(a) from t1 force index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
select pk,length(a),rtrim(a) from t1 ignore index(a) where a < 'zz';
pk	length(a)	rtrim(a)
1	301	a
2	301	b
drop table t1;
create table t1 (
pk int primary key,
col1 varchar(10) collate utf8mb4_bin not null,
col2 varchar(20),
key(col1)
) engine=rocksdb;
insert into t1 values (1, 'ab','ab');
insert into t1 values (2, 'ab\0','ab0');
select pk, hex(col1), col2 from t1 force index(col1) order by col1;
pk	hex(col1)	col2
2	616200	ab0
1	6162	ab
select pk, hex(col1), col2 from t1 ignore index(col1) order by col1;
pk	hex(col1)	col2
2	616200	ab0
1	6162	ab
drop table t1;
create table t (id int primary key, email varchar(100), KEY email_i (email(30)));
insert into t values (1, 'abcabcabcabcabcabcabcabcabcabcabc  ');
explain select 'email_i' as index_name, count(*) AS count from t force index(email_i);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t	ALL	NULL	NULL	NULL	NULL	#	
select 'email_i' as index_name, count(*) AS count from t force index(email_i);
index_name	count
email_i	1
drop table t;
set @save_rocksdb_checksums_pct = @@global.rocksdb_checksums_pct;
set @save_rocksdb_verify_row_debug_checksums = @@session.rocksdb_verify_row_debug_checksums;
set global rocksdb_checksums_pct = 100;
set session rocksdb_verify_row_debug_checksums = on;
create table t (id int primary key, email varchar(100), KEY email_i (email(30)));
insert into t values (1, 'a');
explain select 'email_i' as index_name, count(*) AS count from t force index(email_i);
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t	ALL	NULL	NULL	NULL	NULL	#	
select 'email_i' as index_name, count(*) AS count from t force index(email_i);
index_name	count
email_i	1
drop table t;
set global rocksdb_checksums_pct = @save_rocksdb_checksums_pct;
set session rocksdb_verify_row_debug_checksums = @save_rocksdb_verify_row_debug_checksums;
drop table if exists t;
Warnings:
Note	1051	Unknown table 'test.t'
create table t (h varchar(31) character set utf8 collate utf8_bin not null, i varchar(19) collate latin1_bin not null, primary key(i), key(h)) engine=rocksdb;
insert into t(i,h) values('a','b');
check table t;
Table	Op	Msg_type	Msg_text
test.t	check	status	OK
alter table t modify h varchar(31) character set cp1257 collate cp1257_bin not null;
check table t;
Table	Op	Msg_type	Msg_text
test.t	check	status	OK
drop table t;