mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-30646 View created via JSON_ARRAYAGG returns incorrect json object
Backporting add782a13e
from 10.6, this fixes the problem.
This commit is contained in:
@ -18569,6 +18569,25 @@ Field *Item_func_sp::create_tmp_field_ex(MEM_ROOT *root, TABLE *table,
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static bool make_json_valid_expr(TABLE *table, Field *field)
|
||||
{
|
||||
THD *thd= table->in_use;
|
||||
Query_arena backup_arena;
|
||||
Item *expr, *item_field;
|
||||
|
||||
if (!table->expr_arena && table->init_expr_arena(thd->mem_root))
|
||||
return 1;
|
||||
|
||||
thd->set_n_backup_active_arena(table->expr_arena, &backup_arena);
|
||||
if ((item_field= new (thd->mem_root) Item_field(thd, field)) &&
|
||||
(expr= new (thd->mem_root) Item_func_json_valid(thd, item_field)))
|
||||
field->check_constraint= add_virtual_expression(thd, expr);
|
||||
thd->restore_active_arena(table->expr_arena, &backup_arena);
|
||||
return field->check_constraint == NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Create field for temporary table.
|
||||
|
||||
@ -18614,6 +18633,9 @@ Field *create_tmp_field(TABLE *table, Item *item,
|
||||
make_copy_field);
|
||||
Field *result= item->create_tmp_field_ex(table->in_use->mem_root,
|
||||
table, &src, &prm);
|
||||
if (is_json_type(item) && make_json_valid_expr(table, result))
|
||||
result= NULL;
|
||||
|
||||
*from_field= src.field();
|
||||
*default_field= src.default_field();
|
||||
if (src.item_result_field())
|
||||
|
Reference in New Issue
Block a user