1
by brian
clean slate |
1 |
# Initialise |
2 |
--disable_warnings
|
|
3 |
drop table if exists t1, t2; |
|
4 |
--enable_warnings
|
|
5 |
||
6 |
#
|
|
7 |
# Testing of NULL in a lot of different places |
|
8 |
#
|
|
9 |
||
10 |
select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null; |
|
11 |
explain extended select null,\N,isnull(null),isnull(1/0),isnull(1/0 = null),ifnull(null,1),ifnull(null,"TRUE"),ifnull("TRUE","ERROR"),1/0 is null,1 is not null; |
|
685.4.1
by Jay Pipes
Enabled the null.test. |
12 |
select CONCAT(1, NULL),1+NULL,1-NULL; |
13 |
select NULL=NULL,NULL<>NULL,IFNULL(NULL,1.1)+0,CONCAT(IFNULL(NULL,1), 0); |
|
14 |
select strcmp("a",NULL),(1<NULL)+0.0,null like "a%","a%" like null; |
|
1
by brian
clean slate |
15 |
select concat("a",NULL),replace(NULL,"a","b"),replace("string","i",NULL),replace("string",NULL,"i"),insert("abc",1,1,NULL),left(NULL,1); |
16 |
select repeat("a",0),repeat("ab",5+5),repeat("ab",-1),reverse(NULL); |
|
17 |
select field(NULL,"a","b","c"); |
|
18 |
select 2 between null and 1,2 between 3 AND NULL,NULL between 1 and 2,2 between NULL and 3, 2 between 1 AND null; |
|
19 |
explain extended select 2 between null and 1,2 between 3 AND NULL,NULL between 1 and 2,2 between NULL and 3, 2 between 1 AND null; |
|
20 |
SELECT NULL AND NULL, 1 AND NULL, NULL AND 1, NULL OR NULL, 0 OR NULL, NULL OR 0; |
|
21 |
SELECT (NULL OR NULL) IS NULL; |
|
22 |
select NULL AND 0, 0 and NULL; |
|
685.4.1
by Jay Pipes
Enabled the null.test. |
23 |
# @TODO Move to functions/inet_ntoa.test when INET_NTOA function is |
24 |
# implemented |
|
25 |
# select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); |
|
26 |
# explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton(""); |
|
1
by brian
clean slate |
27 |
|
28 |
create table t1 (x int); |
|
29 |
insert into t1 values (null); |
|
30 |
select * from t1 where x != 0; |
|
31 |
drop table t1; |
|
32 |
||
33 |
#
|
|
34 |
# Test problem med index on NULL columns and testing with =NULL; |
|
35 |
#
|
|
36 |
||
37 |
CREATE TABLE t1 ( |
|
38 |
indexed_field int default NULL, |
|
39 |
KEY indexed_field (indexed_field) |
|
40 |
);
|
|
41 |
INSERT INTO t1 VALUES (NULL),(NULL); |
|
42 |
SELECT * FROM t1 WHERE indexed_field=NULL; |
|
43 |
SELECT * FROM t1 WHERE indexed_field IS NULL; |
|
44 |
SELECT * FROM t1 WHERE indexed_field<=>NULL; |
|
45 |
DROP TABLE t1; |
|
46 |
||
47 |
#
|
|
48 |
# Testing of IFNULL |
|
49 |
#
|
|
685.4.1
by Jay Pipes
Enabled the null.test. |
50 |
create table t1 (a int, b int); |
1
by brian
clean slate |
51 |
insert into t1 values(20,null); |
52 |
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on |
|
53 |
t2.b=t3.a; |
|
54 |
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on |
|
55 |
t2.b=t3.a order by 1; |
|
56 |
insert into t1 values(10,null); |
|
57 |
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on |
|
58 |
t2.b=t3.a order by 1; |
|
59 |
drop table t1; |
|
60 |
||
61 |
#
|
|
62 |
# Test inserting and updating with NULL |
|
63 |
#
|
|
873.1.2
by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke |
64 |
CREATE TABLE t1 (a varchar(16) NOT NULL default '', b int NOT NULL default 0, c datetime NOT NULL default '2009-02-10 00:00:00', d int NOT NULL default 0); |
685.4.1
by Jay Pipes
Enabled the null.test. |
65 |
|
66 |
# Test INSERT with NULL |
|
67 |
||
1
by brian
clean slate |
68 |
--error 1048
|
69 |
INSERT INTO t1 (a) values (null); |
|
70 |
--error 1048
|
|
71 |
INSERT INTO t1 (a) values (1/null); |
|
685.4.1
by Jay Pipes
Enabled the null.test. |
72 |
--error 1048
|
1
by brian
clean slate |
73 |
INSERT INTO t1 (a) values (null),(null); |
74 |
--error 1048
|
|
75 |
INSERT INTO t1 (b) values (null); |
|
76 |
--error 1048
|
|
77 |
INSERT INTO t1 (b) values (1/null); |
|
685.4.1
by Jay Pipes
Enabled the null.test. |
78 |
--error 1048
|
1
by brian
clean slate |
79 |
INSERT INTO t1 (b) values (null),(null); |
80 |
--error 1048
|
|
81 |
INSERT INTO t1 (c) values (null); |
|
82 |
--error 1048
|
|
83 |
INSERT INTO t1 (c) values (1/null); |
|
685.4.1
by Jay Pipes
Enabled the null.test. |
84 |
--error 1048
|
1
by brian
clean slate |
85 |
INSERT INTO t1 (c) values (null),(null); |
86 |
--error 1048
|
|
87 |
INSERT INTO t1 (d) values (null); |
|
88 |
--error 1048
|
|
89 |
INSERT INTO t1 (d) values (1/null); |
|
685.4.1
by Jay Pipes
Enabled the null.test. |
90 |
--error 1048
|
1
by brian
clean slate |
91 |
INSERT INTO t1 (d) values (null),(null); |
685.4.1
by Jay Pipes
Enabled the null.test. |
92 |
|
93 |
# Test UPDATE with NULLs |
|
94 |
||
95 |
# The following should not error since there |
|
96 |
# are no rows in the table. |
|
97 |
UPDATE t1 SET d= NULL; |
|
98 |
||
99 |
# Insert a default row in order to test UPDATE to NULL error |
|
100 |
INSERT INTO t1 VALUES (); |
|
101 |
||
102 |
--error 1048
|
|
103 |
UPDATE t1 SET a=1/NULL; |
|
104 |
--error 1048
|
|
105 |
UPDATE t1 SET a=NULL; |
|
106 |
--error 1048
|
|
107 |
UPDATE t1 SET b=NULL; |
|
108 |
--error 1048
|
|
109 |
UPDATE t1 SET c=NULL; |
|
110 |
--error 1048
|
|
111 |
UPDATE t1 SET d=NULL; |
|
112 |
||
113 |
truncate table t1; |
|
114 |
||
115 |
# Test for LOAD DATA INFILE and check for NULL handling |
|
116 |
# Error produced should be 1263, which is almost the same |
|
117 |
# as 1048, only gives a "row" number. |
|
118 |
# @TODO Is there really a reason for a separate error |
|
119 |
# just for LOAD DATA INFILE? |
|
120 |
--error 1263
|
|
121 |
LOAD DATA INFILE '../std_data_ln/null_test.txt' INTO TABLE t1 FIELDS ENCLOSED BY '"'; |
|
122 |
||
1
by brian
clean slate |
123 |
drop table t1; |
124 |
||
685.4.1
by Jay Pipes
Enabled the null.test. |
125 |
|
1
by brian
clean slate |
126 |
#
|
127 |
# Test to check elimination of IS NULL predicate for a non-nullable attribute |
|
128 |
# (bug #1990) |
|
129 |
#
|
|
130 |
create table t1 (a int not null, b int not null, index idx(a)); |
|
131 |
insert into t1 values |
|
132 |
(1,1), (2,2), (3,3), (4,4), (5,5), (6,6), |
|
133 |
(7,7), (8,8), (9,9), (10,10), (11,11), (12,12); |
|
134 |
explain select * from t1 where a between 2 and 3; |
|
135 |
explain select * from t1 where a between 2 and 3 or b is null; |
|
136 |
drop table t1; |
|
137 |
||
138 |
#
|
|
139 |
# IS NULL is unable to use index in range if column is declared not null |
|
140 |
# (Bug #4256) |
|
141 |
#
|
|
685.4.1
by Jay Pipes
Enabled the null.test. |
142 |
#create table t1(i int, key(i)); |
143 |
#insert into t1 values(1); |
|
144 |
#insert into t1 select i*2 from t1; |
|
145 |
#insert into t1 select i*2 from t1; |
|
146 |
#insert into t1 select i*2 from t1; |
|
147 |
#insert into t1 select i*2 from t1; |
|
148 |
#insert into t1 select i*2 from t1; |
|
149 |
#insert into t1 select i*2 from t1; |
|
150 |
#insert into t1 select i*2 from t1; |
|
151 |
#insert into t1 select i*2 from t1; |
|
152 |
#insert into t1 select i*2 from t1; |
|
153 |
#insert into t1 values(null); |
|
154 |
#explain select * from t1 where i=2 or i is null; |
|
155 |
#select count(*) from t1 where i=2 or i is null; |
|
156 |
# @TODO Fails with error 1265 on line 128. Bug? |
|
157 |
#alter table t1 change i i int not null; |
|
158 |
#explain select * from t1 where i=2 or i is null; |
|
159 |
#select count(*) from t1 where i=2 or i is null; |
|
160 |
#drop table t1; |
|
1
by brian
clean slate |
161 |
|
162 |
#
|
|
163 |
# NULL has its own type BINARY(0) by default. |
|
164 |
# But NULL should be weaker than a constant |
|
165 |
# when mixing charsets/collations |
|
166 |
#
|
|
167 |
# Check that result type is taken from a non-null string |
|
168 |
create table t1 select |
|
169 |
null as c00, |
|
170 |
if(1, null, 'string') as c01, |
|
171 |
if(0, null, 'string') as c02, |
|
172 |
ifnull(null, 'string') as c03, |
|
173 |
ifnull('string', null) as c04, |
|
174 |
case when 0 then null else 'string' end as c05, |
|
175 |
case when 1 then null else 'string' end as c06, |
|
176 |
coalesce(null, 'string') as c07, |
|
177 |
coalesce('string', null) as c08, |
|
178 |
least('string',null) as c09, |
|
179 |
least(null, 'string') as c10, |
|
180 |
greatest('string',null) as c11, |
|
181 |
greatest(null, 'string') as c12, |
|
182 |
nullif('string', null) as c13, |
|
183 |
nullif(null, 'string') as c14, |
|
184 |
trim('string' from null) as c15, |
|
185 |
trim(null from 'string') as c16, |
|
186 |
substring_index('string', null, 1) as c17, |
|
187 |
substring_index(null, 'string', 1) as c18, |
|
188 |
elt(1, null, 'string') as c19, |
|
189 |
elt(1, 'string', null) as c20, |
|
190 |
concat('string', null) as c21, |
|
191 |
concat(null, 'string') as c22, |
|
192 |
concat_ws('sep', 'string', null) as c23, |
|
193 |
concat_ws('sep', null, 'string') as c24, |
|
194 |
concat_ws(null, 'string', 'string') as c25, |
|
195 |
make_set(3, 'string', null) as c26, |
|
196 |
make_set(3, null, 'string') as c27, |
|
197 |
export_set(3, null, 'off', 'sep') as c29, |
|
198 |
export_set(3, 'on', null, 'sep') as c30, |
|
199 |
export_set(3, 'on', 'off', null) as c31, |
|
200 |
replace(null, 'from', 'to') as c32, |
|
201 |
replace('str', null, 'to') as c33, |
|
202 |
replace('str', 'from', null) as c34, |
|
203 |
insert('str', 1, 2, null) as c35, |
|
204 |
insert(null, 1, 2, 'str') as c36, |
|
205 |
lpad('str', 10, null) as c37, |
|
206 |
rpad(null, 10, 'str') as c38; |
|
207 |
||
942.3.1
by Vladimir Kolesnikov
test generalizations |
208 |
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
|
1
by brian
clean slate |
209 |
show create table t1; |
210 |
drop table t1; |
|
211 |
||
212 |
#
|
|
213 |
# Check that comparison is done according to |
|
214 |
# non-null string collation, i.e. case insensitively, |
|
215 |
# rather than according to NULL's collation, i.e. case sensitively |
|
216 |
#
|
|
217 |
# in field
|
|
218 |
select
|
|
219 |
case 'str' when 'STR' then 'str' when null then 'null' end as c01, |
|
220 |
case 'str' when null then 'null' when 'STR' then 'str' end as c02, |
|
221 |
field(null, 'str1', 'str2') as c03, |
|
222 |
field('str1','STR1', null) as c04, |
|
223 |
field('str1', null, 'STR1') as c05, |
|
224 |
'string' in ('STRING', null) as c08, |
|
225 |
'string' in (null, 'STRING') as c09; |
|
226 |
||
227 |
#
|
|
228 |
# Bug#19145: mysqld crashes if you set the default value of an enum field to NULL
|
|
229 |
#
|
|
685.4.1
by Jay Pipes
Enabled the null.test. |
230 |
#create table bug19145a (e enum('a','b','c') default 'b' , s set('x', 'y', 'z') default 'y' ) engine=MyISAM; |
231 |
#create table bug19145b (e enum('a','b','c') default null, s set('x', 'y', 'z') default null) engine=MyISAM; |
|
232 |
||
233 |
#create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM; |
|
234 |
||
235 |
# Invalid default value for 's' |
|
236 |
#--error 1067
|
|
237 |
#create table bug19145setnotnulldefaultnull (e enum('a','b','c') default null, s set('x', 'y', 'z') not null default null) engine=MyISAM; |
|
238 |
||
239 |
# Invalid default value for 'e' |
|
240 |
#--error 1067
|
|
241 |
#create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z') default null) engine=MyISAM; |
|
242 |
||
243 |
#alter table bug19145a alter column e set default null;
|
|
244 |
#alter table bug19145a alter column s set default null;
|
|
245 |
#alter table bug19145a add column (i int);
|
|
246 |
||
247 |
#alter table bug19145b alter column e set default null;
|
|
248 |
#alter table bug19145b alter column s set default null;
|
|
249 |
#alter table bug19145b add column (i int);
|
|
250 |
||
251 |
# Invalid default value for 'e' |
|
252 |
#--error 1067
|
|
253 |
#alter table bug19145c alter column e set default null;
|
|
254 |
||
255 |
# Invalid default value for 's' |
|
256 |
#--error 1067
|
|
257 |
#alter table bug19145c alter column s set default null;
|
|
258 |
#alter table bug19145c add column (i int);
|
|
259 |
||
260 |
#show create table bug19145a;
|
|
261 |
#show create table bug19145b;
|
|
262 |
#show create table bug19145c;
|
|
263 |
||
264 |
#drop table bug19145a;
|
|
265 |
#drop table bug19145b;
|
|
266 |
#drop table bug19145c;
|
|
1
by brian
clean slate |
267 |
|
268 |
--echo # End of 4.1 tests
|
|
269 |
||
270 |
--echo #
|
|
271 |
--echo # Bug #31471: decimal_bin_size: Assertion `scale >= 0 &&
|
|
272 |
--echo # precision > 0 && scale <= precision'
|
|
273 |
--echo #
|
|
274 |
||
685.4.1
by Jay Pipes
Enabled the null.test. |
275 |
CREATE TABLE t1 (a DECIMAL (1, 0) , b DECIMAL (1, 0) ); |
1
by brian
clean slate |
276 |
INSERT INTO t1 (a, b) VALUES (0, 0); |
277 |
||
278 |
CREATE TABLE t2 SELECT IFNULL(a, b) FROM t1; |
|
279 |
DESCRIBE t2; |
|
280 |
DROP TABLE t2; |
|
281 |
||
282 |
CREATE TABLE t2 SELECT IFNULL(a, NULL) FROM t1; |
|
283 |
DESCRIBE t2; |
|
284 |
DROP TABLE t2; |
|
285 |
||
286 |
CREATE TABLE t2 SELECT IFNULL(NULL, b) FROM t1; |
|
287 |
DESCRIBE t2; |
|
288 |
||
289 |
DROP TABLE t1, t2; |
|
290 |
||
291 |
--echo # End of 5.0 tests
|