Commit b4cbaf0b authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-11436 CREATE TABLE .. AS SELECT JSON_OBJECT truncates data.

        fix_length_and_dec() didn't calculate the length of the result
        properly.
parent f391ab4f
......@@ -165,6 +165,16 @@ json_object()
select json_object("ki", 1, "mi", "ya");
json_object("ki", 1, "mi", "ya")
{"ki": 1, "mi": "ya"}
create table t1 as select json_object('id', 87, 'name', 'carrot') as f;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f` varchar(32) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from t1;
f
{"id": 87, "name": "carrot"}
drop table t1;
select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2");
json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2")
1
......
......@@ -68,6 +68,10 @@ select json_remove(@j, '$.a');
select json_object();
select json_object("ki", 1, "mi", "ya");
create table t1 as select json_object('id', 87, 'name', 'carrot') as f;
show create table t1;
select * from t1;
drop table t1;
select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2");
select json_exists('{"key1":"xxxx", "key2":[1, 2, 3]}', "$.key2[1]");
......
......@@ -874,7 +874,7 @@ static int append_json_keyname(String *str, Item *item, String *tmp_val)
void Item_func_json_array::fix_length_and_dec()
{
ulonglong char_length= 4;
ulonglong char_length= 2;
uint n_arg;
if (arg_count == 0)
......@@ -889,7 +889,7 @@ void Item_func_json_array::fix_length_and_dec()
return;
for (n_arg=0 ; n_arg < arg_count ; n_arg++)
char_length+= args[n_arg]->max_char_length() + 2;
char_length+= args[n_arg]->max_char_length() + 4;
fix_char_length_ulonglong(char_length);
tmp_val.set_charset(collation.collation);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment