1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
USE test;
#
# MDEV-14013 : sql_mode=EMPTY_STRING_IS_NULL
#
set @mode='EMPTY_STRING_IS_NULL';
SET SESSION character_set_connection=latin2;
SET SESSION character_set_client=cp1250;
#
# Test litteral
#
SET sql_mode=@mode;
select @@sql_mode;
@@sql_mode
EMPTY_STRING_IS_NULL
SELECT '',CHARSET(''), null, CHARSET(null), CAST(null as char(10)), CHARSET(CAST(null as char(10))), 'x', CHARSET('x');
NULL CHARSET('') NULL CHARSET(null) CAST(null as char(10)) CHARSET(CAST(null as char(10))) x CHARSET('x')
NULL latin2 NULL binary NULL latin2 x latin2
SELECT CHARSET(NULLIF('','')),NULLIF('','');
CHARSET(NULLIF('','')) NULLIF('','')
latin2 NULL
SET sql_mode=default;
SELECT '',CHARSET(''), null, CHARSET(null), CAST(null as char(10)), CHARSET(CAST(null as char(10))), 'x', CHARSET('x');
CHARSET('') NULL CHARSET(null) CAST(null as char(10)) CHARSET(CAST(null as char(10))) x CHARSET('x')
latin2 NULL binary NULL latin2 x latin2
SELECT CHARSET(NULLIF('','')),NULLIF('','');
CHARSET(NULLIF('','')) NULLIF('','')
latin2 NULL
#
# Test NCHAR litteral
#
SET sql_mode=@mode;
SELECT N'',CHARSET(N''), N'x', CHARSET(N'x');
NULL CHARSET(N'') x CHARSET(N'x')
NULL utf8mb3 x utf8mb3
SELECT CHARSET(NULLIF(N'',N'')),NULLIF(N'',N'');
CHARSET(NULLIF(N'',N'')) NULLIF(N'',N'')
utf8mb3 NULL
SET sql_mode=default;
SELECT N'',CHARSET(N''), N'x', CHARSET(N'x');
CHARSET(N'') x CHARSET(N'x')
utf8mb3 x utf8mb3
SELECT CHARSET(NULLIF(N'',N'')),NULLIF(N'',N'');
CHARSET(NULLIF(N'',N'')) NULLIF(N'',N'')
utf8mb3 NULL
#
# Test CHARSET prefix litteral
#
SET sql_mode=@mode;
SELECT _cp1250 '',CHARSET(_cp1250 ''), _cp1250 'x', CHARSET(_cp1250 'x');
NULL CHARSET(_cp1250 '') x CHARSET(_cp1250 'x')
NULL cp1250 x cp1250
SELECT CHARSET(NULLIF(_cp1250 '',_cp1250 '')),NULLIF(_cp1250 '',_cp1250 '');
CHARSET(NULLIF(_cp1250 '',_cp1250 '')) NULLIF(_cp1250 '',_cp1250 '')
cp1250 NULL
SET sql_mode=default;
SELECT _cp1250 '',CHARSET(_cp1250 ''), _cp1250 'x', CHARSET(_cp1250 'x');
CHARSET(_cp1250 '') x CHARSET(_cp1250 'x')
cp1250 x cp1250
SELECT CHARSET(NULLIF(_cp1250 '',_cp1250 '')),NULLIF(_cp1250 '',_cp1250 '');
CHARSET(NULLIF(_cp1250 '',_cp1250 '')) NULLIF(_cp1250 '',_cp1250 '')
cp1250 NULL
SET sql_mode=@mode;
#
# Test litteral concat
#
SELECT 'a' 'b';
a
ab
SELECT 'a' '';
a
a
SELECT '' 'b';
b
b
SELECT '' '';
NULL
NULL
SELECT '' 'b' 'c';
b
bc
SELECT '' '' 'c';
c
c
SELECT 'a' '' 'c';
a
ac
SELECT 'a' '' '';
a
a
SELECT '' '' '';
NULL
NULL
SELECT '' '' '',CHARSET('' '' '');
NULL CHARSET('' '' '')
NULL latin2
SELECT _latin1'' '' '',CHARSET(_latin1'' '' '');
NULL CHARSET(_latin1'' '' '')
NULL latin1
SELECT N'' '' '',CHARSET(N'' '' '');
NULL CHARSET(N'' '' '')
NULL utf8mb3
#
# UNION - implicit group by
#
SELECT 1, null
UNION
SELECT 1 , ''
ORDER BY 1;
1 NULL
1 NULL
SELECT 1, null
UNION
SELECT 1 , N''
ORDER BY 1;
1 NULL
1 NULL
SELECT 1, null
UNION
SELECT 1 , _cp1250 ''
ORDER BY 1;
1 NULL
1 NULL
SELECT NULLIF(_cp1250 '',_cp1250 '')
UNION
SELECT NULLIF(N'',N'');
NULLIF(_cp1250 '',_cp1250 '')
NULL
SELECT 1 , _latin2 ''
UNION
SELECT 1 , _cp1250 '';
ERROR HY000: Illegal mix of collations (latin2_general_ci,IGNORABLE) and (cp1250_general_ci,IGNORABLE) for operation 'UNION'
SELECT 1, null
UNION
SELECT 1 , ''
UNION
SELECT 1 , N'';
1 NULL
1 NULL
CREATE TABLE t1 (c1 INT,c2 VARCHAR(10));
INSERT INTO t1 VALUES (1,'one');
INSERT INTO t1 VALUES (1,'');
INSERT INTO t1 VALUES (1,null);
#
# Test in a view
#
CREATE VIEW v1
AS SELECT c1, c2
FROM t1
UNION
SELECT c1 , ''
FROM t1
ORDER BY 1,2;
SELECT * FROM v1;
c1 c2
1 NULL
1 one
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`c1` AS `c1`,`t1`.`c2` AS `c2` from `t1` union select `t1`.`c1` AS `c1`,NULL AS `NULL` from `t1` order by 1,2 cp1250 latin2_general_ci
DROP VIEW v1;
DROP TABLE t1;
EXPLAIN EXTENDED SELECT '';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select NULL AS `NULL`
EXPLAIN EXTENDED SELECT _latin1'';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select NULL AS `NULL`
EXPLAIN EXTENDED SELECT N'';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select NULL AS `NULL`
EXPLAIN EXTENDED SELECT '' '';
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select NULL AS `NULL`
#
# MDEV-20763 Table corruption or Assertion `btr_validate_index(index, 0, false)' failed in row_upd_sec_index_entry with virtual column and EMPTY_STRING_IS_NULL SQL mode
#
create table t1 (a int, b binary(1) generated always as (''), key(a,b));
insert into t1 (a) values (1);
set sql_mode= default;
flush tables;
update t1 set a = 2;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` binary(1) GENERATED ALWAYS AS (NULL) VIRTUAL,
KEY `a` (`a`,`b`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
create table t1 (a int, b binary(1) generated always as (''), key(a,b));
insert into t1 (a) values (1);
set sql_mode= 'empty_string_is_null';
flush tables;
update t1 set a = 2;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
`b` binary(1) GENERATED ALWAYS AS ('') VIRTUAL,
KEY `a` (`a`,`b`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
|