From 648a88c52705e97c6fedbb4cf55162ca998b19e4 Mon Sep 17 00:00:00 2001 From: Knut Anders Hatlen Date: Wed, 8 Jul 2015 12:41:17 +0200 Subject: [PATCH] Bug#21383497: DBUG_ABORT() IN VAL_JSON Item_func_rollup_const does not override val_json(), and attempts to call it will end up using Item::val_json(), which always raises an error. This patch makes Item_func_rollup_const override val_json() and read the JSON value from its nested item. --- mysql-test/r/json.result | 46 ++++++++++++++++++++++++++++++++++++++++ mysql-test/t/json.test | 16 ++++++++++++++ sql/item_func.cc | 10 +++++++++ sql/item_func.h | 1 + 4 files changed, 73 insertions(+) diff --git a/mysql-test/r/json.result b/mysql-test/r/json.result index 979fa7048c79..3a7d549f7f34 100644 --- a/mysql-test/r/json.result +++ b/mysql-test/r/json.result @@ -12740,3 +12740,49 @@ NULL SELECT JSON_ARRAY(CASE WHEN 1 THEN NULL ELSE NULL END); JSON_ARRAY(CASE WHEN 1 THEN NULL ELSE NULL END) [null] +# +# Bug#21383497 DBUG_ABORT() IN VAL_JSON +# +CREATE TABLE t(a INT PRIMARY KEY); +INSERT INTO t VALUES (1), (2), (3), (4), (5); +SELECT 1 FROM t GROUP BY ST_ASGEOJSON(POINT(1, 1)) WITH ROLLUP; +1 +1 +1 +Warnings: +Warning 1235 This version of MySQL doesn't yet support 'sorting of non-scalar JSON values' +SELECT JSON_EXTRACT('{"a":1}', '$.a') AS je, COUNT(DISTINCT a) +FROM t GROUP BY je WITH ROLLUP; +je COUNT(DISTINCT a) +1 5 +NULL 5 +SELECT JSON_EXTRACT(NULL, '$.a') AS je, COUNT(DISTINCT a) +FROM t GROUP BY je WITH ROLLUP; +je COUNT(DISTINCT a) +NULL 5 +NULL 5 +SELECT JSON_EXTRACT('{"a":1}', '$.a') AS je, a, COUNT(DISTINCT a) +FROM t GROUP BY je, a WITH ROLLUP; +je a COUNT(DISTINCT a) +1 1 1 +1 2 1 +1 3 1 +1 4 1 +1 5 1 +1 NULL 5 +NULL NULL 5 +SELECT JSON_EXTRACT('{"a":1}', '$.a') AS je, a, COUNT(DISTINCT a) +FROM t GROUP BY a, je WITH ROLLUP; +je a COUNT(DISTINCT a) +1 1 1 +NULL 1 1 +1 2 1 +NULL 2 1 +1 3 1 +NULL 3 1 +1 4 1 +NULL 4 1 +1 5 1 +NULL 5 1 +NULL NULL 5 +DROP TABLE t; diff --git a/mysql-test/t/json.test b/mysql-test/t/json.test index 53933a96b519..53cb500560bc 100644 --- a/mysql-test/t/json.test +++ b/mysql-test/t/json.test @@ -5721,6 +5721,22 @@ SELECT JSON_SET(CASE WHEN 1 THEN NULL ELSE NULL END, '{}', '{}'); SELECT JSON_VALID(CASE WHEN 1 THEN NULL ELSE NULL END); SELECT JSON_ARRAY(CASE WHEN 1 THEN NULL ELSE NULL END); +--echo # +--echo # Bug#21383497 DBUG_ABORT() IN VAL_JSON +--echo # +CREATE TABLE t(a INT PRIMARY KEY); +INSERT INTO t VALUES (1), (2), (3), (4), (5); +SELECT 1 FROM t GROUP BY ST_ASGEOJSON(POINT(1, 1)) WITH ROLLUP; +SELECT JSON_EXTRACT('{"a":1}', '$.a') AS je, COUNT(DISTINCT a) +FROM t GROUP BY je WITH ROLLUP; +SELECT JSON_EXTRACT(NULL, '$.a') AS je, COUNT(DISTINCT a) +FROM t GROUP BY je WITH ROLLUP; +SELECT JSON_EXTRACT('{"a":1}', '$.a') AS je, a, COUNT(DISTINCT a) +FROM t GROUP BY je, a WITH ROLLUP; +SELECT JSON_EXTRACT('{"a":1}', '$.a') AS je, a, COUNT(DISTINCT a) +FROM t GROUP BY a, je WITH ROLLUP; +DROP TABLE t; + # Local Variables: # mode: sql # sql-product: mysql diff --git a/sql/item_func.cc b/sql/item_func.cc index 70a8a1738819..81e263434b46 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3880,6 +3880,16 @@ my_decimal *Item_func_rollup_const::val_decimal(my_decimal *dec) return res; } + +bool Item_func_rollup_const::val_json(Json_wrapper *result) +{ + DBUG_ASSERT(fixed == 1); + bool res= args[0]->val_json(result); + null_value= args[0]->null_value; + return res; +} + + longlong Item_func_length::val_int() { DBUG_ASSERT(fixed == 1); diff --git a/sql/item_func.h b/sql/item_func.h index eaded568db92..a9c9726ba17e 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1393,6 +1393,7 @@ class Item_func_rollup_const :public Item_func longlong val_int(); String *val_str(String *str); my_decimal *val_decimal(my_decimal *dec); + bool val_json(Json_wrapper *result); bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) { return (null_value= args[0]->get_date(ltime, fuzzydate));