1
drop table if exists t1,t2,t3,t4,t5,t6,t7;
2
CREATE TABLE t1 (a blob, b text, c blob, d text, e text);
4
Field Type Null Default Default_is_NULL On_Update
10
CREATE TABLE t2 (a varchar(255), b blob, c blob);
11
CREATE TABLE t4 (c varchar(16383) not null);
13
Field Type Null Default Default_is_NULL On_Update
17
create table t3 (a int, b int);
20
t3 CREATE TABLE `t3` (
23
) ENGINE=DEFAULT COLLATE = utf8_general_ci
26
t4 CREATE TABLE `t4` (
27
`c` VARCHAR(16383) COLLATE utf8_general_ci NOT NULL
28
) ENGINE=DEFAULT COLLATE = utf8_general_ci
29
drop table t1,t2,t3,t4;
30
CREATE TABLE t1 (a blob default "hello");
31
ERROR 42000: BLOB/TEXT column 'a' can't have a default value
32
CREATE TABLE t2 (a varchar(256));
34
CREATE TABLE t1 (a varchar(70000) default "hello");
35
ERROR 42000: Column length too big for column 'a' (max = 65535); use BLOB or TEXT instead
36
CREATE TABLE t2 (a blob default "hello");
37
ERROR 42000: BLOB/TEXT column 'a' can't have a default value
38
drop table if exists t1,t2;
39
create table t1 (nr int not null auto_increment,b blob,str char(10), primary key (nr));
40
insert into t1 values (null,"a","A");
41
insert into t1 values (null,"bbb","BBB");
42
insert into t1 values (null,"ccc","CCC");
43
select last_insert_id();
46
select * from t1,t1 as t2;
58
create table t1 (a text);
59
insert into t1 values ('where');
60
update t1 set a='Where';
65
create table t1 (t text,c varchar(10),b blob, d blob);
66
insert into t1 values (NULL,NULL,NULL,NULL);
67
insert into t1 values ("","","","");
68
insert into t1 values ("hello","hello","hello","hello");
69
insert into t1 values ("HELLO","HELLO","HELLO","HELLO");
70
insert into t1 values ("HELLO MY","HELLO MY","HELLO MY","HELLO MY");
71
insert into t1 values ("a","a","a","a");
72
insert into t1 values (1,1,1,1);
73
insert into t1 values (NULL,NULL,NULL,NULL);
74
update t1 set c="",b=null where c="1";
75
select t from t1 where t like "hello";
79
select c from t1 where c like "hello";
83
select b from t1 where b like "hello";
86
select d from t1 where d like "hello";
89
select c from t1 having c like "hello";
93
select d from t1 having d like "hello";
96
select t from t1 where t like "%HELLO%";
101
select c from t1 where c like "%HELLO%";
106
select b from t1 where b like "%HELLO%";
110
select d from t1 where d like "%HELLO%";
114
select c from t1 having c like "%HELLO%";
119
select d from t1 having d like "%HELLO%";
123
select d from t1 having d like "%HE%LLO%";
127
select t from t1 order by t;
137
select c from t1 order by c;
147
select b from t1 order by b;
157
select d from t1 order by d;
167
select distinct t from t1;
175
select distinct b from t1;
183
select distinct t from t1 order by t;
191
select distinct b from t1 order by b;
199
select t from t1 group by t;
207
select b from t1 group by b;
215
select distinct t from t1;
223
select distinct b from t1;
231
select distinct t from t1 order by t;
239
select distinct b from t1 order by b;
247
select distinct c from t1;
254
select distinct d from t1;
263
select distinct c from t1 order by c;
270
select distinct d from t1 order by d;
279
select c from t1 group by c;
286
select d from t1 group by d;
295
select distinct * from t1;
299
hello hello hello hello
300
HELLO HELLO HELLO HELLO
301
HELLO MY HELLO MY HELLO MY HELLO MY
304
select t,count(*) from t1 group by t;
312
select b,count(*) from t1 group by b;
320
select c,count(*) from t1 group by c;
327
select d,count(*) from t1 group by d;
337
create table t1 (a text, unique (a(2100)));
338
ERROR 42000: Specified key was too long; max key length is 767 bytes
339
create table t1 (a text, key (a(2100)));
341
Warning 1071 Specified key was too long; max key length is 767 bytes
342
show create table t1;
344
t1 CREATE TABLE `t1` (
345
`a` TEXT COLLATE utf8_general_ci,
346
KEY `a` (`a`(191)) USING BTREE
347
) ENGINE=DEFAULT COLLATE = utf8_general_ci
350
t1_id bigint NOT NULL auto_increment,
351
_field_72 varchar(128) DEFAULT '' NOT NULL,
352
_field_95 varchar(32),
353
_field_115 int DEFAULT '0' NOT NULL,
354
_field_122 int DEFAULT '0' NOT NULL,
358
UNIQUE _field_72 (_field_72),
359
KEY _field_115 (_field_115),
360
KEY _field_122 (_field_122)
362
INSERT INTO t1 VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',0,1,NULL,NULL);
363
INSERT INTO t1 VALUES (2,'hroberts','7415275a8c95952901e42b13a6b78566',0,1,NULL,NULL);
364
INSERT INTO t1 VALUES (3,'guest','d41d8cd98f00b204e9800998ecf8427e',1,0,NULL,NULL);
366
seq_0_id bigint DEFAULT '0' NOT NULL,
367
seq_1_id bigint DEFAULT '0' NOT NULL,
368
PRIMARY KEY (seq_0_id,seq_1_id)
370
INSERT INTO t2 VALUES (1,1);
371
INSERT INTO t2 VALUES (2,1);
372
INSERT INTO t2 VALUES (2,2);
374
t3_id bigint NOT NULL auto_increment,
375
_field_131 varchar(128),
376
_field_133 int DEFAULT '0' NOT NULL,
381
_field_142 int DEFAULT '0' NOT NULL,
382
_field_145 int DEFAULT '0' NOT NULL,
383
_field_148 int DEFAULT '0' NOT NULL,
385
KEY _field_133 (_field_133),
386
KEY _field_135 (_field_135),
387
KEY _field_139 (_field_139),
388
KEY _field_142 (_field_142),
389
KEY _field_145 (_field_145),
390
KEY _field_148 (_field_148)
392
INSERT INTO t3 VALUES (1,'test job 1',0,NULL,0,'1999-02-25 22:43:32','test\r\njob\r\n1',0,0,0);
393
INSERT INTO t3 VALUES (2,'test job 2',0,NULL,0,'1999-02-26 21:08:04','',0,0,0);
395
seq_0_id bigint DEFAULT '0' NOT NULL,
396
seq_1_id bigint DEFAULT '0' NOT NULL,
397
PRIMARY KEY (seq_0_id,seq_1_id)
399
INSERT INTO t4 VALUES (1,1);
400
INSERT INTO t4 VALUES (2,1);
402
t5_id bigint NOT NULL auto_increment,
404
_field_156 varchar(128) DEFAULT '' NOT NULL,
405
_field_157 varchar(128) DEFAULT '' NOT NULL,
406
_field_158 varchar(128) DEFAULT '' NOT NULL,
407
_field_159 varchar(128) DEFAULT '' NOT NULL,
408
_field_160 varchar(128) DEFAULT '' NOT NULL,
409
_field_161 varchar(128) DEFAULT '' NOT NULL,
411
KEY _field_156 (_field_156),
412
KEY _field_157 (_field_157),
413
KEY _field_158 (_field_158),
414
KEY _field_159 (_field_159),
415
KEY _field_160 (_field_160),
416
KEY _field_161 (_field_161)
418
INSERT INTO t5 VALUES (1,0,'tomato','','','','','');
419
INSERT INTO t5 VALUES (2,0,'cilantro','','','','','');
421
seq_0_id bigint DEFAULT '0' NOT NULL,
422
seq_1_id bigint DEFAULT '0' NOT NULL,
423
PRIMARY KEY (seq_0_id,seq_1_id)
425
INSERT INTO t6 VALUES (1,1);
426
INSERT INTO t6 VALUES (1,2);
427
INSERT INTO t6 VALUES (2,2);
429
t7_id bigint NOT NULL auto_increment,
431
_field_165 varchar(32),
432
_field_166 int DEFAULT '0' NOT NULL,
434
KEY _field_166 (_field_166)
436
INSERT INTO t7 VALUES (1,0,'High',1);
437
INSERT INTO t7 VALUES (2,0,'Medium',2);
438
INSERT INTO t7 VALUES (3,0,'Low',3);
439
select replace(t3._field_140, "\r","^M"),t3_id,min(t3._field_131), min(t3._field_135), min(t3._field_139), min(t3._field_137), min(link_alias_142._field_165), min(link_alias_133._field_72), min(t3._field_145), min(link_alias_148._field_156), replace(min(t3._field_140), "\r","^M"),t3.t3_id from t3 left join t4 on t4.seq_0_id = t3.t3_id left join t7 link_alias_142 on t4.seq_1_id = link_alias_142.t7_id left join t6 on t6.seq_0_id = t3.t3_id left join t1 link_alias_133 on t6.seq_1_id = link_alias_133.t1_id left join t2 on t2.seq_0_id = t3.t3_id left join t5 link_alias_148 on t2.seq_1_id = link_alias_148.t5_id where t3.t3_id in (1) group by t3.t3_id order by link_alias_142._field_166, _field_139, link_alias_133._field_72, _field_135, link_alias_148._field_156;
440
replace(t3._field_140, "\r","^M") t3_id min(t3._field_131) min(t3._field_135) min(t3._field_139) min(t3._field_137) min(link_alias_142._field_165) min(link_alias_133._field_72) min(t3._field_145) min(link_alias_148._field_156) replace(min(t3._field_140), "\r","^M") t3_id
443
1 1 test job 1 NULL 1999-02-25 22:43:32 0 High admin 0 tomato test^M
446
drop table t1,t2,t3,t4,t5,t6,t7;
447
create table t1 (a blob);
448
insert into t1 values ("empty"),("");
449
select a,reverse(a) from t1;
454
create table t1 (a blob, key (a(10)));
455
insert into t1 values ("bye"),("hello"),("hello"),("hello word");
456
select * from t1 where a like "hello%";
463
f1 int DEFAULT '0' NOT NULL,
464
f2 varchar(16) DEFAULT '' NOT NULL,
466
KEY index_name (f1,f2,f5(16))
468
INSERT INTO t1 VALUES (0,'traktor','1111111111111');
469
INSERT INTO t1 VALUES (1,'traktor','1111111111111111111111111');
470
select count(*) from t1 where f2='traktor';
474
create table t1 (foobar tinyblob not null, boggle int not null, key (foobar(32), boggle));
475
insert into t1 values ('fish', 10),('bear', 20);
476
select foobar, boggle from t1 where foobar = 'fish';
479
select foobar, boggle from t1 where foobar = 'fish' and boggle = 10;
483
create table t1 (id integer primary key auto_increment, txt text, index txt_index (txt (20)));
484
insert into t1 (txt) values ('Chevy'), ('Chevy '), (NULL);
485
select * from t1 where txt='Chevy' or txt is NULL;
490
explain select * from t1 where txt='Chevy' or txt is NULL;
491
id select_type table type possible_keys key key_len ref rows Extra
492
1 SIMPLE t1 ALL txt_index NULL NULL NULL # Using where
493
select * from t1 where txt='Chevy ';
497
select * from t1 where txt='Chevy ' or txt='Chevy';
501
select * from t1 where txt='Chevy' or txt='Chevy ';
505
select * from t1 where id='1' or id='2';
509
insert into t1 (txt) values('Ford');
510
select * from t1 where txt='Chevy' or txt='Chevy ' or txt='Ford';
515
select * from t1 where txt='Chevy' or txt='Chevy ';
519
select * from t1 where txt='Chevy' or txt='Chevy ' or txt=' Chevy';
523
select * from t1 where txt in ('Chevy ','Chevy');
527
select * from t1 where txt in ('Chevy');
531
select * from t1 where txt between 'Chevy' and 'Chevy';
535
select * from t1 where txt between 'Chevy' and 'Chevy' or txt='Chevy ';
539
select * from t1 where txt between 'Chevy' and 'Chevy ';
543
select * from t1 where txt < 'Chevy ';
545
select * from t1 where txt < 'Chevy ' or txt is NULL;
548
select * from t1 where txt <= 'Chevy';
552
select * from t1 where txt > 'Chevy';
555
select * from t1 where txt >= 'Chevy';
560
alter table t1 modify column txt blob;
561
explain select * from t1 where txt='Chevy' or txt is NULL;
562
id select_type table type possible_keys key key_len ref rows Extra
563
1 SIMPLE t1 ALL txt_index NULL NULL NULL # Using where
564
select * from t1 where txt='Chevy' or txt is NULL;
568
explain select * from t1 where txt='Chevy' or txt is NULL order by txt;
569
id select_type table type possible_keys key key_len ref rows Extra
570
1 SIMPLE t1 ALL txt_index NULL NULL NULL # Using where; Using filesort
571
select * from t1 where txt='Chevy' or txt is NULL order by txt;
576
CREATE TABLE t1 ( i int NOT NULL default '0', c text NOT NULL, d varchar(1) NOT NULL DEFAULT ' ', PRIMARY KEY (i), KEY (c(1),d));
577
INSERT t1 (i, c) VALUES (1,''),(2,''),(3,'asdfh'),(4,'');
578
select max(i) from t1 where c = '';
582
create table t1 (a int, b int, c tinyblob, d int, e int);
583
alter table t1 add primary key (a,b,c(255),d);
584
alter table t1 add key (a,b,d,e);
585
show create table t1;
587
t1 CREATE TABLE `t1` (
592
`e` INT DEFAULT NULL,
593
PRIMARY KEY (`a`,`b`,`c`(255),`d`) USING BTREE,
594
KEY `a` (`a`,`b`,`d`,`e`) USING BTREE
595
) ENGINE=DEFAULT COLLATE = utf8_general_ci
597
CREATE table t1 (a blob);
598
insert into t1 values ('b'),('a\0'),('a'),('a '),('aa'),(NULL);
599
select hex(a) from t1 order by a;
607
select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0');
615
alter table t1 modify a blob;
616
select hex(a) from t1 order by a;
624
select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0');
632
alter table t1 modify a char(5);
633
select hex(a) from t1 order by a;
641
select hex(concat(a,'\0')) as b from t1 order by concat(a,'\0');
650
create table t1 (a text default '');
651
show create table t1;
653
t1 CREATE TABLE `t1` (
654
`a` TEXT COLLATE utf8_general_ci DEFAULT ''
655
) ENGINE=DEFAULT COLLATE = utf8_general_ci
656
insert into t1 values (default);
661
create table t1 (a text default '');
663
CREATE TABLE t (c TEXT);
664
INSERT INTO t (c) VALUES (REPEAT('1',65537));
665
INSERT INTO t (c) VALUES (REPEAT('2',65536));
666
INSERT INTO t (c) VALUES (REPEAT('3',65535));
667
SELECT LENGTH(c), CHAR_LENGTH(c) FROM t;
668
LENGTH(c) CHAR_LENGTH(c)