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

Server crashes when creating a table using function with a return type sys_refcursor

Details

    Description

      --delimiter $
       
      CREATE FUNCTION f1() RETURNS SYS_REFCURSOR 
      BEGIN 
        DECLARE c SYS_REFCURSOR;
        OPEN c FOR SELECT 1;
        RETURN c;
      END;
      $
       
      --delimiter ;
       
      CREATE TABLE t1 AS SELECT f1();
       
      DROP FUNCTION f1;
      DROP TABLE t1;
      

      Leads to

      CS 12.0.0 61c96785d1910976fd740aa0724105b16952786d (Debug) Build 21/03/2025

      mariadbd: /test/mtest/12.0_dbg/sql/field.cc:4258: virtual longlong Field_short::val_int(): Assertion `marked_for_read()' failed.
      

      CS 12.0.0 61c96785d1910976fd740aa0724105b16952786d (Debug) Build 21/03/2025

      Core was generated by `/test/mtest/MD210325-mariadb-12.0.0-linux-x86_64-dbg/bin/mariadbd --no-defaults'.
      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 0x14d1ac0a46c0 (LWP 2886792))]
      (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  0x000014d1b244527e in __GI_raise (sig=sig@entry=6)at ../sysdeps/posix/raise.c:26
      #4  0x000014d1b24288ff in __GI_abort () at ./stdlib/abort.c:79
      #5  0x000014d1b242881b in __assert_fail_base (fmt=0x14d1b25d01e8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x560313162313 "marked_for_read()", file=file@entry=0x5603131622f1 "/test/mtest/12.0_dbg/sql/field.cc", line=line@entry=4258, function=function@entry=0x5603131633c5 "virtual longlong Field_short::val_int()") at ./assert/assert.c:96
      #6  0x000014d1b243b517 in __assert_fail (assertion=0x560313162313 "marked_for_read()", file=0x5603131622f1 "/test/mtest/12.0_dbg/sql/field.cc", line=4258, function=0x5603131633c5 "virtual longlong Field_short::val_int()")at ./assert/assert.c:105
      #7  0x00005603124950f7 in Field_short::val_int (this=0x14d1500519d8)at /test/mtest/12.0_dbg/sql/field.cc:4258
      #8  0x000056031303ea75 in Field_sys_refcursor::val_ref (this=0x14d1500519d8, thd=0x14d150000d58)at /test/mtest/12.0_dbg/plugin/type_cursor/plugin.cc:239
      #9  0x0000560313041083 in Field_sys_refcursor::update_to_not_null_ref (this=0x14d1500519d8, ref=0)at /test/mtest/12.0_dbg/plugin/type_cursor/plugin.cc:157
      #10 0x000056031303e993 in Field_sys_refcursor::store_ref (this=0x14d1500519d8, ref=@0x14d1ac0a0140: {<Null_flag> = {m_is_null = false}, m_value = 0}, no_conversions=true)at /test/mtest/12.0_dbg/plugin/type_cursor/plugin.cc:245
      #11 0x00005603130406bb in Field_sys_refcursor::store_item (this=0x14d1500519d8, item=0x14d15001aef8)at /test/mtest/12.0_dbg/plugin/type_cursor/plugin.cc:252
      #12 0x000056031303fa3c in Type_handler_sys_refcursor::Item_save_in_field (this=0x560314535a08 <type_handler_sys_refcursor>, item=0x14d15001aef8, field=0x14d1500519d8, no_conversions=false)at /test/mtest/12.0_dbg/plugin/type_cursor/plugin.cc:410
      #13 0x0000560312508075 in Item::save_in_field (this=0x14d15001aef8, field=0x14d1500519d8, no_conversions=false)at /test/mtest/12.0_dbg/sql/item.cc:7208
      #14 0x0000560311fe6bd9 in fill_record (thd=0x14d150000d58, table=0x14d15005c038, ptr=0x14d1500519c0, values=@0x14d15001aac0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14d15001bb58, last = 0x14d15001bb58, elements = 1}, <No data fields>}, ignore_errors=true, use_value=false, check_for_computability=false)at /test/mtest/12.0_dbg/sql/sql_base.cc:9404
      #15 0x0000560311fe6d7f in fill_record_n_invoke_before_triggers (thd=0x14d150000d58, table=0x14d15005c038, ptr=0x14d1500519b8, values=@0x14d15001aac0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14d15001bb58, last = 0x14d15001bb58, elements = 1}, <No data fields>}, ignore_errors=true, event=TRG_EVENT_INSERT, skip_row_indicator=0x14d1ac0a0376)at /test/mtest/12.0_dbg/sql/sql_base.cc:9463
      #16 0x0000560312047ca1 in select_create::store_values (this=0x14d15001c8b8, values=@0x14d15001aac0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14d15001bb58, last = 0x14d15001bb58, elements = 1}, <No data fields>}, trg_skip_row=0x14d1ac0a0376) at /test/mtest/12.0_dbg/sql/sql_insert.cc:5234
      #17 0x0000560312044baf in select_insert::send_data (this=0x14d15001c8b8, values=@0x14d15001aac0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14d15001bb58, last = 0x14d15001bb58, elements = 1}, <No data fields>})at /test/mtest/12.0_dbg/sql/sql_insert.cc:4355
      #18 0x00005603120064e0 in select_result_sink::send_data_with_check (this=0x14d15001c8b8, items=@0x14d15001aac0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14d15001bb58, last = 0x14d15001bb58, elements = 1}, <No data fields>}, u=0x14d150005150, sent=0) at /test/mtest/12.0_dbg/sql/sql_class.cc:3244
      #19 0x000056031212ef32 in JOIN::exec_inner (this=0x14d15001c9f8)at /test/mtest/12.0_dbg/sql/sql_select.cc:4935
      #20 0x000056031212e75e in JOIN::exec (this=0x14d15001c9f8)at /test/mtest/12.0_dbg/sql/sql_select.cc:4847
      #21 0x00005603121098ad in mysql_select (thd=0x14d150000d58, tables=0x0, fields=@0x14d15001aac0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x14d15001bb58, last = 0x14d15001bb58, elements = 1}, <No data fields>}, conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201187781376, result=0x14d15001c8b8, unit=0x14d150005150, select_lex=0x14d15001a808) at /test/mtest/12.0_dbg/sql/sql_select.cc:5380
      #22 0x0000560312109335 in handle_select (thd=0x14d150000d58, lex=0x14d150005070, result=0x14d15001c8b8, setup_tables_done_option=0)at /test/mtest/12.0_dbg/sql/sql_select.cc:635
      #23 0x00005603121de864 in Sql_cmd_create_table_like::execute (this=0x14d15001a058, thd=0x14d150000d58)at /test/mtest/12.0_dbg/sql/sql_table.cc:13870
      #24 0x00005603120ae7a2 in mysql_execute_command (thd=0x14d150000d58, is_called_from_prepared_stmt=false)at /test/mtest/12.0_dbg/sql/sql_parse.cc:5859
      #25 0x000056031209db04 in mysql_parse (thd=0x14d150000d58, rawbuf=0x14d150019fc0 "CREATE TABLE t1 AS SELECT f1()", length=30, parser_state=0x14d1ac0a2a10) at /test/mtest/12.0_dbg/sql/sql_parse.cc:7889
      #26 0x000056031209aed8 in dispatch_command (command=COM_QUERY, thd=0x14d150000d58, packet=0x14d15000b339 "CREATE TABLE t1 AS SELECT f1()", packet_length=30, blocking=true) at /test/mtest/12.0_dbg/sql/sql_parse.cc:1875
      #27 0x000056031209e6b3 in do_command (thd=0x14d150000d58, blocking=true)at /test/mtest/12.0_dbg/sql/sql_parse.cc:1416
      #28 0x000056031228b799 in do_handle_one_connection (connect=0x5603395bd7d8, put_in_cache=true) at /test/mtest/12.0_dbg/sql/sql_connect.cc:1415
      #29 0x000056031228b53e in handle_one_connection (arg=0x56033957b1d8)at /test/mtest/12.0_dbg/sql/sql_connect.cc:1327
      #30 0x000014d1b249caa4 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447
      #31 0x000014d1b2529c3c in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
      

      Attachments

        Issue Links

          Activity

            bar Alexander Barkov added a comment - - edited

            The patch fixing this problem was incorporated into the main patch for MDEV-20034 in bb-11.4-bar-MDEV-20034.

            It's not yet in preview-12.0-preview at the time of writing.

            bar Alexander Barkov added a comment - - edited The patch fixing this problem was incorporated into the main patch for MDEV-20034 in bb-11.4-bar- MDEV-20034 . It's not yet in preview-12.0-preview at the time of writing.

            People

              bar Alexander Barkov
              ramesh Ramesh Sivaraman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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