Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-36114

Assertion `(mem_root->flags & 4) == 0' failed in Field_iterator_table::create_item

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.4, 11.7(EOL), 11.8
    • 11.4, 11.8
    • Stored routines
    • None

    Description

      The issue may be similar to MDEV-35137, but here the failure is in a different place when using the given test case.

      DELIMITER //
      CREATE PROCEDURE p() 
      BEGIN 
          DECLARE cur1 CURSOR FOR SELECT * FROM t;
          BEGIN 
            DECLARE rec1 ROW TYPE OF cur1;
          END;
      END; //
      DELIMITER ;
      CREATE TABLE t (id INT);
      CALL p();
      CREATE OR REPLACE TABLE t (id INT);
      CALL p();
      

      Leads to:

      CS 11.4.6 ef966af801afc2a07222b5df65dddd52c77431dd (Debug) Build 13/02/2025

      mariadbd: /test/11.4_dbg/mysys/my_alloc.c:278: alloc_root: Assertion `(mem_root->flags & 4) == 0' failed.
      

      CS 11.4.6 ef966af801afc2a07222b5df65dddd52c77431dd (Debug) Build 13/02/2025

      Core was generated by `/test/MD130225-mariadb-11.4.6-linux-x86_64-dbg/bin/mariadbd --no-defaults --max'.
      Program terminated with signal SIGABRT, Aborted.
      #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:44
       
      [Current thread is 1 (Thread 0x1491809486c0 (LWP 3091721))]
      (gdb) bt
      #0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:44
      #1  __pthread_kill_internal (signo=6, threadid=<optimized out>)at ./nptl/pthread_kill.c:78
      #2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6)at ./nptl/pthread_kill.c:89
      #3  0x0000149187c4527e in __GI_raise (sig=sig@entry=6)at ../sysdeps/posix/raise.c:26
      #4  0x0000149187c288ff in __GI_abort () at ./stdlib/abort.c:79
      #5  0x0000149187c2881b in __assert_fail_base (fmt=0x149187dd01e8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x55584c144880 "(mem_root->flags & 4) == 0", file=file@entry=0x55584c0d18e8 "/test/11.4_dbg/mysys/my_alloc.c", line=line@entry=278, function=function@entry=0x55584c2ab7d0 <__PRETTY_FUNCTION__.1> "alloc_root") at ./assert/assert.c:96
      #6  0x0000149187c3b517 in __assert_fail (assertion=assertion@entry=0x55584c144880 "(mem_root->flags & 4) == 0", file=file@entry=0x55584c0d18e8 "/test/11.4_dbg/mysys/my_alloc.c", line=line@entry=278, function=function@entry=0x55584c2ab7d0 <__PRETTY_FUNCTION__.1> "alloc_root") at ./assert/assert.c:105
      #7  0x000055584bd8665d in alloc_root (mem_root=0x149124022bc8, length=288)at /test/11.4_dbg/mysys/my_alloc.c:278
      #8  0x000055584b472be5 in Item::operator new (size=size@entry=288, mem_root=<optimized out>) at /test/11.4_dbg/sql/item.h:866
      #9  0x000055584b65852a in Field_iterator_table::create_item (this=0x149180944ee0, thd=0x149124000d58)at /test/11.4_dbg/sql/table.cc:7249
      #10 0x000055584b4ff947 in Field_iterator_table_ref::create_item (thd=0x149124000d58, this=0x149180944ec0) at /test/11.4_dbg/sql/table.h:3279
      #11 insert_fields (thd=thd@entry=0x149124000d58, context=<optimized out>, db_name_arg=@0x1491240b0298: {str = 0x0, length = 0}, table_name=@0x1491240b02a8: {str = 0x0, length = 0}, it=it@entry=0x1491809452b0, any_privileges=any_privileges@entry=false, hidden_bit_fields=0x1491240b011c, returning_field=false)at /test/11.4_dbg/sql/sql_base.cc:8621
      #12 0x000055584b5000aa in setup_wild (thd=0x149124000d58, tables=<optimized out>, fields=@0x1491240affd8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x1491240b0308, last = 0x1491240b0308, elements = 1}, <No data fields>}, sum_func_list=sum_func_list@entry=0x149124057d28, select_lex=0x1491240afd20, returning_field=returning_field@entry=false)at /test/11.4_dbg/sql/sql_base.cc:8022
      #13 0x000055584b5c12db in JOIN::prepare (this=this@entry=0x149124057980, tables_init=tables_init@entry=0x1491240b0350, conds_init=conds_init@entry=0x0, og_num=og_num@entry=0, order_init=order_init@entry=0x0, skip_order_by=skip_order_by@entry=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x1491240afd20, unit_arg=0x14912404b6b0)at /test/11.4_dbg/sql/sql_select.cc:1531
      #14 0x000055584b5dc8d9 in mysql_select (thd=thd@entry=0x149124000d58, tables=0x1491240b0350, fields=@0x1491240affd8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x1491240b0308, last = 0x1491240b0308, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2164526848, result=0x149124057750, unit=0x14912404b6b0, select_lex=0x1491240afd20) at /test/11.4_dbg/sql/sql_select.cc:5336
      #15 0x000055584b5dcad8 in handle_select (thd=thd@entry=0x149124000d58, lex=lex@entry=0x14912404b5d0, result=result@entry=0x149124057750, setup_tables_done_option=setup_tables_done_option@entry=0)at /test/11.4_dbg/sql/sql_select.cc:642
      #16 0x000055584b55cc58 in execute_sqlcom_select (thd=thd@entry=0x149124000d58, all_tables=0x1491240b0350) at /test/11.4_dbg/sql/sql_parse.cc:6183
      #17 0x000055584b566712 in mysql_execute_command (thd=thd@entry=0x149124000d58, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false)at /test/11.4_dbg/sql/sql_parse.cc:3975
      #18 0x000055584b51bdc7 in mysql_open_cursor (thd=thd@entry=0x149124000d58, result=result@entry=0x149180946020, pcursor=pcursor@entry=0x149180946058)at /test/11.4_dbg/sql/sql_cursor.cc:138
      #19 0x000055584b4cd508 in sp_cursor::open (this=this@entry=0x149180946000, thd=thd@entry=0x149124000d58) at /test/11.4_dbg/sql/sp_rcontext.cc:764
      #20 0x000055584b72cef9 in sp_instr_cursor_copy_struct::exec_core (this=0x14912404d448, thd=0x149124000d58, nextp=0x14918094629c)at /test/11.4_dbg/sql/sp_instr.cc:2048
      #21 0x000055584b72bba0 in sp_lex_keeper::reset_lex_and_exec_core (this=this@entry=0x14912404d480, thd=thd@entry=0x149124000d58, nextp=nextp@entry=0x14918094629c, open_tables=open_tables@entry=false, instr=instr@entry=0x14912404d448, rerun_the_same_instr=rerun_the_same_instr@entry=true)at /test/11.4_dbg/sql/sp_instr.cc:297
      #22 0x000055584b72c727 in sp_lex_keeper::validate_lex_and_exec_core (this=this@entry=0x14912404d480, thd=thd@entry=0x149124000d58, nextp=nextp@entry=0x14918094629c, open_tables=open_tables@entry=false, instr=instr@entry=0x14912404d448) at /test/11.4_dbg/sql/sp_instr.cc:476
      #23 0x000055584b72c89a in sp_lex_keeper::cursor_reset_lex_and_exec_core (this=0x14912404d480, thd=0x149124000d58, nextp=0x14918094629c, open_tables=open_tables@entry=false, instr=0x14912404d448)at /test/11.4_dbg/sql/sp_instr.cc:531
      #24 0x000055584b72c8df in sp_instr_cursor_copy_struct::execute (this=<optimized out>, thd=<optimized out>, nextp=<optimized out>)at /test/11.4_dbg/sql/sp_instr.cc:2078
      #25 0x000055584b4c6d0c in sp_head::execute (this=this@entry=0x149124022b88, thd=thd@entry=0x149124000d58, merge_da_on_success=merge_da_on_success@entry=true)at /test/11.4_dbg/sql/sp_head.cc:1286
      #26 0x000055584b4c7f5d in sp_head::execute_procedure (this=0x149124022b88, thd=thd@entry=0x149124000d58, args=0x149124005f58)at /test/11.4_dbg/sql/sp_head.cc:2302
      #27 0x000055584b55c5c3 in do_execute_sp (thd=thd@entry=0x149124000d58, sp=sp@entry=0x149124022b88) at /test/11.4_dbg/sql/sql_parse.cc:3082
      #28 0x000055584b5605bd in Sql_cmd_call::execute (this=0x149124019c48, thd=0x149124000d58) at /test/11.4_dbg/sql/sql_parse.cc:3305
      #29 0x000055584b56b3ce in mysql_execute_command (thd=thd@entry=0x149124000d58, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false)at /test/11.4_dbg/sql/sql_parse.cc:5878
      #30 0x000055584b56bf41 in mysql_parse (thd=thd@entry=0x149124000d58, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x1491809472f0)at /test/11.4_dbg/sql/sql_parse.cc:7907
      #31 0x000055584b56d563 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x149124000d58, packet=packet@entry=0x14912400b0b9 "CALL p()", packet_length=packet_length@entry=8, blocking=blocking@entry=true)at /test/11.4_dbg/sql/sql_parse.cc:1904
      #32 0x000055584b56ea37 in do_command (thd=thd@entry=0x149124000d58, blocking=blocking@entry=true) at /test/11.4_dbg/sql/sql_parse.cc:1417
      #33 0x000055584b69c487 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5558626ae6e8, put_in_cache=put_in_cache@entry=true)at /test/11.4_dbg/sql/sql_connect.cc:1408
      #34 0x000055584b69c6ac in handle_one_connection (arg=0x5558626ae6e8)at /test/11.4_dbg/sql/sql_connect.cc:1320
      #35 0x0000149187c9caa4 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447
      #36 0x0000149187d29c3c in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
      

      Bug confirmed present in:
      MariaDB: 11.4.6 (dbg), 11.7.2 (dbg), 11.8.0 (dbg)

      Bug (or feature/syntax) confirmed not present in:
      MariaDB: 10.6.21 (dbg), 10.6.21 (opt), 10.11.12 (dbg), 10.11.12 (opt), 11.4.6 (opt), 11.7.2 (opt), 11.8.0 (opt)

      Attachments

        Activity

          ramesh Ramesh Sivaraman added a comment - - edited

          Please also test the fix with following test case

          CREATE TABLE t (a INT);
           
          --delimiter $
          CREATE PROCEDURE p() 
          BEGIN 
          	DECLARE cur CURSOR FOR SELECT * FROM t;
          	BEGIN 
          		DECLARE rec ROW(a INT,b INT) DEFAULT ROW(0,0);
          		DECLARE rec2 ROW TYPE OF cur DEFAULT rec;
          	END;
          END $
           
          --delimiter ;
          --ERROR ER_OPERAND_COLUMNS
          CALL p();
          CREATE OR REPLACE TABLE t (a INT);
          CALL p();
          

          CS 12.0.0 feb1cf9086e7a3d9ddde78a48ada801ee9913285 (Debug) Build 17/03/2025

          Core was generated by `/test/MD170325-mariadb-12.0.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --max'.
          Program terminated with signal SIGSEGV, Segmentation fault.
          #0  0x000055995a1b2586 in Field_row::sp_prepare_and_store_item (this=0x15278001cc68, thd=0x152780000d58, value=0x152780036d70)at /test/12.0_dbg/sql/field.cc:2797
           
          [Current thread is 1 (Thread 0x1527d41696c0 (LWP 2201161))]
          (gdb) bt
          #0  0x000055995a1b2586 in Field_row::sp_prepare_and_store_item (this=0x15278001cc68, thd=0x152780000d58, value=0x152780036d70)at /test/12.0_dbg/sql/field.cc:2797
          #1  0x0000559959cbca78 in THD::sp_eval_expr (this=0x152780000d58, result_field=0x15278001cc68, expr_item_ptr=0x152780036d70)at /test/12.0_dbg/sql/sp_head.cc:444
          #2  0x0000559959cd5583 in sp_rcontext::set_variable (this=0x15278001bf80, thd=0x152780000d58, idx=1, value=0x152780036d70)at /test/12.0_dbg/sql/sp_rcontext.cc:605
          #3  0x000055995a08c452 in sp_instr_set::exec_core (this=0x152780036ce0, thd=0x152780000d58, nextp=0x1527d41657e8)at /test/12.0_dbg/sql/sp_instr.cc:1102
          #4  0x000055995a089ba6 in sp_lex_keeper::reset_lex_and_exec_core (this=0x152780036d18, thd=0x152780000d58, nextp=0x1527d41657e8, open_tables=true, instr=0x152780036ce0, rerun_the_same_instr=false)at /test/12.0_dbg/sql/sp_instr.cc:314
          #5  0x000055995a08a32c in sp_lex_keeper::validate_lex_and_exec_core (this=0x152780036d18, thd=0x152780000d58, nextp=0x1527d41657e8, open_tables=true, instr=0x152780036ce0)at /test/12.0_dbg/sql/sp_instr.cc:493
          #6  0x000055995a08c3be in sp_instr_set::execute (this=0x152780036ce0, thd=0x152780000d58, nextp=0x1527d41657e8)at /test/12.0_dbg/sql/sp_instr.cc:1089
          #7  0x0000559959cbf849 in sp_head::execute (this=0x152780031368, thd=0x152780000d58, merge_da_on_success=true)at /test/12.0_dbg/sql/sp_head.cc:1289
          #8  0x0000559959cc21d1 in sp_head::execute_procedure (this=0x152780031368, thd=0x152780000d58, args=0x152780005ff8)at /test/12.0_dbg/sql/sp_head.cc:2312
          #9  0x0000559959dd52bd in do_execute_sp (thd=0x152780000d58, sp=0x152780031368)at /test/12.0_dbg/sql/sql_parse.cc:3085
          #10 0x0000559959dd4dd4 in Sql_cmd_call::execute (this=0x152780019dd8, thd=0x152780000d58) at /test/12.0_dbg/sql/sql_parse.cc:3308
          #11 0x0000559959de10ff in mysql_execute_command (thd=0x152780000d58, is_called_from_prepared_stmt=false) at /test/12.0_dbg/sql/sql_parse.cc:5886
          #12 0x0000559959dd0314 in mysql_parse (thd=0x152780000d58, rawbuf=0x152780019d30 "CALL p()", length=8, parser_state=0x1527d4167a20)at /test/12.0_dbg/sql/sql_parse.cc:7915
          #13 0x0000559959dcd6e4 in dispatch_command (command=COM_QUERY, thd=0x152780000d58, packet=0x15278000b0a9 "CALL p()", packet_length=8, blocking=true) at /test/12.0_dbg/sql/sql_parse.cc:1902
          #14 0x0000559959dd0ec3 in do_command (thd=0x152780000d58, blocking=true)at /test/12.0_dbg/sql/sql_parse.cc:1415
          #15 0x0000559959fba809 in do_handle_one_connection (connect=0x559979a6f618, put_in_cache=true) at /test/12.0_dbg/sql/sql_connect.cc:1415
          #16 0x0000559959fba5ae in handle_one_connection (arg=0x559979a6ee38)at /test/12.0_dbg/sql/sql_connect.cc:1327
          #17 0x00001527e4c9caa4 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447
          #18 0x00001527e4d29c3c in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
          

          ramesh Ramesh Sivaraman added a comment - - edited Please also test the fix with following test case CREATE TABLE t (a INT );   --delimiter $ CREATE PROCEDURE p() BEGIN DECLARE cur CURSOR FOR SELECT * FROM t; BEGIN DECLARE rec ROW(a INT ,b INT ) DEFAULT ROW(0,0); DECLARE rec2 ROW TYPE OF cur DEFAULT rec; END ; END $   --delimiter ; --ERROR ER_OPERAND_COLUMNS CALL p(); CREATE OR REPLACE TABLE t (a INT ); CALL p(); CS 12.0.0 feb1cf9086e7a3d9ddde78a48ada801ee9913285 (Debug) Build 17/03/2025 Core was generated by `/test/MD170325-mariadb-12.0.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --max'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x000055995a1b2586 in Field_row::sp_prepare_and_store_item (this=0x15278001cc68, thd=0x152780000d58, value=0x152780036d70)at /test/12.0_dbg/sql/field.cc:2797   [Current thread is 1 (Thread 0x1527d41696c0 (LWP 2201161))] (gdb) bt #0 0x000055995a1b2586 in Field_row::sp_prepare_and_store_item (this=0x15278001cc68, thd=0x152780000d58, value=0x152780036d70)at /test/12.0_dbg/sql/field.cc:2797 #1 0x0000559959cbca78 in THD::sp_eval_expr (this=0x152780000d58, result_field=0x15278001cc68, expr_item_ptr=0x152780036d70)at /test/12.0_dbg/sql/sp_head.cc:444 #2 0x0000559959cd5583 in sp_rcontext::set_variable (this=0x15278001bf80, thd=0x152780000d58, idx=1, value=0x152780036d70)at /test/12.0_dbg/sql/sp_rcontext.cc:605 #3 0x000055995a08c452 in sp_instr_set::exec_core (this=0x152780036ce0, thd=0x152780000d58, nextp=0x1527d41657e8)at /test/12.0_dbg/sql/sp_instr.cc:1102 #4 0x000055995a089ba6 in sp_lex_keeper::reset_lex_and_exec_core (this=0x152780036d18, thd=0x152780000d58, nextp=0x1527d41657e8, open_tables=true, instr=0x152780036ce0, rerun_the_same_instr=false)at /test/12.0_dbg/sql/sp_instr.cc:314 #5 0x000055995a08a32c in sp_lex_keeper::validate_lex_and_exec_core (this=0x152780036d18, thd=0x152780000d58, nextp=0x1527d41657e8, open_tables=true, instr=0x152780036ce0)at /test/12.0_dbg/sql/sp_instr.cc:493 #6 0x000055995a08c3be in sp_instr_set::execute (this=0x152780036ce0, thd=0x152780000d58, nextp=0x1527d41657e8)at /test/12.0_dbg/sql/sp_instr.cc:1089 #7 0x0000559959cbf849 in sp_head::execute (this=0x152780031368, thd=0x152780000d58, merge_da_on_success=true)at /test/12.0_dbg/sql/sp_head.cc:1289 #8 0x0000559959cc21d1 in sp_head::execute_procedure (this=0x152780031368, thd=0x152780000d58, args=0x152780005ff8)at /test/12.0_dbg/sql/sp_head.cc:2312 #9 0x0000559959dd52bd in do_execute_sp (thd=0x152780000d58, sp=0x152780031368)at /test/12.0_dbg/sql/sql_parse.cc:3085 #10 0x0000559959dd4dd4 in Sql_cmd_call::execute (this=0x152780019dd8, thd=0x152780000d58) at /test/12.0_dbg/sql/sql_parse.cc:3308 #11 0x0000559959de10ff in mysql_execute_command (thd=0x152780000d58, is_called_from_prepared_stmt=false) at /test/12.0_dbg/sql/sql_parse.cc:5886 #12 0x0000559959dd0314 in mysql_parse (thd=0x152780000d58, rawbuf=0x152780019d30 "CALL p()", length=8, parser_state=0x1527d4167a20)at /test/12.0_dbg/sql/sql_parse.cc:7915 #13 0x0000559959dcd6e4 in dispatch_command (command=COM_QUERY, thd=0x152780000d58, packet=0x15278000b0a9 "CALL p()", packet_length=8, blocking=true) at /test/12.0_dbg/sql/sql_parse.cc:1902 #14 0x0000559959dd0ec3 in do_command (thd=0x152780000d58, blocking=true)at /test/12.0_dbg/sql/sql_parse.cc:1415 #15 0x0000559959fba809 in do_handle_one_connection (connect=0x559979a6f618, put_in_cache=true) at /test/12.0_dbg/sql/sql_connect.cc:1415 #16 0x0000559959fba5ae in handle_one_connection (arg=0x559979a6ee38)at /test/12.0_dbg/sql/sql_connect.cc:1327 #17 0x00001527e4c9caa4 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447 #18 0x00001527e4d29c3c in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

          People

            shulga Dmitry Shulga
            ramesh Ramesh Sivaraman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.