diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2020-06-04 10:00:56 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2020-06-04 10:00:56 +0400 |
commit | bb47050e1fdc49aa56fb55c8c55ff81ba24d355b (patch) | |
tree | 4b0e592a38460d12b4baf61f4203abe366e9cc27 /sql/item_sum.cc | |
parent | e7bab059b764bc58ee14e182b51f90c47a6c8e17 (diff) | |
download | mariadb-git-bb47050e1fdc49aa56fb55c8c55ff81ba24d355b.tar.gz |
MDEV-22640, MDEV-22449, MDEV-21528 JSON_ARRAYAGG crashes with NULL values.
We have to include NULL in the result which the GOUP_CONCAT doesn't
always do. Also converting should be done into another String instance
as these can be same.
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r-- | sql/item_sum.cc | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc index b676186f571..0ce5352ccfb 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -3674,20 +3674,18 @@ int dump_leaf_key(void* key_arg, element_count count __attribute__((unused)), else res= (*arg)->val_str(&tmp); } - if (res) + if (item->sum_func() == Item_sum::JSON_ARRAYAGG_FUNC) { - if (item->sum_func() == Item_sum::JSON_ARRAYAGG_FUNC) - { - /* - JSON_ARRAYAGG needs to convert the type into valid JSON before - appending it to the result - */ - Item_func_json_arrayagg *arrayagg= (Item_func_json_arrayagg *) item_arg; - res= arrayagg->convert_to_json(*arg, res); - } + /* + JSON_ARRAYAGG needs to convert the type into valid JSON before + appending it to the result + */ + Item_func_json_arrayagg *arrayagg= (Item_func_json_arrayagg *) item_arg; + res= arrayagg->convert_to_json(*arg); + } + if (res) result->append(*res); - } } if (item->limit_clause) @@ -4151,13 +4149,10 @@ bool Item_func_group_concat::setup(THD *thd) Item *item= args[i]; if (list.push_back(item, thd->mem_root)) DBUG_RETURN(TRUE); - if (item->const_item()) + if (item->const_item() && item->is_null() && skip_nulls()) { - if (item->is_null()) - { - always_null= 1; - DBUG_RETURN(FALSE); - } + always_null= 1; + DBUG_RETURN(FALSE); } } |