From 8711adb7863b10fd868cc2b1c84c3416e715b539 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 30 Jun 2021 01:00:50 +0200 Subject: [PATCH] fix JSON_ARRAYAGG not to over-quote json in joins use metadata (in particular is_json() property) of the original argument item, even if the actual argument was later replaced with an Item_temptable_field --- mysql-test/main/func_json.result | 6 +++--- sql/item_jsonfunc.cc | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mysql-test/main/func_json.result b/mysql-test/main/func_json.result index 0c242a886b7..a889cb228b7 100644 --- a/mysql-test/main/func_json.result +++ b/mysql-test/main/func_json.result @@ -1376,9 +1376,9 @@ SELECT t1.id, JSON_ARRAYAGG(JSON_OBJECT('id',t2.id)) as materials from t1 LEFT JOIN t2 on t1.id = t2.owner_id GROUP BY t1.id ORDER BY id; id materials -1 ["{\"id\": 1}","{\"id\": 2}"] -2 ["{\"id\": 3}"] -3 ["{\"id\": 4}"] +1 [{"id": 1},{"id": 2}] +2 [{"id": 3}] +3 [{"id": 4}] DROP TABLE t1; DROP TABLE t2; # diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 4b63b119a83..60c0e4cc2fe 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -3723,12 +3723,12 @@ String *Item_func_json_arrayagg::get_str_from_item(Item *i, String *tmp) } -String *Item_func_json_arrayagg::get_str_from_field(Item *i,Field *f, +String *Item_func_json_arrayagg::get_str_from_field(Item *, Field *f, String *tmp, const uchar *key, size_t offset) { m_tmp_json.length(0); - if (append_json_value_from_field(&m_tmp_json, i, f, key, offset, tmp)) + if (append_json_value_from_field(&m_tmp_json, *orig_args, f, key, offset, tmp)) return NULL; return &m_tmp_json;