3
drop table if exists t1,t2,t3;
7
select "--- Testing varchar ---";
11
# Simple basic test that endspace is saved
14
create table t1 (v varchar(10), c char(10), t text);
15
insert into t1 values('+ ', '+ ', '+ ');
16
set @a=repeat(' ',20);
17
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
18
select concat('*',v,'*',c,'*',t,'*') from t1;
20
# Check how columns are copied
22
create table t2 like t1;
24
create table t3 select * from t1;
26
alter table t1 modify c varchar(10);
28
alter table t1 modify v char(10);
30
alter table t1 modify t varchar(10);
32
select concat('*',v,'*',c,'*',t,'*') from t1;
38
create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
45
eval set @space=repeat(' ',10-$1);
48
eval set @char=char(ascii('a')+$2-1);
49
insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
55
select count(*) from t1;
56
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
57
select count(*) from t1 where v='a';
58
select count(*) from t1 where c='a';
59
select count(*) from t1 where t='a';
60
select count(*) from t1 where v='a ';
61
select count(*) from t1 where c='a ';
62
select count(*) from t1 where t='a ';
63
select count(*) from t1 where v between 'a' and 'a ';
64
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
65
select count(*) from t1 where v like 'a%';
66
select count(*) from t1 where c like 'a%';
67
select count(*) from t1 where t like 'a%';
68
select count(*) from t1 where v like 'a %';
69
# Test results differ for BDB, see comments in bdb.test
70
# and they are also different from MySAM test results.
72
explain select count(*) from t1 where v='a ';
74
explain select count(*) from t1 where c='a ';
76
explain select count(*) from t1 where t='a ';
78
explain select count(*) from t1 where v like 'a%';
80
explain select count(*) from t1 where v between 'a' and 'a ';
82
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
85
alter table t1 add unique(v);
86
alter table t1 add key(v);
87
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
88
--replace_column 6 # 9 #
89
explain select * from t1 where v='a';
93
select v,count(*) from t1 group by v limit 10;
94
select v,count(t) from t1 group by v limit 10;
95
select v,count(c) from t1 group by v limit 10;
96
select sql_big_result v,count(t) from t1 group by v limit 10;
97
select sql_big_result v,count(c) from t1 group by v limit 10;
98
select c,count(*) from t1 group by c limit 10;
99
select c,count(t) from t1 group by c limit 10;
100
select sql_big_result c,count(t) from t1 group by c limit 10;
101
select t,count(*) from t1 group by t limit 10;
102
select t,count(t) from t1 group by t limit 10;
103
select sql_big_result t,count(t) from t1 group by t limit 10;
106
# Test varchar > 255 bytes
109
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
110
show create table t1;
111
select count(*) from t1 where v='a';
112
select count(*) from t1 where v='a ';
113
select count(*) from t1 where v between 'a' and 'a ';
114
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
115
select count(*) from t1 where v like 'a%';
116
select count(*) from t1 where v like 'a %';
118
explain select count(*) from t1 where v='a ';
120
explain select count(*) from t1 where v like 'a%';
122
explain select count(*) from t1 where v between 'a' and 'a ';
124
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
126
explain select * from t1 where v='a';
130
select v,count(*) from t1 group by v limit 10;
131
select v,count(t) from t1 group by v limit 10;
132
select sql_big_result v,count(t) from t1 group by v limit 10;
135
# Test varchar > 255 bytes, key < 255
138
alter table t1 drop key v, add key v (v(30));
139
show create table t1;
140
select count(*) from t1 where v='a';
141
select count(*) from t1 where v='a ';
142
select count(*) from t1 where v between 'a' and 'a ';
143
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
144
select count(*) from t1 where v like 'a%';
145
select count(*) from t1 where v like 'a %';
147
explain select count(*) from t1 where v='a ';
149
explain select count(*) from t1 where v like 'a%';
151
explain select count(*) from t1 where v between 'a' and 'a ';
153
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
155
explain select * from t1 where v='a';
159
select v,count(*) from t1 group by v limit 10;
160
select v,count(t) from t1 group by v limit 10;
161
select sql_big_result v,count(t) from t1 group by v limit 10;
164
# Test varchar > 512 (special case for GROUP BY becasue of
165
# CONVERT_IF_BIGGER_TO_BLOB define)
168
alter table t1 modify v varchar(600), drop key v, add key v (v);
169
show create table t1;
170
select v,count(*) from t1 group by v limit 10;
171
select v,count(t) from t1 group by v limit 10;
172
select sql_big_result v,count(t) from t1 group by v limit 10;
180
create table t1 (a char(10), unique (a));
181
insert into t1 values ('a ');
183
insert into t1 values ('a ');
185
alter table t1 modify a varchar(10);
187
insert into t1 values ('a '),('a '),('a '),('a ');
189
insert into t1 values ('a ');
191
insert into t1 values ('a ');
193
insert into t1 values ('a ');
194
update t1 set a='a ' where a like 'a%';
195
select concat(a,'.') from t1;
196
update t1 set a='abc ' where a like 'a ';
197
select concat(a,'.') from t1;
198
update t1 set a='a ' where a like 'a %';
199
select concat(a,'.') from t1;
200
update t1 set a='a ' where a like 'a ';
201
select concat(a,'.') from t1;
205
# test show create table
208
create table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
209
show create table t1;
211
create table t1 (v char(10) character set utf8);
212
show create table t1;
215
create table t1 (v varchar(10), c char(10)) row_format=fixed;
216
show create table t1;
217
insert into t1 values('a','a'),('a ','a ');
218
select concat('*',v,'*',c,'*') from t1;
225
create table t1 (v varchar(65530), key(v(10)));
226
insert into t1 values(repeat('a',65530));
227
select length(v) from t1 where v=repeat('a',65530);
231
# Bug #9489: problem with hash indexes
232
# Bug #10802: Index is not used if table using BDB engine on HP-UX
235
create table t1(a int, b varchar(12), key ba(b, a));
236
insert into t1 values (1, 'A'), (20, NULL);
237
explain select * from t1 where a=20 and b is null;
238
select * from t1 where a=20 and b is null;