summaryrefslogtreecommitdiff
path: root/mysql-test/t/type_varchar.test
blob: 0168128d513c3a657c3338615b2ac4d9ad02a8c4 (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
--disable_warnings
drop table if exists t1;
--enable_warnings

create table t1 (v varchar(30), c char(3), e enum('abc','def','ghi'), t text);
system cp std_data/vchar.frm var/master-data/test/;
truncate table vchar;
show create table t1;
show create table vchar;
insert into t1 values ('abc', 'de', 'ghi', 'jkl');
insert into t1 values ('abc ', 'de ', 'ghi', 'jkl ');
insert into t1 values ('abc    ', 'd  ', 'ghi', 'jkl    ');
insert into vchar values ('abc', 'de', 'ghi', 'jkl');
insert into vchar values ('abc ', 'de ', 'ghi', 'jkl ');
insert into vchar values ('abc    ', 'd  ', 'ghi', 'jkl    ');
select length(v),length(c),length(e),length(t) from t1;
select length(v),length(c),length(e),length(t) from vchar;
alter table vchar add i int;
show create table vchar;
select length(v),length(c),length(e),length(t) from vchar;
drop table t1, vchar;
create table t1 (v varchar(20));
insert into t1 values('a ');
select v='a' from t1;
select binary v='a' from t1;
select binary v='a ' from t1;
insert into t1 values('a');
--error 1062
alter table t1 add primary key (v);
drop table t1;
create table t1 (v varbinary(20));
insert into t1 values('a');
insert into t1 values('a ');
alter table t1 add primary key (v);
drop table t1;

#
# Test with varchar of lengths 254,255,256,258 & 258 to ensure we don't
# have any problems with varchar with one or two byte length_bytes
#

create table t1 (v varchar(254), index (v));
insert into t1 values ("This is a test ");
insert into t1 values ("Some sample data");
insert into t1 values (" garbage ");
insert into t1 values (" This is a test ");
insert into t1 values ("This is a test");
insert into t1 values ("Hello world");
insert into t1 values ("Foo bar");
insert into t1 values ("This is a test");
insert into t1 values ("MySQL varchar test");
insert into t1 values ("test MySQL varchar");
insert into t1 values ("This is a long string to have some random length data included");
insert into t1 values ("Short string");
insert into t1 values ("VSS");
insert into t1 values ("Some samples");
insert into t1 values ("Bar foo");
insert into t1 values ("Bye");
let $i= 255;
let $j= 5;
while ($j)
{
  select * from t1 where v like 'This is a test' order by v;
  select * from t1 where v='This is a test' order by v;
  select * from t1 where v like 'S%' order by v;
  explain select * from t1 where v like 'This is a test' order by v;
  explain select * from t1 where v='This is a test' order by v;
  explain select * from t1 where v like 'S%' order by v;
  eval alter table t1 change v v varchar($i);
  inc $i;
  dec $j;
}
let $i= 258;
let $j= 6;
while ($j)
{
  select * from t1 where v like 'This is a test' order by v;
  select * from t1 where v='This is a test' order by v;
  select * from t1 where v like 'S%' order by v;
  explain select * from t1 where v like 'This is a test' order by v;
  explain select * from t1 where v='This is a test' order by v;
  explain select * from t1 where v like 'S%' order by v;
  eval alter table t1 change v v varchar($i);
  dec $i;
  dec $j;
}
alter table t1 change v v varchar(254), drop key v;

# Test with length(varchar) > 256 and key < 256 (to ensure things works with
# different kind of packing

alter table t1 change v v varchar(300), add key (v(10));
select * from t1 where v like 'This is a test' order by v;
select * from t1 where v='This is a test' order by v;
select * from t1 where v like 'S%' order by v;
explain select * from t1 where v like 'This is a test' order by v;
explain select * from t1 where v='This is a test' order by v;
explain select * from t1 where v like 'S%' order by v;
drop table t1;