2
2
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;
3
3
NULL NULL 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
4
4
NULL NULL 1 1 1 1 TRUE TRUE 1 1
6
Error 1365 Division by 0
7
Error 1365 Division by 0
8
Error 1365 Division by 0
5
9
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;
6
10
id select_type table type possible_keys key key_len ref rows filtered Extra
7
11
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
13
Error 1365 Division by 0
14
Error 1365 Division by 0
15
Error 1365 Division by 0
9
16
Note 1003 select NULL AS `NULL`,NULL AS `NULL`,isnull(NULL) AS `isnull(null)`,isnull((1 / 0)) AS `isnull(1/0)`,isnull(((1 / 0) = NULL)) AS `isnull(1/0 = null)`,ifnull(NULL,1) AS `ifnull(null,1)`,ifnull(NULL,'TRUE') AS `ifnull(null,"TRUE")`,ifnull('TRUE','ERROR') AS `ifnull("TRUE","ERROR")`,isnull((1 / 0)) AS `1/0 is null`,(1 is not null) AS `1 is not null`
10
select 1 | NULL,1 & NULL,1+NULL,1-NULL;
11
1 | NULL 1 & NULL 1+NULL 1-NULL
17
select CONCAT(1, NULL),1+NULL,1-NULL;
18
CONCAT(1, NULL) 1+NULL 1-NULL
20
select NULL=NULL,NULL<>NULL,IFNULL(NULL,1.1)+0,CONCAT(IFNULL(NULL,1), 0);
21
NULL=NULL NULL<>NULL IFNULL(NULL,1.1)+0 CONCAT(IFNULL(NULL,1), 0)
23
select strcmp("a",NULL),(1<NULL)+0.0,null like "a%","a%" like null;
24
strcmp("a",NULL) (1<NULL)+0.0 null like "a%" "a%" like null
12
25
NULL NULL NULL NULL
13
select NULL=NULL,NULL<>NULL,IFNULL(NULL,1.1)+0,IFNULL(NULL,1) | 0;
14
NULL=NULL NULL<>NULL IFNULL(NULL,1.1)+0 IFNULL(NULL,1) | 0
16
select strcmp("a",NULL),(1<NULL)+0.0,NULL regexp "a",null like "a%","a%" like null;
17
strcmp("a",NULL) (1<NULL)+0.0 NULL regexp "a" null like "a%" "a%" like null
18
NULL NULL NULL NULL NULL
19
26
select concat("a",NULL),replace(NULL,"a","b"),replace("string","i",NULL),replace("string",NULL,"i"),insert("abc",1,1,NULL),left(NULL,1);
20
27
concat("a",NULL) replace(NULL,"a","b") replace("string","i",NULL) replace("string",NULL,"i") insert("abc",1,1,NULL) left(NULL,1)
21
28
NULL NULL NULL NULL NULL NULL
42
49
select NULL AND 0, 0 and NULL;
43
50
NULL AND 0 0 and NULL
45
select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
46
inet_ntoa(null) inet_aton(null) inet_aton("122.256") inet_aton("122.226.") inet_aton("")
47
NULL NULL NULL NULL NULL
48
explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
49
id select_type table type possible_keys key key_len ref rows filtered Extra
50
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
52
Note 1003 select inet_ntoa(NULL) AS `inet_ntoa(null)`,inet_aton(NULL) AS `inet_aton(null)`,inet_aton('122.256') AS `inet_aton("122.256")`,inet_aton('122.226.') AS `inet_aton("122.226.")`,inet_aton('') AS `inet_aton("")`
53
52
create table t1 (x int);
54
53
insert into t1 values (null);
55
54
select * from t1 where x != 0;
91
CREATE TABLE t1 (a varchar(16) NOT NULL default '', b smallint(6) NOT NULL default 0, c datetime NOT NULL default '0000-00-00 00:00:00', d smallint(6) NOT NULL default 0);
92
INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55";
94
Warning 1265 Data truncated for column 'd' at row 1
95
UPDATE t1 SET d=1/NULL;
96
ERROR 23000: Column 'd' cannot be null
98
ERROR 23000: Column 'd' cannot be null
90
CREATE TABLE t1 (a varchar(16) NOT NULL default '', b int NOT NULL default 0, c datetime NOT NULL default '0000-00-00 00:00:00', d int NOT NULL default 0);
99
91
INSERT INTO t1 (a) values (null);
100
92
ERROR 23000: Column 'a' cannot be null
101
93
INSERT INTO t1 (a) values (1/null);
102
94
ERROR 23000: Column 'a' cannot be null
103
95
INSERT INTO t1 (a) values (null),(null);
105
Warning 1048 Column 'a' cannot be null
106
Warning 1048 Column 'a' cannot be null
96
ERROR 23000: Column 'a' cannot be null
107
97
INSERT INTO t1 (b) values (null);
108
98
ERROR 23000: Column 'b' cannot be null
109
99
INSERT INTO t1 (b) values (1/null);
110
100
ERROR 23000: Column 'b' cannot be null
111
101
INSERT INTO t1 (b) values (null),(null);
113
Warning 1048 Column 'b' cannot be null
114
Warning 1048 Column 'b' cannot be null
102
ERROR 23000: Column 'b' cannot be null
115
103
INSERT INTO t1 (c) values (null);
116
104
ERROR 23000: Column 'c' cannot be null
117
105
INSERT INTO t1 (c) values (1/null);
118
106
ERROR 23000: Column 'c' cannot be null
119
107
INSERT INTO t1 (c) values (null),(null);
121
Warning 1048 Column 'c' cannot be null
122
Warning 1048 Column 'c' cannot be null
108
ERROR 23000: Column 'c' cannot be null
123
109
INSERT INTO t1 (d) values (null);
124
110
ERROR 23000: Column 'd' cannot be null
125
111
INSERT INTO t1 (d) values (1/null);
126
112
ERROR 23000: Column 'd' cannot be null
127
113
INSERT INTO t1 (d) values (null),(null);
129
Warning 1048 Column 'd' cannot be null
130
Warning 1048 Column 'd' cannot be null
133
0 0000-00-00 00:00:00 2003
134
0 0000-00-00 00:00:00 0
135
0 0000-00-00 00:00:00 0
136
0 0000-00-00 00:00:00 0
137
0 0000-00-00 00:00:00 0
138
0 0000-00-00 00:00:00 0
139
0 0000-00-00 00:00:00 0
140
0 0000-00-00 00:00:00 0
141
0 0000-00-00 00:00:00 0
114
ERROR 23000: Column 'd' cannot be null
115
UPDATE t1 SET d= NULL;
116
INSERT INTO t1 VALUES ();
117
UPDATE t1 SET a=1/NULL;
118
ERROR 23000: Column 'a' cannot be null
119
UPDATE t1 SET a=NULL;
120
ERROR 23000: Column 'a' cannot be null
121
UPDATE t1 SET b=NULL;
122
ERROR 23000: Column 'b' cannot be null
123
UPDATE t1 SET c=NULL;
124
ERROR 23000: Column 'c' cannot be null
125
UPDATE t1 SET d=NULL;
126
ERROR 23000: Column 'd' cannot be null
128
LOAD DATA INFILE '../std_data_ln/null_test.txt' INTO TABLE t1 FIELDS ENCLOSED BY '"';
129
ERROR 22004: Column set to default value; NULL supplied to NOT NULL column 'a' at row 1
143
131
create table t1 (a int not null, b int not null, index idx(a));
144
132
insert into t1 values
146
134
(7,7), (8,8), (9,9), (10,10), (11,11), (12,12);
147
135
explain select * from t1 where a between 2 and 3;
148
136
id select_type table type possible_keys key key_len ref rows Extra
149
1 SIMPLE t1 range idx idx 4 NULL 2 Using index condition; Using MRR
137
1 SIMPLE t1 range idx idx 4 NULL 2 Using where; Using MRR
150
138
explain select * from t1 where a between 2 and 3 or b is null;
151
139
id select_type table type possible_keys key key_len ref rows Extra
152
1 SIMPLE t1 range idx idx 4 NULL 2 Using index condition; Using MRR
154
select cast(NULL as signed);
157
create table t1(i int, key(i));
158
insert into t1 values(1);
159
insert into t1 select i*2 from t1;
160
insert into t1 select i*2 from t1;
161
insert into t1 select i*2 from t1;
162
insert into t1 select i*2 from t1;
163
insert into t1 select i*2 from t1;
164
insert into t1 select i*2 from t1;
165
insert into t1 select i*2 from t1;
166
insert into t1 select i*2 from t1;
167
insert into t1 select i*2 from t1;
168
insert into t1 values(null);
169
explain select * from t1 where i=2 or i is null;
170
id select_type table type possible_keys key key_len ref rows Extra
171
1 SIMPLE t1 ref_or_null i i 5 const 9 Using index
172
select count(*) from t1 where i=2 or i is null;
175
alter table t1 change i i int not null;
177
Warning 1265 Data truncated for column 'i' at row 513
178
explain select * from t1 where i=2 or i is null;
179
id select_type table type possible_keys key key_len ref rows Extra
180
1 SIMPLE t1 ref i i 4 const 7 Using index
181
select count(*) from t1 where i=2 or i is null;
140
1 SIMPLE t1 range idx idx 4 NULL 2 Using where; Using MRR
186
142
create table t1 select
188
144
if(1, null, 'string') as c01,
225
181
show create table t1;
226
182
Table Create Table
227
183
t1 CREATE TABLE `t1` (
228
`c00` binary(0) DEFAULT NULL,
229
`c01` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
230
`c02` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
231
`c03` varchar(6) CHARACTER SET latin2 NOT NULL DEFAULT '',
232
`c04` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
233
`c05` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
234
`c06` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
235
`c07` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
236
`c08` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
237
`c09` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
238
`c10` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
239
`c11` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
240
`c12` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
241
`c13` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
242
`c14` char(0) CHARACTER SET latin2 DEFAULT NULL,
243
`c15` char(0) CHARACTER SET latin2 DEFAULT NULL,
244
`c16` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
245
`c17` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
246
`c18` char(0) CHARACTER SET latin2 DEFAULT NULL,
247
`c19` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
248
`c20` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
249
`c21` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
250
`c22` varchar(6) CHARACTER SET latin2 DEFAULT NULL,
251
`c23` varchar(9) CHARACTER SET latin2 DEFAULT NULL,
252
`c24` varchar(9) CHARACTER SET latin2 DEFAULT NULL,
253
`c25` varchar(12) CHARACTER SET latin2 DEFAULT NULL,
254
`c26` varchar(7) CHARACTER SET latin2 DEFAULT NULL,
255
`c27` varchar(7) CHARACTER SET latin2 DEFAULT NULL,
256
`c29` varchar(381) CHARACTER SET latin2 DEFAULT NULL,
257
`c30` varchar(317) CHARACTER SET latin2 DEFAULT NULL,
258
`c31` varchar(192) CHARACTER SET latin2 DEFAULT NULL,
259
`c32` char(0) CHARACTER SET latin2 DEFAULT NULL,
260
`c33` varchar(3) CHARACTER SET latin2 DEFAULT NULL,
261
`c34` varchar(3) CHARACTER SET latin2 DEFAULT NULL,
262
`c35` varchar(3) CHARACTER SET latin2 DEFAULT NULL,
263
`c36` varchar(3) CHARACTER SET latin2 DEFAULT NULL,
264
`c37` varchar(10) CHARACTER SET latin2 DEFAULT NULL,
265
`c38` varchar(10) CHARACTER SET latin2 DEFAULT NULL
266
) ENGINE=MyISAM DEFAULT CHARSET=latin1
187
`c03` varchar(6) NOT NULL,
269
225
case 'str' when 'STR' then 'str' when null then 'null' end as c01,
275
231
'string' in (null, 'STRING') as c09;
276
232
c01 c02 c03 c04 c05 c08 c09
277
233
str str 0 1 2 1 1
279
create table bug19145a (e enum('a','b','c') default 'b' , s set('x', 'y', 'z') default 'y' ) engine=MyISAM;
280
create table bug19145b (e enum('a','b','c') default null, s set('x', 'y', 'z') default null) engine=MyISAM;
281
create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM;
282
create table bug19145setnotnulldefaultnull (e enum('a','b','c') default null, s set('x', 'y', 'z') not null default null) engine=MyISAM;
283
ERROR 42000: Invalid default value for 's'
284
create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z') default null) engine=MyISAM;
285
ERROR 42000: Invalid default value for 'e'
286
alter table bug19145a alter column e set default null;
287
alter table bug19145a alter column s set default null;
288
alter table bug19145a add column (i int);
289
alter table bug19145b alter column e set default null;
290
alter table bug19145b alter column s set default null;
291
alter table bug19145b add column (i int);
292
alter table bug19145c alter column e set default null;
293
ERROR 42000: Invalid default value for 'e'
294
alter table bug19145c alter column s set default null;
295
ERROR 42000: Invalid default value for 's'
296
alter table bug19145c add column (i int);
297
show create table bug19145a;
299
bug19145a CREATE TABLE `bug19145a` (
300
`e` enum('a','b','c') DEFAULT NULL,
301
`s` set('x','y','z') DEFAULT NULL,
302
`i` int(11) DEFAULT NULL
303
) ENGINE=MyISAM DEFAULT CHARSET=latin1
304
show create table bug19145b;
306
bug19145b CREATE TABLE `bug19145b` (
307
`e` enum('a','b','c') DEFAULT NULL,
308
`s` set('x','y','z') DEFAULT NULL,
309
`i` int(11) DEFAULT NULL
310
) ENGINE=MyISAM DEFAULT CHARSET=latin1
311
show create table bug19145c;
313
bug19145c CREATE TABLE `bug19145c` (
314
`e` enum('a','b','c') NOT NULL DEFAULT 'b',
315
`s` set('x','y','z') NOT NULL DEFAULT 'y',
316
`i` int(11) DEFAULT NULL
317
) ENGINE=MyISAM DEFAULT CHARSET=latin1
318
drop table bug19145a;
319
drop table bug19145b;
320
drop table bug19145c;
321
234
# End of 4.1 tests
323
236
# Bug #31471: decimal_bin_size: Assertion `scale >= 0 &&
324
237
# precision > 0 && scale <= precision'
326
CREATE TABLE t1 (a DECIMAL (1, 0) ZEROFILL, b DECIMAL (1, 0) ZEROFILL);
239
CREATE TABLE t1 (a DECIMAL (1, 0) , b DECIMAL (1, 0) );
327
240
INSERT INTO t1 (a, b) VALUES (0, 0);
328
241
CREATE TABLE t2 SELECT IFNULL(a, b) FROM t1;
330
243
Field Type Null Key Default Extra
331
IFNULL(a, b) decimal(1,0) unsigned YES NULL
244
IFNULL(a, b) decimal(1,0) YES NULL
333
246
CREATE TABLE t2 SELECT IFNULL(a, NULL) FROM t1;