oceanbase
289 строк · 10.7 Кб
1--disable_query_log
2set @@session.explicit_defaults_for_timestamp=off;
3--enable_query_log
4# owner: luofan.zp
5# owner group: SQL3
6# description: collation of all expression operator
7# Author: zhuweng.yzf
8# ....yzf....Fri, 21 Aug 2015....17:55....
9
10# set-up
11--disable_warnings
12drop table if exists coll_test;
13--enable_warnings
14create table coll_test(pk bigint primary key, uc varchar(10) collate utf8_general_ci, ub varchar(10) collate utf8_bin, b varbinary(10));
15--source mysql_test/include/show_create_table_old_version.inc
16--source mysql_test/include/show_create_table_old_version_replica2.inc
17show create table coll_test;
18insert into coll_test values (1314, 'abc', 'def', 'xyz');
19select * from coll_test;
20################################################################
21# concat
22select collation(concat(null)) from coll_test;
23select collation(concat(uc, ub)) from coll_test;
24select collation(concat(uc, b)) from coll_test;
25select collation(concat(uc, x'41')) from coll_test;
26select collation(concat('abc', x'41')) from coll_test;
27select collation(concat('abc' collate utf8mb4_general_ci, x'41')) from coll_test;
28select collation(concat(1, 2)) from coll_test;
29# @bug collation is wrong for NULL result (zhuweng.yzf) ....yzf....Fri, 21 Aug 2015....18:17....
30select collation(concat(1, null)) from coll_test;
31
32# group_concat
33select collation(group_concat(null)) from coll_test;
34select collation(group_concat(uc, ub)) from coll_test;
35select collation(group_concat(uc, b)) from coll_test;
36select collation(group_concat(uc, x'41')) from coll_test;
37select collation(group_concat('abc', x'41')) from coll_test;
38select collation(group_concat('abc' collate utf8mb4_general_ci, x'41')) from coll_test;
39select collation(group_concat(1, 2)) from coll_test;
40select collation(group_concat(1, null)) from coll_test;
41
42# concat_ws
43select collation(concat_ws(',', null)) from coll_test;
44select collation(concat_ws(',', uc, ub)) from coll_test;
45select collation(concat_ws(',', uc, b)) from coll_test;
46select collation(concat_ws(',', uc, x'41')) from coll_test;
47select collation(concat_ws(',', 'abc', x'41')) from coll_test;
48select collation(concat_ws(',', 'abc' collate utf8mb4_general_ci, x'41')) from coll_test;
49select collation(concat_ws(',', 1, 2)) from coll_test;
50select collation(concat_ws(',', 1, null)) from coll_test;
51
52# reverse
53select collation(reverse(null)) from coll_test;
54select collation(reverse(uc)) from coll_test;
55select collation(reverse(ub)) from coll_test;
56select collation(reverse(b)) from coll_test;
57select collation(reverse(pk)) from coll_test;
58select collation(reverse(X'41')) from coll_test;
59
60# lower
61select collation(lower(null)) from coll_test;
62select collation(lower(uc)) from coll_test;
63select collation(lower(ub)) from coll_test;
64select collation(lower(b)) from coll_test;
65select collation(lower(pk)) from coll_test;
66select collation(lower(X'41')) from coll_test;
67
68# upper
69select collation(upper(null)) from coll_test;
70select collation(upper(uc)) from coll_test;
71select collation(upper(ub)) from coll_test;
72select collation(upper(b)) from coll_test;
73select collation(upper(pk)) from coll_test;
74select collation(upper(X'41')) from coll_test;
75
76# right
77select collation(right(null, 2)) from coll_test;
78select collation(right(uc, 2)) from coll_test;
79select collation(right(ub, 2)) from coll_test;
80select collation(right(b, 2)) from coll_test;
81select collation(right(pk, 2)) from coll_test;
82select collation(right(X'41', 2)) from coll_test;
83
84#substr
85select collation(substr(null, 2)) from coll_test;
86select collation(substr(uc, 2)) from coll_test;
87select collation(substr(ub, 2)) from coll_test;
88select collation(substr(b, 2)) from coll_test;
89select collation(substr(pk, 2)) from coll_test;
90select collation(substr(X'41', 2)) from coll_test;
91
92#trim
93select collation(trim('a' from null)) from coll_test;
94select collation(trim('a' from uc)) from coll_test;
95select collation(trim('a' from ub)) from coll_test;
96select collation(trim('a' from b)) from coll_test;
97select collation(trim('a' from pk)) from coll_test;
98select collation(trim('a' from X'41')) from coll_test;
99
100#repeat
101select collation(repeat(null, 2)) from coll_test;
102select collation(repeat(uc, 2)) from coll_test;
103select collation(repeat(ub, 2)) from coll_test;
104select collation(repeat(b, 2)) from coll_test;
105select collation(repeat(pk, 2)) from coll_test;
106select collation(repeat(X'41', 2)) from coll_test;
107
108# rpad
109select collation(rpad(null, 2, 'a')) from coll_test;
110select collation(rpad(uc, 2, ub)) from coll_test;
111select collation(rpad(ub, 2, b)) from coll_test;
112select collation(rpad(b, 2, uc)) from coll_test;
113select collation(rpad(pk, 2, uc)) from coll_test;
114select collation(rpad(X'41', 2, uc)) from coll_test;
115
116#replace
117select collation(replace(null, b, 'a')) from coll_test;
118select collation(replace(uc, b, ub)) from coll_test;
119select collation(replace(ub, uc, ub)) from coll_test;
120select collation(replace(uc, 'a', 'b')) from coll_test;
121select collation(replace(pk, 1, 2)) from coll_test;
122select collation(replace(X'41', 'a', 'b')) from coll_test;
123
124#replace
125select collation(replace(null, b, 'a')) from coll_test;
126select collation(replace(uc, b, ub)) from coll_test;
127select collation(replace(ub, uc, ub)) from coll_test;
128select collation(replace(uc, 'a', 'b')) from coll_test;
129select collation(replace(pk, 1, 2)) from coll_test;
130select collation(replace(X'41', 'a', 'b')) from coll_test;
131
132#substring_index
133select collation(substring_index(null, b, 2)) from coll_test;
134select collation(substring_index(uc, b, 2)) from coll_test;
135select collation(substring_index(ub, uc, 2)) from coll_test;
136select collation(substring_index(ub, b, 2)) from coll_test;
137select collation(substring_index(uc, 'a', 2)) from coll_test;
138select collation(substring_index(pk, 1, 2)) from coll_test;
139select collation(substring_index(X'41', 'a', 2)) from coll_test;
140
141# locate
142select cmp_meta(locate('b' collate utf8mb4_general_ci, 'aBc' collate utf8mb4_general_ci));
143select cmp_meta(locate('b' collate utf8mb4_bin, 'aBc' collate utf8mb4_bin));
144select cmp_meta(locate('b', 'aBc'));
145select cmp_meta(locate('b' collate utf8mb4_general_ci, 'aBc' collate utf8mb4_general_ci, 1));
146select cmp_meta(locate('b' collate utf8mb4_bin, 'aBc' collate utf8mb4_bin, 1));
147select cmp_meta(locate('b', 'aBc', 1));
148select cmp_meta(locate(uc, ub)) from coll_test;
149select cmp_meta(locate(uc, b)) from coll_test;
150select cmp_meta(locate(b, b)) from coll_test;
151select cmp_meta(locate(b, pk)) from coll_test;
152
153# instr
154select cmp_meta(instr('abc' collate utf8_bin, 'B' collate utf8_bin));
155select cmp_meta(instr('abc' collate utf8_general_ci, 'B' collate utf8_general_ci));
156select cmp_meta(instr('abc', 'B'));
157
158# current_user
159select collation(current_user());
160select coercibility(current_user());
161
162# database
163select collation(database());
164select coercibility(database());
165
166# conv
167select collation(conv(null, 10, 8));
168select collation(conv(1024, 10, 8));
169
170# bin
171select collation(bin(null));
172select collation(bin(uc)) from coll_test;
173select collation(bin(pk)) from coll_test;
174select collation(bin(b)) from coll_test;
175
176# effective_tenant
177select collation(effective_tenant());
178select coercibility(effective_tenant());
179
180# like
181select collation(uc like b) from coll_test;
182select cmp_meta(uc like b) from coll_test;
183select cmp_meta(uc like ub) from coll_test;
184select cmp_meta(b like b) from coll_test;
185select cmp_meta(uc like b) from coll_test;
186
187# cast
188select collation(cast(uc as binary)) from coll_test;
189select collation(cast(pk as char)) from coll_test;
190select uc, collation(binary uc) from coll_test;
191select collation(binary binary uc collate utf8_bin) from coll_test;
192
193# user
194select collation(user());
195select coercibility(user());
196
197# version
198select collation(version());
199select coercibility(version());
200
201# unhex
202select collation(unhex('42'));
203select collation(unhex(null));
204
205# regexp
206--error 3995
207select collation(uc regexp b) from coll_test;
208--error 3995
209select cmp_meta(uc regexp b) from coll_test;
210select cmp_meta(uc regexp ub) from coll_test;
211select cmp_meta(b regexp b) from coll_test;
212--error 3995
213select cmp_meta(uc regexp b) from coll_test;
214select cmp_meta(uc regexp 'abc') from coll_test;
215
216# quote
217select collation(quote(uc)) from coll_test;
218select collation(quote(ub)) from coll_test;
219select collation(quote(b)) from coll_test;
220select collation(quote(pk)) from coll_test;
221select collation(quote(null)) from coll_test;
222
223# md5
224select collation(md5(uc)) from coll_test;
225select collation(md5(ub)) from coll_test;
226select collation(md5(b)) from coll_test;
227select collation(md5(pk)) from coll_test;
228select collation(md5(null)) from coll_test;
229
230# dump
231select collation(dump(null)) from coll_test;
232
233# hex
234select collation(hex(uc)) from coll_test;
235select collation(hex(ub)) from coll_test;
236select collation(hex(b)) from coll_test;
237select collation(hex(pk)) from coll_test;
238select collation(hex(null)) from coll_test;
239
240# int2ip
241select collation(int2ip(pk)) from coll_test;
242select collation(int2ip(null)) from coll_test;
243
244# date_format
245SELECT collation(DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y'));
246
247# all implicit cast should use the connection_collation as the result collation
248set collation_connection = utf8mb4_general_ci;
249select collation(cast(1 as char));
250SELECT collation(DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y'));
251select collation(cast('A' as char)), cast('A' as char) < 'a';
252
253set collation_connection = utf8mb4_bin;
254select collation(cast(1 as char));
255SELECT collation(DATE_FORMAT('2009-10-04 22:23:00', '%W %M %Y'));
256select collation(cast('A' as char)), cast('A' as char) < 'a';
257
258################################################################
259# tear-down
260drop table coll_test;
261
262
263select CAST('Ab123人' AS char CHAR SET utf8mb4);
264SELECT collation(CAST('Ab123人' AS char CHAR SET utf8mb4));
265SELECT length(CAST('Ab123人' AS char CHAR SET utf8mb4));
266
267select CAST('Ab123人' AS char CHAR SET binary);
268SELECT collation(CAST('Ab123人' AS char CHAR SET binary));
269SELECT length(CAST('Ab123人' AS char CHAR SET binary));
270
271select CAST('Ab123人' AS char CHAR SET gbk);
272SELECT collation(CAST('Ab123人' AS char CHAR SET gbk));
273SELECT length(CAST('Ab123人' AS char CHAR SET gbk));
274
275create table coll_test(c1 char(10) collate utf8mb4_bin, c2 char(10) collate gbk_bin, c3 char(10) char set binary);
276insert into coll_test values('Ab123人', 'Ab123人', 'Ab123人');
277select cast(c1 as char(20)), cast(c2 as char(20)), cast(c3 as char(20)) from coll_test;
278select collation(cast(c1 as char(20))), collation(cast(c2 as char(20))), collation(cast(c3 as char(20))) from coll_test;
279
280
281create or replace view v1(c1,c2,c3,c4) as select cast('abc' as char), cast('abc' as char char set utf8mb4),
282cast('abc' as char char set binary), cast('abc' as binary);
283show create view v1;
284
285create or replace view v1(c1,c2,c3,c4) as select cast('abc' as char(10)), cast('abc' as char(10) char set utf8mb4),
286cast('abc' as char(10) char set binary), cast('abc' as binary(10));
287show create view v1;
288drop table coll_test;
289drop view v1;