Bug #108326 | confusing result about json value | ||
---|---|---|---|
Submitted: | 30 Aug 2022 2:56 | Modified: | 7 Sep 2022 13:02 |
Reporter: | x j | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: JSON | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[30 Aug 2022 2:56]
x j
[30 Aug 2022 12:42]
MySQL Verification Team
Hi Mr j, Thank you for your bug report. We have managed to repeat the behaviour with 8.0.30: json_type(json_extract(a, '$.a')) STRING json_type(json_extract(json_object('a', b'01010101'), '$.a')) BLOB Verified as reported.
[5 Sep 2022 7:18]
huahua xu
The execution path for `select json_type(json_extract(json_object('a', b'01010101'), '$.a'));`: Item_func_json_type -->args[0] = Item_func_json_extract # (m_is_dom = true, m_dom_value = {json_type=enum_json_type::J_OPAQUE, m_mytype=MYSQL_TYPE_VARCHAR, m_val="U"} }) -->m_data_type = MYSQL_TYPE_JSON args[0] = Item_func_json_row_object # Json_object:(m_map={"a":{json_type=enum_json_type::J_OPAQUE, m_mytype=MYSQL_TYPE_VARCHAR, m_val="U" }}) -->m_data_type = MYSQL_TYPE_JSON args[0] = PTI_text_literal_text_string args[1] = Item_bin_string # val_json_func_field_subselect(args[1]) = ([Json_opaque] = {m_mytype=MYSQL_TYPE_VARCHAR, m_val="U" }) args[1] = PTI_text_literal_text_string for `select json_type(json_extract(a, '$.a')) from test;`: Item_func_json_type -->args[0] = Item_func_json_extract # (m_is_dom = false, m_value={m_data="base64:type15:VQ==", m_type=STRING}) -->m_data_type = MYSQL_TYPE_JSON args[0] = Item_field args[1] = PTI_text_literal_text_string I think that the mysql server serializes json value with missing type information, when it stores the column value.
[7 Sep 2022 13:02]
Jon Stephens
Documented fix as follows in the MySQL 8.0.32 changelog: While saving the result of JSON_ARRAYAGG() or JSON_OBJECTAGG() in a column, the data type information was lost due to the result being an item of type SUM_FUNC_ITEM. To fix this, we remove the type check and this way retain the type information. Closed.
[19 Sep 2022 11:51]
MySQL Verification Team
Thank you, Jon .......