Skip to content

Commit b93252a

Browse files
author
Alexey Botchkov
committed
MDEV-32454 JSON test has problem in view protocol.
Few Item_func_json_xxx::fix_length_and_dec() functions fixed.
1 parent c9b0c00 commit b93252a

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

mysql-test/main/func_json.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ create table t1 as select json_object('id', 87, 'name', 'carrot') as f;
272272
show create table t1;
273273
Table Create Table
274274
t1 CREATE TABLE `t1` (
275-
`f` varchar(32) DEFAULT NULL
275+
`f` varchar(46) DEFAULT NULL
276276
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
277277
select * from t1;
278278
f

mysql-test/main/func_json.test

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,12 @@ select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]') as exp;
8787
select json_extract('[10, 20, [30, 40], 1, 10]', '$[1]', '$[25]') as exp;
8888
select json_extract( '[{"a": [3, 4]}, {"b": 2}]', '$[0].a', '$[1].a') as exp;
8989

90-
#enable after MDEV-32454 fix
91-
--disable_view_protocol
9290
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.k1', 'word') as exp;
9391
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.d[3]', 3) as exp;
9492
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.a[2]', 2) as exp;
9593
select json_insert('{"a":1, "b":{"c":1}, "d":[1, 2]}', '$.b.c', 'word') as exp;
9694

9795
select json_set('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]') as exp;
98-
--enable_view_protocol
9996

10097
select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.c', '[true, false]') as exp;
10198
select json_replace('{ "a": 1, "b": [2, 3]}', '$.a', 10, '$.b', '[true, false]') as exp;
@@ -137,14 +134,11 @@ select json_merge('a','b');
137134
select json_merge('{"a":"b"}','{"c":"d"}');
138135
SELECT JSON_MERGE('[1, 2]', '{"id": 47}');
139136

140-
#enable after MDEV-32454 fix
141-
--disable_view_protocol
142137
select json_type('{"k1":123, "k2":345}');
143138
select json_type('[123, "k2", 345]');
144139
select json_type("true");
145140
select json_type('123');
146141
select json_type('123.12');
147-
--enable_view_protocol
148142

149143
select json_keys('{"a":{"c":1, "d":2}, "b":2}');
150144
select json_keys('{"a":{"c":1, "d":2}, "b":2}', "$.a");
@@ -173,11 +167,8 @@ select json_search( json_col, 'all', 'foot' ) as ex from t1;
173167
drop table t1;
174168

175169

176-
#enable after MDEV-32454 fix
177-
--disable_view_protocol
178170
select json_unquote('"abc"');
179171
select json_unquote('abc');
180-
--enable_view_protocol
181172
#
182173
# MDEV-13703 Illegal mix of collations for operation 'json_object' on using JSON_UNQUOTE as an argument.
183174
#
@@ -188,13 +179,9 @@ select json_object('foo', json_unquote(json_object('bar', c)),'qux', c) as fld f
188179
drop table t1;
189180

190181

191-
#enable after MDEV-32454 fix
192-
--disable_view_protocol
193182
select json_object("a", json_object("b", "abcd"));
194183
select json_object("a", '{"b": "abcd"}');
195184
select json_object("a", json_compact('{"b": "abcd"}'));
196-
--enable_view_protocol
197-
198185

199186
select json_compact(NULL);
200187
select json_depth(json_compact(NULL));
@@ -270,11 +257,8 @@ select json_merge('{"a":{"u":12, "x":"b"}}', '{"a":{"x":"c"}}') as ex ;
270257
select json_merge('{"a":{"u":12, "x":"b", "r":1}}', '{"a":{"x":"c", "r":2}}') as ex ;
271258

272259
select json_compact('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
273-
#enable after MDEV-32454 fix
274-
--disable_view_protocol
275260
select json_loose('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
276261
select json_detailed('{"a":1, "b":[1,2,3], "c":{"aa":"v1", "bb": "v2"}}') as ex;
277-
--enable_view_protocol
278262

279263
#
280264
# MDEV-11856 json_search doesn't search for values with double quotes character (")
@@ -466,12 +450,9 @@ drop table t1;
466450
--echo # MDEV-16750 JSON_SET mishandles unicode every second pair of arguments.
467451
--echo #
468452

469-
#enable after MDEV-32454 fix
470-
--disable_view_protocol
471453
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6) as exp;
472454
SELECT JSON_SET('{}', '$.a', _utf8 0xC3B6, '$.b', _utf8 0xC3B6) as exp;
473455
SELECT JSON_SET('{}', '$.a', _utf8 X'C3B6', '$.x', 1, '$.b', _utf8 X'C3B6') as exp;
474-
--enable_view_protocol
475456

476457
--echo #
477458
--echo # MDEV-17121 JSON_ARRAY_APPEND

mysql-test/suite/json/r/json_no_table.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3338,7 +3338,7 @@ OBJECT
33383338
CREATE VIEW v1 AS SELECT JSON_TYPE(JSON_OBJECT());
33393339
SELECT * FROM v1;
33403340
JSON_TYPE(JSON_OBJECT())
3341-
OBJE
3341+
OBJECT
33423342
drop view v1;
33433343
#
33443344
# Bug#21198333 SIG 6 IN ITEM_CACHE_JSON::CACHE_VALUE AT SQL/ITEM.CC:9470

sql/item_jsonfunc.cc

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ bool Item_func_json_unquote::fix_length_and_dec()
761761
{
762762
collation.set(&my_charset_utf8_general_ci,
763763
DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
764-
max_length= args[0]->max_length;
764+
max_length= args[0]->max_char_length() * collation.collation->mbmaxlen;
765765
maybe_null= 1;
766766
return FALSE;
767767
}
@@ -1730,7 +1730,22 @@ bool Item_func_json_array::fix_length_and_dec()
17301730
return TRUE;
17311731

17321732
for (n_arg=0 ; n_arg < arg_count ; n_arg++)
1733-
char_length+= args[n_arg]->max_char_length() + 4;
1733+
{
1734+
ulonglong arg_length;
1735+
Item *arg= args[n_arg];
1736+
1737+
if (!arg->is_json_type() && arg->result_type() == STRING_RESULT)
1738+
arg_length= arg->max_char_length() * 2; /*escaping possible */
1739+
else if (arg->type_handler()->is_bool_type())
1740+
arg_length= 5;
1741+
else
1742+
arg_length= arg->max_char_length();
1743+
1744+
if (arg_length < 4)
1745+
arg_length= 4; /* can be 'null' */
1746+
1747+
char_length+= arg_length + 4;
1748+
}
17341749

17351750
fix_char_length_ulonglong(char_length);
17361751
tmp_val.set_charset(collation.collation);
@@ -2874,7 +2889,7 @@ longlong Item_func_json_depth::val_int()
28742889
bool Item_func_json_type::fix_length_and_dec()
28752890
{
28762891
collation.set(&my_charset_utf8_general_ci);
2877-
max_length= 12;
2892+
max_length= 12 * collation.collation->mbmaxlen;
28782893
maybe_null= 1;
28792894
return FALSE;
28802895
}
@@ -2940,6 +2955,11 @@ bool Item_func_json_insert::fix_length_and_dec()
29402955
for (n_arg= 1; n_arg < arg_count; n_arg+= 2)
29412956
{
29422957
paths[n_arg/2].set_constant_flag(args[n_arg]->const_item());
2958+
/*
2959+
In the resulting JSON we can insert the property
2960+
name from the path, and the value itself.
2961+
*/
2962+
char_length+= args[n_arg/2]->max_char_length() + 6;
29432963
char_length+= args[n_arg/2+1]->max_char_length() + 4;
29442964
}
29452965

@@ -3749,7 +3769,20 @@ bool Item_func_json_format::fix_length_and_dec()
37493769
{
37503770
decimals= 0;
37513771
collation.set(args[0]->collation);
3752-
max_length= args[0]->max_length;
3772+
switch (fmt)
3773+
{
3774+
case COMPACT:
3775+
max_length= args[0]->max_length;
3776+
break;
3777+
case LOOSE:
3778+
max_length= args[0]->max_length * 2;
3779+
break;
3780+
case DETAILED:
3781+
max_length= MAX_BLOB_WIDTH;
3782+
break;
3783+
default:
3784+
DBUG_ASSERT(0);
3785+
};
37533786
maybe_null= 1;
37543787
return FALSE;
37553788
}

0 commit comments

Comments
 (0)