3
drop table if exists t1,t2,t3;
7
select "--- Testing varchar ---";
11
# Simple basic test that endspace is saved
14
eval create $temp table t1 (v varchar(10), c char(10), t text);
15
insert into t1 values('+ ', '+ ', '+ ');
16
set @a=repeat(' ',20);
18
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
19
set @a=repeat(' ',10);
21
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
23
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
24
select concat('*',v,'*',c,'*',t,'*') from t1;
26
# Check how columns are copied
28
eval create $temp table t2 like t1;
30
eval create $temp table t3 select * from t1;
32
alter table t1 modify c varchar(10);
34
alter table t1 modify v char(10);
36
alter table t1 modify t varchar(10);
38
select concat('*',v,'*',c,'*',t,'*') from t1;
44
eval create $temp table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
52
eval set @space=repeat(' ',10-$1);
55
eval set @char=char(ascii('a')+$2-1);
56
insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
63
select count(*) from t1;
64
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
65
select count(*) from t1 where v='a';
66
select count(*) from t1 where c='a';
67
select count(*) from t1 where t='a';
68
select count(*) from t1 where v='a ';
69
select count(*) from t1 where c='a ';
70
select count(*) from t1 where t='a ';
71
select count(*) from t1 where v between 'a' and 'a ';
72
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
73
select count(*) from t1 where v like 'a%';
74
select count(*) from t1 where c like 'a%';
75
select count(*) from t1 where t like 'a%';
76
select count(*) from t1 where v like 'a %';
77
# Test results differ for BDB, see comments in bdb.test
78
# and they are also different from MySAM test results.
80
explain select count(*) from t1 where v='a ';
82
explain select count(*) from t1 where c='a ';
84
explain select count(*) from t1 where t='a ';
86
explain select count(*) from t1 where v like 'a%';
88
explain select count(*) from t1 where v between 'a' and 'a ';
90
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
93
alter table t1 add unique(v);
94
alter table t1 add key(v);
95
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
96
--replace_column 6 # 9 #
97
explain select * from t1 where v='a';
101
select v,count(*) from t1 group by v limit 10;
102
select v,count(t) from t1 group by v limit 10;
103
select v,count(c) from t1 group by v limit 10;
104
select sql_big_result v,count(t) from t1 group by v limit 10;
105
select sql_big_result v,count(c) from t1 group by v limit 10;
106
select c,count(*) from t1 group by c limit 10;
107
select c,count(t) from t1 group by c limit 10;
108
select sql_big_result c,count(t) from t1 group by c limit 10;
109
select t,count(*) from t1 group by t limit 10;
110
select t,count(t) from t1 group by t limit 10;
111
select sql_big_result t,count(t) from t1 group by t limit 10;
114
# Test varchar > 255 bytes
117
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
118
show create table t1;
119
select count(*) from t1 where v='a';
120
select count(*) from t1 where v='a ';
121
select count(*) from t1 where v between 'a' and 'a ';
122
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
123
select count(*) from t1 where v like 'a%';
124
select count(*) from t1 where v like 'a %';
126
explain select count(*) from t1 where v='a ';
128
explain select count(*) from t1 where v like 'a%';
130
explain select count(*) from t1 where v between 'a' and 'a ';
132
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
134
explain select * from t1 where v='a';
138
select v,count(*) from t1 group by v limit 10;
139
select v,count(t) from t1 group by v limit 10;
140
select sql_big_result v,count(t) from t1 group by v limit 10;
143
# Test varchar > 255 bytes, key < 255
146
alter table t1 drop key v, add key v (v(30));
147
show create table t1;
148
select count(*) from t1 where v='a';
149
select count(*) from t1 where v='a ';
150
select count(*) from t1 where v between 'a' and 'a ';
151
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
152
select count(*) from t1 where v like 'a%';
153
select count(*) from t1 where v like 'a %';
155
explain select count(*) from t1 where v='a ';
157
explain select count(*) from t1 where v like 'a%';
159
explain select count(*) from t1 where v between 'a' and 'a ';
161
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
163
explain select * from t1 where v='a';
167
select v,count(*) from t1 group by v limit 10;
168
select v,count(t) from t1 group by v limit 10;
169
select sql_big_result v,count(t) from t1 group by v limit 10;
172
# Test varchar > 512 (special case for GROUP BY becasue of
173
# CONVERT_IF_BIGGER_TO_BLOB define)
176
alter table t1 modify v varchar(600), drop key v, add key v (v);
177
show create table t1;
178
select v,count(*) from t1 group by v limit 10;
179
select v,count(t) from t1 group by v limit 10;
180
select sql_big_result v,count(t) from t1 group by v limit 10;
188
eval create $temp table t1 (a char(10), unique (a));
189
insert into t1 values ('a ');
191
insert into t1 values ('a ');
193
alter table t1 modify a varchar(10);
195
insert into t1 values ('a '),('a '),('a '),('a ');
197
insert into t1 values ('a ');
199
insert into t1 values ('a ');
201
insert into t1 values ('a ');
202
update t1 set a='a ' where a like 'a%';
203
select concat(a,'.') from t1;
204
update t1 set a='abc ' where a like 'a ';
205
select concat(a,'.') from t1;
206
update t1 set a='a ' where a like 'a %';
207
select concat(a,'.') from t1;
208
update t1 set a='a ' where a like 'a ';
209
select concat(a,'.') from t1;
213
# test show create table
216
eval create $temp table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
217
show create table t1;
219
eval create $temp table t1 (v char(10));
220
show create table t1;
223
eval create $temp table t1 (v varchar(10), c char(10));
224
show create table t1;
225
insert into t1 values('a','a'),('a ','a ');
226
select concat('*',v,'*',c,'*') from t1;
232
# @TODO The below fails because it assumes latin1
233
# as the charset. Possibly re-enable a similar test
234
# for UTF8-only in future
235
#create $temp table t1 (v varchar(65530), key(v(10)));
236
#insert into t1 values(repeat('a',65530));
237
#select length(v) from t1 where v=repeat('a',65530);
241
# Bug #9489: problem with hash indexes
242
# Bug #10802: Index is not used if table using BDB engine on HP-UX
245
eval create $temp table t1(a int, b varchar(12), key ba(b, a));
246
insert into t1 values (1, 'A'), (20, NULL);
247
explain select * from t1 where a=20 and b is null;
248
select * from t1 where a=20 and b is null;