diff options
| author | Anel Husakovic <anel@mariadb.org> | 2022-01-17 16:26:47 +0100 |
|---|---|---|
| committer | Anel Husakovic <anel@mariadb.org> | 2022-01-18 17:44:55 +0100 |
| commit | e83de74f78fec438debe557190ca511fcc0db208 (patch) | |
| tree | c3ac3956b0863c73d7552ccccf9c6d89347444c7 | |
| parent | bf9bc991066df78a37e917127d61d044700c3950 (diff) | |
| download | mariadb-git-bb-10.2-anel-MDEV-18284-json_compact.tar.gz | |
MDEV-18284: JSON casting using JSON_COMPACT doesn't always work with values from subqueriesbb-10.2-anel-MDEV-18284-json_compact
- Cherry-pick 2fcff310d024cc2201586c568391ba8b039f0bf3 (MDEV-21902)
- Closed PR #1145
Reviewed by: holyfoot@mariadb.com
| -rw-r--r-- | mysql-test/r/func_json.result | 18 | ||||
| -rw-r--r-- | mysql-test/t/func_json.test | 15 | ||||
| -rw-r--r-- | sql/item.h | 1 |
3 files changed, 34 insertions, 0 deletions
diff --git a/mysql-test/r/func_json.result b/mysql-test/r/func_json.result index f8e78c79f5d..b0005b13e45 100644 --- a/mysql-test/r/func_json.result +++ b/mysql-test/r/func_json.result @@ -940,5 +940,23 @@ SELECT JSON_REPLACE( JSON_DETAILED('["x"]'), '$.a', 'xx' ); JSON_REPLACE( JSON_DETAILED('["x"]'), '$.a', 'xx' ) ["x"] # +# MDEV-18284 JSON casting using JSON_COMPACT doesn't always work +# with values from subqueries +# +CREATE TABLE json_test(a JSON, b JSON); +INSERT INTO json_test VALUES ("[1,2,3]", '{"a":"foo"}'); +SELECT * FROM json_test; +a b +[1,2,3] {"a":"foo"} +SELECT json_object("a", json_compact(a), "b", b) +FROM (SELECT * FROM json_test) AS json_test_values; +json_object("a", json_compact(a), "b", b) +{"a": [1,2,3], "b": "{\"a\":\"foo\"}"} +SELECT json_object("a", json_compact(a), "b", json_compact(b)) +FROM (SELECT * FROM json_test) AS json_test_values; +json_object("a", json_compact(a), "b", json_compact(b)) +{"a": [1,2,3], "b": {"a":"foo"}} +DROP TABLE json_test; +# # End of 10.2 tests # diff --git a/mysql-test/t/func_json.test b/mysql-test/t/func_json.test index e4e093225f8..aaba3c21315 100644 --- a/mysql-test/t/func_json.test +++ b/mysql-test/t/func_json.test @@ -561,5 +561,20 @@ SELECT SELECT JSON_REPLACE( JSON_DETAILED('["x"]'), '$.a', 'xx' ); --echo # +--echo # MDEV-18284 JSON casting using JSON_COMPACT doesn't always work +--echo # with values from subqueries +--echo # + +CREATE TABLE json_test(a JSON, b JSON); +INSERT INTO json_test VALUES ("[1,2,3]", '{"a":"foo"}'); +SELECT * FROM json_test; + +SELECT json_object("a", json_compact(a), "b", b) + FROM (SELECT * FROM json_test) AS json_test_values; +SELECT json_object("a", json_compact(a), "b", json_compact(b)) + FROM (SELECT * FROM json_test) AS json_test_values; +DROP TABLE json_test; + +--echo # --echo # End of 10.2 tests --echo # diff --git a/sql/item.h b/sql/item.h index 086d85e989f..290ff11a0f8 100644 --- a/sql/item.h +++ b/sql/item.h @@ -4564,6 +4564,7 @@ public: { return ref ? (*ref)->real_item() : this; } + bool is_json_type() { return (*ref)->is_json_type(); } bool walk(Item_processor processor, bool walk_subquery, void *arg) { if (ref && *ref) |
