null.result 7.98 KB
Newer Older
1
drop table if exists t1;
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 4
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
NULL	NULL	1	1	1	1	TRUE	TRUE	1	1
5 6 7 8
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;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
Warnings:
9
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,_latin1'TRUE') AS `ifnull(null,"TRUE")`,ifnull(_latin1'TRUE',_latin1'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 12
1 | NULL	1 & NULL	1+NULL	1-NULL
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
15
NULL	NULL	1.1	1
16
select strcmp("a",NULL),(1<NULL)+0.0,NULL regexp "a",null like "a%","a%" like null;
17 18
strcmp("a",NULL)	(1<NULL)+0.0	NULL regexp "a"	null like "a%"	"a%" like null
NULL	NULL	NULL	NULL	NULL
19
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 21
concat("a",NULL)	replace(NULL,"a","b")	replace("string","i",NULL)	replace("string",NULL,"i")	insert("abc",1,1,NULL)	left(NULL,1)
NULL	NULL	NULL	NULL	NULL	NULL
22
select repeat("a",0),repeat("ab",5+5),repeat("ab",-1),reverse(NULL);
23 24
repeat("a",0)	repeat("ab",5+5)	repeat("ab",-1)	reverse(NULL)
	abababababababababab		NULL
25
select field(NULL,"a","b","c");
26 27
field(NULL,"a","b","c")
0
28
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;
29 30
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
0	0	NULL	NULL	NULL
31 32 33 34
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;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
Warnings:
35
Note	1003	select (2 between NULL and 1) AS `2 between null and 1`,(2 between 3 and NULL) AS `2 between 3 AND NULL`,(NULL between 1 and 2) AS `NULL between 1 and 2`,(2 between NULL and 3) AS `2 between NULL and 3`,(2 between 1 and NULL) AS `2 between 1 AND null`
36
SELECT NULL AND NULL, 1 AND NULL, NULL AND 1, NULL OR NULL, 0 OR NULL, NULL OR 0;
37 38
NULL AND NULL	1 AND NULL	NULL AND 1	NULL OR NULL	0 OR NULL	NULL OR 0
NULL	NULL	NULL	NULL	NULL	NULL
39
SELECT (NULL OR NULL) IS NULL;
40 41
(NULL OR NULL) IS NULL
1
42
select NULL AND 0, 0 and NULL;
43
NULL AND 0	0 and NULL
44
0	0
45
select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
46 47
inet_ntoa(null)	inet_aton(null)	inet_aton("122.256")	inet_aton("122.226.")	inet_aton("")
NULL	NULL	NULL	NULL	NULL
48 49 50 51
explain extended select inet_ntoa(null),inet_aton(null),inet_aton("122.256"),inet_aton("122.226."),inet_aton("");
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
Warnings:
52
Note	1003	select inet_ntoa(NULL) AS `inet_ntoa(null)`,inet_aton(NULL) AS `inet_aton(null)`,inet_aton(_latin1'122.256') AS `inet_aton("122.256")`,inet_aton(_latin1'122.226.') AS `inet_aton("122.226.")`,inet_aton(_latin1'') AS `inet_aton("")`
53 54 55
create table t1 (x int);
insert into t1 values (null);
select * from t1 where x != 0;
56
x
57
drop table t1;
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
CREATE TABLE t1 (
indexed_field int default NULL,
KEY indexed_field (indexed_field)
);
INSERT INTO t1 VALUES (NULL),(NULL);
SELECT * FROM t1 WHERE indexed_field=NULL;
indexed_field
SELECT * FROM t1 WHERE indexed_field IS NULL;
indexed_field
NULL
NULL
SELECT * FROM t1 WHERE indexed_field<=>NULL;
indexed_field
NULL
NULL
DROP TABLE t1;
74
create table t1 (a int, b int) engine=myisam;
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
insert into t1 values(20,null);
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
t2.b=t3.a;
b	ifnull(t2.b,"this is null")
NULL	this is null
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
t2.b=t3.a order by 1;
b	ifnull(t2.b,"this is null")
NULL	this is null
insert into t1 values(10,null);
select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
t2.b=t3.a order by 1;
b	ifnull(t2.b,"this is null")
NULL	this is null
NULL	this is null
drop table t1;
91 92
CREATE TABLE t1 (a varchar(16) NOT NULL, b smallint(6) NOT NULL, c datetime NOT NULL, d smallint(6) NOT NULL);
INSERT INTO t1 SET a = "", d= "2003-01-14 03:54:55";
93
Warnings:
monty@mysql.com's avatar
monty@mysql.com committed
94
Warning	1265	Data truncated for column 'd' at row 1
95
UPDATE t1 SET d=1/NULL;
venu@myvenu.com's avatar
venu@myvenu.com committed
96
Warnings:
monty@mysql.com's avatar
monty@mysql.com committed
97
Warning	1265	Data truncated for column 'd' at row 1
98
UPDATE t1 SET d=NULL;
venu@myvenu.com's avatar
venu@myvenu.com committed
99
Warnings:
100
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'd' at row 1
101
INSERT INTO t1 (a) values (null);
102
ERROR 23000: Column 'a' cannot be null
103
INSERT INTO t1 (a) values (1/null);
104
ERROR 23000: Column 'a' cannot be null
105
INSERT INTO t1 (a) values (null),(null);
venu@myvenu.com's avatar
venu@myvenu.com committed
106
Warnings:
107 108
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'a' at row 1
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'a' at row 2
109
INSERT INTO t1 (b) values (null);
110
ERROR 23000: Column 'b' cannot be null
111
INSERT INTO t1 (b) values (1/null);
112
ERROR 23000: Column 'b' cannot be null
113
INSERT INTO t1 (b) values (null),(null);
venu@myvenu.com's avatar
venu@myvenu.com committed
114
Warnings:
115 116
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'b' at row 1
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'b' at row 2
117
INSERT INTO t1 (c) values (null);
118
ERROR 23000: Column 'c' cannot be null
119
INSERT INTO t1 (c) values (1/null);
120
ERROR 23000: Column 'c' cannot be null
121
INSERT INTO t1 (c) values (null),(null);
venu@myvenu.com's avatar
venu@myvenu.com committed
122
Warnings:
123 124
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'c' at row 1
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'c' at row 2
125
INSERT INTO t1 (d) values (null);
126
ERROR 23000: Column 'd' cannot be null
127
INSERT INTO t1 (d) values (1/null);
128
ERROR 23000: Column 'd' cannot be null
129
INSERT INTO t1 (d) values (null),(null);
venu@myvenu.com's avatar
venu@myvenu.com committed
130
Warnings:
131 132
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'd' at row 1
Warning	1263	Data truncated; NULL supplied to NOT NULL column 'd' at row 2
133 134 135 136 137 138 139 140 141 142 143 144
select * from t1;
a	b	c	d
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
	0	0000-00-00 00:00:00	0
drop table t1;
145 146 147 148 149 150 151 152 153 154 155
create table t1 (a int not null, b int not null, index idx(a));
insert into t1 values
(1,1), (2,2), (3,3), (4,4), (5,5), (6,6),
(7,7), (8,8), (9,9), (10,10), (11,11), (12,12);
explain select * from t1 where a between 2 and 3;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	idx	idx	4	NULL	2	Using where
explain select * from t1 where a between 2 and 3 or b is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	range	idx	idx	4	NULL	2	Using where
drop table t1;
156 157 158
select cast(NULL as signed);
cast(NULL as signed)
NULL
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
create table t1(i int, key(i));
insert into t1 values(1);
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
insert into t1 select i*2 from t1;
explain select * from t1 where i=2 or i is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref_or_null	i	i	5	const	10	Using where; Using index
alter table t1 change i i int not null;
explain select * from t1 where i=2 or i is null;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	ref	i	i	4	const	7	Using where; Using index
drop table t1;