From 46559da7340c559d3e061066c8940305b2ef2f21 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 23 May 2026 15:03:44 +1000 Subject: [PATCH] MDEV-37864 json_array_intersect result has incorrect length MDEV-37864 added a length setting to the function Item_func_json_array_intersect::prepare_json_and_create_hash however some paths of Item_func_json_array_intersect::fix_length_and_dec never reach this function. Leave the length calculation the same but place in the ::fix_length_and_dec function. Collation is based on the arg[0], but potentially after they are swapped. Corrects cursor protocol for the test case added in MDEV-36808. --- sql/item_jsonfunc.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc index 417464ce64d82..4a6c5cc716802 100644 --- a/sql/item_jsonfunc.cc +++ b/sql/item_jsonfunc.cc @@ -5533,10 +5533,7 @@ bool Item_func_json_array_intersect::prepare_json_and_create_hash(json_engine_t report_json_error(js, je1, 0); } - max_length= 2*(args[0]->max_length < args[1]->max_length ? - args[0]->max_length : args[1]->max_length); - - return false; + return false; } bool Item_func_json_array_intersect::fix_length_and_dec(THD *thd) @@ -5565,6 +5562,10 @@ bool Item_func_json_array_intersect::fix_length_and_dec(THD *thd) } end: + collation.set(args[0]->collation); + fix_char_length_ulonglong((ulonglong) + 2* MY_MIN(args[0]->max_char_length(), + args[1]->max_char_length())); set_maybe_null(); return FALSE; }