Skip to content

Commit

Permalink
Bug#21383497: DBUG_ABORT() IN VAL_JSON
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kahatlen committed Jul 9, 2015
1 parent 96891de commit 648a88c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
46 changes: 46 additions & 0 deletions mysql-test/r/json.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions mysql-test/t/json.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions sql/item_func.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions sql/item_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 648a88c

Please sign in to comment.