10
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
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;
12
select 1 | NULL,1 & NULL,1+NULL,1-NULL;
13
select NULL=NULL,NULL<>NULL,IFNULL(NULL,1.1)+0,IFNULL(NULL,1) | 0;
14
select strcmp("a",NULL),(1<NULL)+0.0,NULL regexp "a",null like "a%","a%" like null;
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;
15
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
16
select repeat("a",0),repeat("ab",5+5),repeat("ab",-1),reverse(NULL);
17
17
select field(NULL,"a","b","c");
20
20
SELECT NULL AND NULL, 1 AND NULL, NULL AND 1, NULL OR NULL, 0 OR NULL, NULL OR 0;
21
21
SELECT (NULL OR NULL) IS NULL;
22
22
select NULL AND 0, 0 and NULL;
23
select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
24
explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
23
# @TODO Move to functions/inet_ntoa.test when INET_NTOA function is
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("");
26
28
create table t1 (x int);
27
29
insert into t1 values (null);
60
62
# Test inserting and updating with NULL
62
CREATE TABLE t1 (a varchar(16) NOT NULL default '', b int(6) NOT NULL default 0, c datetime NOT NULL default '0000-00-00 00:00:00', d int(6) NOT NULL default 0);
63
INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55";
65
UPDATE t1 SET d=1/NULL;
64
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);
66
# Test INSERT with NULL
69
69
INSERT INTO t1 (a) values (null);
71
71
INSERT INTO t1 (a) values (1/null);
72
73
INSERT INTO t1 (a) values (null),(null);
74
75
INSERT INTO t1 (b) values (null);
76
77
INSERT INTO t1 (b) values (1/null);
77
79
INSERT INTO t1 (b) values (null),(null);
79
81
INSERT INTO t1 (c) values (null);
81
83
INSERT INTO t1 (c) values (1/null);
82
85
INSERT INTO t1 (c) values (null),(null);
84
87
INSERT INTO t1 (d) values (null);
86
89
INSERT INTO t1 (d) values (1/null);
87
91
INSERT INTO t1 (d) values (null),(null);
93
# Test UPDATE with NULLs
95
# The following should not error since there
96
# are no rows in the table.
97
UPDATE t1 SET d= NULL;
99
# Insert a default row in order to test UPDATE to NULL error
100
INSERT INTO t1 VALUES ();
103
UPDATE t1 SET a=1/NULL;
105
UPDATE t1 SET a=NULL;
107
UPDATE t1 SET b=NULL;
109
UPDATE t1 SET c=NULL;
111
UPDATE t1 SET d=NULL;
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?
121
LOAD DATA INFILE '../std_data_ln/null_test.txt' INTO TABLE t1 FIELDS ENCLOSED BY '"';
92
127
# Test to check elimination of IS NULL predicate for a non-nullable attribute
99
134
explain select * from t1 where a between 2 and 3;
100
135
explain select * from t1 where a between 2 and 3 or b is null;
102
select cast(NULL as signed);
105
139
# IS NULL is unable to use index in range if column is declared not null
108
create table t1(i int, key(i));
109
insert into t1 values(1);
110
insert into t1 select i*2 from t1;
111
insert into t1 select i*2 from t1;
112
insert into t1 select i*2 from t1;
113
insert into t1 select i*2 from t1;
114
insert into t1 select i*2 from t1;
115
insert into t1 select i*2 from t1;
116
insert into t1 select i*2 from t1;
117
insert into t1 select i*2 from t1;
118
insert into t1 select i*2 from t1;
119
insert into t1 values(null);
120
explain select * from t1 where i=2 or i is null;
121
select count(*) from t1 where i=2 or i is null;
122
alter table t1 change i i int not null;
123
explain select * from t1 where i=2 or i is null;
124
select count(*) from t1 where i=2 or i is null;
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;
128
163
# NULL has its own type BINARY(0) by default.
129
164
# But NULL should be weaker than a constant
130
165
# when mixing charsets/collations
133
167
# Check that result type is taken from a non-null string
134
168
create table t1 select
189
223
'string' in ('STRING', null) as c08,
190
224
'string' in (null, 'STRING') as c09;
192
# Restore charset to the default value.
196
227
# Bug#19145: mysqld crashes if you set the default value of an enum field to NULL
198
create table bug19145a (e enum('a','b','c') default 'b' , s set('x', 'y', 'z') default 'y' ) engine=MyISAM;
199
create table bug19145b (e enum('a','b','c') default null, s set('x', 'y', 'z') default null) engine=MyISAM;
201
create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM;
203
# Invalid default value for 's'
205
create table bug19145setnotnulldefaultnull (e enum('a','b','c') default null, s set('x', 'y', 'z') not null default null) engine=MyISAM;
207
# Invalid default value for 'e'
209
create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z') default null) engine=MyISAM;
211
alter table bug19145a alter column e set default null;
212
alter table bug19145a alter column s set default null;
213
alter table bug19145a add column (i int);
215
alter table bug19145b alter column e set default null;
216
alter table bug19145b alter column s set default null;
217
alter table bug19145b add column (i int);
219
# Invalid default value for 'e'
221
alter table bug19145c alter column e set default null;
223
# Invalid default value for 's'
225
alter table bug19145c alter column s set default null;
226
alter table bug19145c add column (i int);
228
show create table bug19145a;
229
show create table bug19145b;
230
show create table bug19145c;
232
drop table bug19145a;
233
drop table bug19145b;
234
drop table bug19145c;
229
#create table bug19145a (e enum('a','b','c') default 'b' , s set('x', 'y', 'z') default 'y' ) engine=MyISAM;
230
#create table bug19145b (e enum('a','b','c') default null, s set('x', 'y', 'z') default null) engine=MyISAM;
232
#create table bug19145c (e enum('a','b','c') not null default 'b' , s set('x', 'y', 'z') not null default 'y' ) engine=MyISAM;
234
# Invalid default value for 's'
236
#create table bug19145setnotnulldefaultnull (e enum('a','b','c') default null, s set('x', 'y', 'z') not null default null) engine=MyISAM;
238
# Invalid default value for 'e'
240
#create table bug19145enumnotnulldefaultnull (e enum('a','b','c') not null default null, s set('x', 'y', 'z') default null) engine=MyISAM;
242
#alter table bug19145a alter column e set default null;
243
#alter table bug19145a alter column s set default null;
244
#alter table bug19145a add column (i int);
246
#alter table bug19145b alter column e set default null;
247
#alter table bug19145b alter column s set default null;
248
#alter table bug19145b add column (i int);
250
# Invalid default value for 'e'
252
#alter table bug19145c alter column e set default null;
254
# Invalid default value for 's'
256
#alter table bug19145c alter column s set default null;
257
#alter table bug19145c add column (i int);
259
#show create table bug19145a;
260
#show create table bug19145b;
261
#show create table bug19145c;
263
#drop table bug19145a;
264
#drop table bug19145b;
265
#drop table bug19145c;
236
267
--echo # End of 4.1 tests