[MDEV-33270] Failure to call SP invoking another SP with parameter requiring type conversion Created: 2024-01-18  Updated: 2024-01-23  Resolved: 2024-01-22

Status: Closed
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2, 11.3, 11.4
Fix Version/s: 10.4.33, 10.5.24, 10.6.17, 10.11.7, 11.0.5, 11.1.4, 11.2.3, 11.3.2, 11.4.1

Type: Bug Priority: Blocker
Reporter: Ramesh Sivaraman Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: regression


 Description   

SET SQL_MODE='';
SET SESSION old_mode=0;
CALL sys.diagnostics (4,2,0);

Leads to:

11.4.0 c0c1c80346b926ea1358aa512374d72d513299b0 (Optimized)

Core was generated by `/test/MD100124-mariadb-11.4.0-linux-x86_64-opt/bin/mariadbd --no-defaults --cor'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00005623d261fc31 in Type_std_attributes::agg_item_set_converter (
    this=this@entry=0x14d430226af8, coll=..., fname=..., 
    args=args@entry=0x14d430226bd8, nargs=nargs@entry=3, flags=flags@entry=11, 
    item_sep=1, single_err=0x0) at /test/11.4_opt/sql/sql_class.h:1243
 
warning: Source file is more recent than executable.
1243	  { return state == STMT_CONVENTIONAL_EXECUTION; }
[Current thread is 1 (Thread 0x14d4600cf700 (LWP 1385239))]
(gdb) bt
#0  0x00005623d261fc31 in Type_std_attributes::agg_item_set_converter (this=this@entry=0x14d430226af8, coll=@0x14d430226b00: {collation = 0x5623d36828e0 <my_charset_utf8mb4_general_ci>, derivation = DERIVATION_IMPLICIT, repertoire = MY_REPERTOIRE_UNICODE30}, fname=@0x14d4600cb7e0: {str = 0x5623d2e80bbe "concat", length = 6}, args=args@entry=0x14d430226bd8, nargs=nargs@entry=3, flags=flags@entry=11, item_sep=1, single_err=0x0) at /test/11.4_opt/sql/sql_class.h:1243
#1  0x00005623d269ef9f in Type_std_attributes::agg_arg_charsets (item_sep=1, flags=11, nitems=3, items=0x14d430226bd8, func_name=@0x14d4600cb7e0: {str = 0x5623d2e80bbe "concat", length = 6}, c=@0x14d430226b00: {collation = 0x5623d36828e0 <my_charset_utf8mb4_general_ci>, derivation = DERIVATION_IMPLICIT, repertoire = MY_REPERTOIRE_UNICODE30}, this=0x14d430226af8) at /test/11.4_opt/sql/sql_type.h:3317
#2  Type_std_attributes::agg_arg_charsets (item_sep=1, flags=11, nitems=3, items=0x14d430226bd8, func_name=@0x14d4600cb7e0: {str = 0x5623d2e80bbe "concat", length = 6}, c=@0x14d430226b00: {collation = 0x5623d36828e0 <my_charset_utf8mb4_general_ci>, derivation = DERIVATION_IMPLICIT, repertoire = MY_REPERTOIRE_UNICODE30}, this=0x14d430226af8) at /test/11.4_opt/sql/sql_type.h:3311
#3  Type_std_attributes::agg_arg_charsets_for_string_result (item_sep=1, nitems=3, items=0x14d430226bd8, func_name=@0x14d4600cb7e0: {str = 0x5623d2e80bbe "concat", length = 6}, c=@0x14d430226b00: {collation = 0x5623d36828e0 <my_charset_utf8mb4_general_ci>, derivation = DERIVATION_IMPLICIT, repertoire = MY_REPERTOIRE_UNICODE30}, this=0x14d430226af8) at /test/11.4_opt/sql/sql_type.h:3332
#4  Item_func_or_sum::agg_arg_charsets_for_string_result (item_sep=1, nitems=3, items=0x14d430226bd8, c=@0x14d430226b00: {collation = 0x5623d36828e0 <my_charset_utf8mb4_general_ci>, derivation = DERIVATION_IMPLICIT, repertoire = MY_REPERTOIRE_UNICODE30}, this=0x14d430226af0) at /test/11.4_opt/sql/item.h:5389
#5  Item_func_concat::fix_length_and_dec (this=0x14d430226af0, thd=<optimized out>) at /test/11.4_opt/sql/item_strfunc.cc:883
#6  0x00005623d26635ab in Item_func::fix_fields (ref=<optimized out>, thd=0x14d430000c58, this=0x14d430226af0) at /test/11.4_opt/sql/item_func.cc:377
#7  Item_func::fix_fields (this=this@entry=0x14d430226af0, thd=thd@entry=0x14d430000c58, ref=<optimized out>) at /test/11.4_opt/sql/item_func.cc:326
#8  0x00005623d2699ad6 in Item_str_func::fix_fields (this=0x14d430226af0, thd=0x14d430000c58, ref=<optimized out>) at /test/11.4_opt/sql/item_strfunc.cc:132
#9  0x00005623d22b89c7 in Item::fix_fields_if_needed (ref=0x14d4600cbab8, thd=0x14d430000c58, this=<optimized out>) at /test/11.4_opt/sql/item.h:1151
#10 Item::fix_fields_if_needed (ref=0x14d4600cbab8, thd=0x14d430000c58, this=<optimized out>) at /test/11.4_opt/sql/item.h:1151
#11 THD::sp_fix_func_item (this=this@entry=0x14d430000c58, it_addr=0x14d4600cbab8) at /test/11.4_opt/sql/sp_head.cc:394
#12 0x00005623d22b8a87 in THD::sp_fix_func_item_for_assignment (this=this@entry=0x14d430000c58, to=to@entry=0x14d43055c578, it_addr=<optimized out>) at /test/11.4_opt/sql/sp_head.cc:423
#13 0x00005623d25cefdc in Field::sp_prepare_and_store_item (this=0x14d43055c578, thd=0x14d430000c58, value=<optimized out>) at /test/11.4_opt/sql/field.cc:1502
#14 0x00005623d22b8b1c in THD::sp_eval_expr (this=this@entry=0x14d430000c58, result_field=<optimized out>, expr_item_ptr=expr_item_ptr@entry=0x14d4600cbab8) at /test/11.4_opt/sql/sp_head.cc:448
#15 0x00005623d22c5778 in sp_rcontext::set_variable (this=this@entry=0x14d43055bba8, thd=thd@entry=0x14d430000c58, idx=idx@entry=0, value=value@entry=0x14d4600cbab8) at /test/11.4_opt/sql/sp_rcontext.cc:642
#16 0x00005623d22bb9f9 in sp_rcontext::set_parameter (value=0x14d4600cbab8, var_idx=0, thd=0x14d430000c58, this=0x14d43055bba8) at /test/11.4_opt/sql/sp_rcontext.h:194
#17 sp_head::bind_input_param (this=0x14d43085baa8, thd=0x14d430000c58, arg_item=<optimized out>, arg_no=0, nctx=0x14d43055bba8, is_function=<optimized out>) at /test/11.4_opt/sql/sp_head.cc:2421
#18 0x00005623d22bbd84 in sp_head::execute_procedure (this=0x14d43085baa8, thd=thd@entry=0x14d430000c58, args=0x14d4302257c0) at /test/11.4_opt/sql/sp_head.cc:2217
#19 0x00005623d236b447 in do_execute_sp (thd=thd@entry=0x14d430000c58, sp=sp@entry=0x14d43085baa8) at /test/11.4_opt/sql/sql_parse.cc:3033
#20 0x00005623d2370026 in Sql_cmd_call::execute (this=0x14d430226560, thd=0x14d430000c58) at /test/11.4_opt/sql/sql_parse.cc:3256
#21 0x00005623d237685e in mysql_execute_command (thd=0x14d430000c58, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/11.4_opt/sql/sql_parse.cc:5786
#22 0x00005623d252950b in sp_instr_stmt::exec_core (this=0x14d430226c68, thd=<optimized out>, nextp=0x14d4600cd0f4) at /test/11.4_opt/sql/sp_instr.cc:956
#23 0x00005623d252b3fb in sp_lex_keeper::reset_lex_and_exec_core (this=0x14d430226ca0, thd=0x14d430000c58, nextp=<optimized out>, open_tables=<optimized out>, instr=0x14d430226c68, rerun_the_same_instr=<optimized out>) at /test/11.4_opt/sql/sp_instr.cc:296
#24 0x00005623d252c01e in sp_lex_keeper::validate_lex_and_exec_core (this=this@entry=0x14d430226ca0, thd=thd@entry=0x14d430000c58, nextp=nextp@entry=0x14d4600cd0f4, open_tables=open_tables@entry=false, instr=instr@entry=0x14d430226c68) at /test/11.4_opt/sql/sp_instr.cc:475
#25 0x00005623d252c84e in sp_instr_stmt::execute (this=0x14d430226c68, thd=0x14d430000c58, nextp=0x14d4600cd0f4) at /test/11.4_opt/sql/sp_instr.cc:862
#26 0x00005623d22ba5a0 in sp_head::execute (this=0x14d4300386b0, thd=0x14d430000c58, merge_da_on_success=true) at /test/11.4_opt/sql/sp_head.cc:1284
#27 0x00005623d22bc19f in sp_head::execute_procedure (this=0x14d4300386b0, thd=thd@entry=0x14d430000c58, args=0x14d430005e68) at /test/11.4_opt/sql/sp_head.cc:2300
#28 0x00005623d236b447 in do_execute_sp (thd=thd@entry=0x14d430000c58, sp=sp@entry=0x14d4300386b0) at /test/11.4_opt/sql/sql_parse.cc:3033
#29 0x00005623d2370026 in Sql_cmd_call::execute (this=0x14d430010c10, thd=0x14d430000c58) at /test/11.4_opt/sql/sql_parse.cc:3256
#30 0x00005623d237685e in mysql_execute_command (thd=0x14d430000c58, is_called_from_prepared_stmt=<optimized out>) at /test/11.4_opt/sql/sql_parse.cc:5786
#31 0x00005623d23661d6 in mysql_parse (thd=0x14d430000c58, rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>) at /test/11.4_opt/sql/sql_parse.cc:7798
#32 0x00005623d2372755 in dispatch_command (command=COM_QUERY, thd=0x14d430000c58, packet=<optimized out>, packet_length=<optimized out>, blocking=<optimized out>) at /test/11.4_opt/sql/sql_class.h:1552
#33 0x00005623d237499e in do_command (thd=0x14d430000c58, blocking=blocking@entry=true) at /test/11.4_opt/sql/sql_parse.cc:1406
#34 0x00005623d24a4467 in do_handle_one_connection (connect=<optimized out>, put_in_cache=true) at /test/11.4_opt/sql/sql_connect.cc:1417
#35 0x00005623d24a47ad in handle_one_connection (arg=arg@entry=0x5623d5355ea8) at /test/11.4_opt/sql/sql_connect.cc:1319
#36 0x00005623d284cd7c in pfs_spawn_thread (arg=0x5623d537dc18) at /test/11.4_opt/storage/perfschema/pfs.cc:2201
#37 0x000014d477690609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#38 0x000014d47727c133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.6.17 (dbg), 10.6.17 (opt), 10.11.7 (dbg), 10.11.7 (opt), 11.0.5 (dbg), 11.0.5 (opt), 11.1.4 (dbg), 11.1.4 (opt), 11.2.3 (dbg), 11.2.3 (opt), 11.3.2 (opt), 11.3.2 (dbg), 11.4.0 (dbg), 11.4.0 (opt)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.4.33 (dbg), 10.4.33 (opt), 10.5.24 (dbg), 10.5.24 (opt),



 Comments   
Comment by Elena Stepanova [ 2024-01-18 ]

Version-independent test case:

SET NAMES latin1;
CREATE PROCEDURE pr1 (a TEXT) BEGIN END;
CREATE PROCEDURE pr2 () CALL pr1(CONCAT('x',_utf8'x'));
CALL pr2();

I expect the summary will be changed as needed after analysis, so I won't change it now.

The failure started happening after this commit in 10.4:

commit 9b049266ea9eebaa93e24f4ec522f9b239c85c61
Author: Igor Babaev
Date:   Tue Oct 31 09:59:39 2023 -0700
 
    MDEV-32569 Failure when executing PS for query using IN subquery

Comment by Igor Babaev [ 2024-01-19 ]

See bb-10.4-mdev-33270

Comment by Oleksandr Byelkin [ 2024-01-19 ]

OK to push

Comment by Igor Babaev [ 2024-01-22 ]

A fix for this bug was pushed into 10.4. It has to be merged upstream as it is.

Generated at Thu Feb 08 10:37:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.