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

Assertion `auto_increment_value' failed in ha_partition::info on INSERT into MEMORY table

Details

    Description

      SET SQL_MODE='';
      CREATE TABLE t (c BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY) ENGINE=MEMORY;
      INSERT INTO t VALUES ('-9e999999');
      ALTER TABLE t PARTITION BY KEY();
      INSERT t VALUES (1);
      

      Leads to:

      10.6.0 9118fd360a3da0bba521caf2a35c424968235ac4 (Debug)

      mysqld: /test/10.6_dbg/sql/ha_partition.cc:8330: virtual int ha_partition::info(uint): Assertion `auto_increment_value' failed.
      

      10.6.0 9118fd360a3da0bba521caf2a35c424968235ac4 (Debug)

      Core was generated by `/test/MD010121-mariadb-10.6.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
      Program terminated with signal SIGABRT, Aborted.
      #0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
          at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
      [Current thread is 1 (Thread 0x15454c146700 (LWP 2550847))]
      (gdb) bt
      #0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
      #1  0x0000563deaa820d7 in my_write_core (sig=sig@entry=6) at /test/10.6_dbg/mysys/stacktrace.c:424
      #2  0x0000563dea216ab1 in handle_fatal_signal (sig=6) at /test/10.6_dbg/sql/signal_handler.cc:330
      #3  <signal handler called>
      #4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
      #5  0x0000154562dc2859 in __GI_abort () at abort.c:79
      #6  0x0000154562dc2729 in __assert_fail_base (fmt=0x154562f58588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x563deadee6ad "auto_increment_value", file=0x563deadea900 "/test/10.6_dbg/sql/ha_partition.cc", line=8330, function=<optimized out>) at assert.c:92
      #7  0x0000154562dd3f36 in __GI___assert_fail (assertion=assertion@entry=0x563deadee6ad "auto_increment_value", file=file@entry=0x563deadea900 "/test/10.6_dbg/sql/ha_partition.cc", line=line@entry=8330, function=function@entry=0x563deadebe50 "virtual int ha_partition::info(uint)") at assert.c:101
      #8  0x0000563dea5463a4 in ha_partition::info (this=0x15451c069ac0, flag=64) at /test/10.6_dbg/sql/ha_partition.cc:8330
      #9  0x0000563dea557415 in ha_partition::update_next_auto_inc_val (this=this@entry=0x15451c069ac0) at /test/10.6_dbg/sql/ha_partition.cc:10538
      #10 0x0000563dea5574c2 in ha_partition::write_row (this=0x15451c069ac0, buf=0x15451c023a88 "\377\001") at /test/10.6_dbg/sql/ha_partition.cc:4397
      #11 0x0000563dea22ae67 in handler::ha_write_row (this=0x15451c069ac0, buf=0x15451c023a88 "\377\001") at /test/10.6_dbg/sql/handler.cc:7144
      #12 0x0000563de9f002ea in write_record (thd=thd@entry=0x15451c000db8, table=table@entry=0x15451c068dc8, info=info@entry=0x15454c144c60, sink=sink@entry=0x0) at /test/10.6_dbg/sql/sql_insert.cc:2104
      #13 0x0000563de9f0c9a5 in mysql_insert (thd=thd@entry=0x15451c000db8, table_list=0x15451c012798, fields=@0x15451c005e28: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x563deb51b0e0 <end_of_list>, last = 0x15451c005e28, elements = 0}, <No data fields>}, values_list=@0x15451c005e70: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x15451c0133a0, last = 0x15451c0133a0, elements = 1}, <No data fields>}, update_fields=@0x15451c005e58: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x563deb51b0e0 <end_of_list>, last = 0x15451c005e58, elements = 0}, <No data fields>}, update_values=@0x15451c005e40: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x563deb51b0e0 <end_of_list>, last = 0x15451c005e40, elements = 0}, <No data fields>}, duplic=DUP_ERROR, ignore=false, result=0x0) at /test/10.6_dbg/sql/sql_insert.cc:1099
      #14 0x0000563de9f5362d in mysql_execute_command (thd=thd@entry=0x15451c000db8) at /test/10.6_dbg/sql/sql_parse.cc:4439
      #15 0x0000563de9f3e072 in mysql_parse (thd=thd@entry=0x15451c000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x15454c1453d0) at /test/10.6_dbg/sql/sql_parse.cc:7881
      #16 0x0000563de9f4c1ec in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x15451c000db8, packet=packet@entry=0x15451c008d39 "INSERT t VALUES (1)", packet_length=packet_length@entry=19) at /test/10.6_dbg/sql/sql_class.h:1293
      #17 0x0000563de9f4f52d in do_command (thd=0x15451c000db8) at /test/10.6_dbg/sql/sql_parse.cc:1348
      #18 0x0000563dea0ab7fc in do_handle_one_connection (connect=<optimized out>, connect@entry=0x563dec5526e8, put_in_cache=put_in_cache@entry=true) at /test/10.6_dbg/sql/sql_connect.cc:1410
      #19 0x0000563dea0abf03 in handle_one_connection (arg=arg@entry=0x563dec5526e8) at /test/10.6_dbg/sql/sql_connect.cc:1312
      #20 0x0000563dea56188f in pfs_spawn_thread (arg=0x563dec47a718) at /test/10.6_dbg/storage/perfschema/pfs.cc:2201
      #21 0x00001545632d0609 in start_thread (arg=<optimized out>) at pthread_create.c:477
      #22 0x0000154562ebf293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      

      10.2.37 (Debug)

      mysqld: /test/10.2_dbg/sql/ha_partition.cc:6601: virtual int ha_partition::info(uint): Assertion `auto_increment_value' failed.
      

      10.2.37 (Debug)

      Core was generated by `/test/MD010121-mariadb-10.2.37-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
      Program terminated with signal SIGABRT, Aborted.
      #0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
          at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
      [Current thread is 1 (Thread 0x153cb8156700 (LWP 2592432))]
      (gdb) bt
      #0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
      #1  0x0000563391ae9c2a in my_write_core (sig=sig@entry=6) at /test/10.2_dbg/mysys/stacktrace.c:382
      #2  0x00005633913dc82b in handle_fatal_signal (sig=6) at /test/10.2_dbg/sql/signal_handler.cc:343
      #3  <signal handler called>
      #4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
      #5  0x0000153cd1842859 in __GI_abort () at abort.c:79
      #6  0x0000153cd1842729 in __assert_fail_base (fmt=0x153cd19d8588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x563391d54d82 "auto_increment_value", file=0x563391d55640 "/test/10.2_dbg/sql/ha_partition.cc", line=6601, function=<optimized out>) at assert.c:92
      #7  0x0000153cd1853f36 in __GI___assert_fail (assertion=assertion@entry=0x563391d54d82 "auto_increment_value", file=file@entry=0x563391d55640 "/test/10.2_dbg/sql/ha_partition.cc", line=line@entry=6601, function=function@entry=0x563391d56558 "virtual int ha_partition::info(uint)") at assert.c:101
      #8  0x0000563391a81f53 in ha_partition::info (this=0x153c640255a8, flag=64) at /test/10.2_dbg/sql/ha_partition.cc:6608
      #9  0x0000563391a87b48 in ha_partition::write_row (this=0x153c640255a8, buf=0x153c64023c70 "\377\001") at /test/10.2_dbg/sql/ha_partition.cc:4147
      #10 0x00005633913eabc6 in handler::ha_write_row (this=0x153c640255a8, buf=0x153c64023c70 "\377\001") at /test/10.2_dbg/sql/handler.cc:6116
      #11 0x00005633911b2623 in write_record (thd=thd@entry=0x153c64000d90, table=table@entry=0x153c640249a0, info=info@entry=0x153cb8153ce0) at /test/10.2_dbg/sql/sql_insert.cc:1939
      #12 0x00005633911bdbba in mysql_insert (thd=thd@entry=0x153c64000d90, table_list=0x153c64011268, fields=@0x153c640056b8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x5633922e4b20 <end_of_list>, last = 0x153c640056b8, elements = 0}, <No data fields>}, values_list=@0x153c64005700: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x153c64011948, last = 0x153c64011948, elements = 1}, <No data fields>}, update_fields=@0x153c640056e8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x5633922e4b20 <end_of_list>, last = 0x153c640056e8, elements = 0}, <No data fields>}, update_values=@0x153c640056d0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x5633922e4b20 <end_of_list>, last = 0x153c640056d0, elements = 0}, <No data fields>}, duplic=DUP_ERROR, ignore=false) at /test/10.2_dbg/sql/sql_insert.cc:1066
      #13 0x00005633911d6558 in mysql_execute_command (thd=thd@entry=0x153c64000d90) at /test/10.2_dbg/sql/sql_parse.cc:4193
      #14 0x00005633911dcea0 in mysql_parse (thd=thd@entry=0x153c64000d90, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x153cb8155550, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.2_dbg/sql/sql_parse.cc:7762
      #15 0x00005633911df9d9 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x153c64000d90, packet=packet@entry=0x153c640195d1 "INSERT t VALUES (1)", packet_length=packet_length@entry=19, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.2_dbg/sql/sql_class.h:1096
      #16 0x00005633911e27e1 in do_command (thd=0x153c64000d90) at /test/10.2_dbg/sql/sql_parse.cc:1381
      #17 0x00005633912e7a61 in do_handle_one_connection (connect=connect@entry=0x5633952e5350) at /test/10.2_dbg/sql/sql_connect.cc:1336
      #18 0x00005633912e7c8c in handle_one_connection (arg=0x5633952e5350) at /test/10.2_dbg/sql/sql_connect.cc:1241
      #19 0x0000153cd1d48609 in start_thread (arg=<optimized out>) at pthread_create.c:477
      #20 0x0000153cd193f293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      

      Bug confirmed present in:
      MariaDB: 10.2.37 (dbg), 10.3.28 (dbg), 10.4.18 (dbg), 10.5.9 (dbg), 10.6.0 (dbg)
      MySQL: 5.5.62 (dbg), 5.6.50 (dbg), 5.7.32 (dbg)

      Bug (or feature/syntax) confirmed not present in:
      MariaDB: 10.2.37 (opt), 10.3.28 (opt), 10.4.18 (opt), 10.5.9 (opt), 10.6.0 (opt)
      MySQL: 5.5.62 (opt), 5.6.50 (opt), 5.7.32 (opt), 8.0.22 (dbg), 8.0.22 (opt)

      Attachments

        Issue Links

          Activity

            ycp Yuchen Pei added a comment -

            Hi holyfoot, this is more of a "for discussion" review request, as I have two provisional commits that I would like your feedback on, one fixing on partition level and one on MEMORY SE level, ptal and let me know whether either is good as a patch to fix this ticket, thanks:

            upstream/bb-10.5-mdev-24610 b28a7be800f923714880a2484d9c3c607d888fe4
            MDEV-24610 Check for partition auto increment overflow
             
            When ha_partition::info() is called with a flag containing
            HA_STATUS_AUTO, it may iterate partitions and call info() on them with
            HA_STATUS_AUTO, and update its own auto increment value with the
            maximum of the partitions.
             
            When info() is called on the MEMORY SE, it could cause an overflow
            when its internal auto increment value is already ULONGLONG_MAX,
            thereby setting the table stats auto increment value to 0.
             
            If such an overflow happens, we return an error in
            ha_partition::info() indicating so.
             
            Note that callsites of ha_partition::update_next_auto_inc_val(), which
            calls ha_partition::info() with HA_STATUS_AUTO, do not handle any
            returned error.
            

            upstream/bb-10.5-mdev-24610-memory-se dae79d0b2b230aad2f2bd740ef4ce1ada4914cd6
            MDEV-24610 MEMORY SE: check overflow in info calls with HA_STATUS_AUTO
            

            ycp Yuchen Pei added a comment - Hi holyfoot , this is more of a "for discussion" review request, as I have two provisional commits that I would like your feedback on, one fixing on partition level and one on MEMORY SE level, ptal and let me know whether either is good as a patch to fix this ticket, thanks: upstream/bb-10.5-mdev-24610 b28a7be800f923714880a2484d9c3c607d888fe4 MDEV-24610 Check for partition auto increment overflow   When ha_partition::info() is called with a flag containing HA_STATUS_AUTO, it may iterate partitions and call info() on them with HA_STATUS_AUTO, and update its own auto increment value with the maximum of the partitions.   When info() is called on the MEMORY SE, it could cause an overflow when its internal auto increment value is already ULONGLONG_MAX, thereby setting the table stats auto increment value to 0.   If such an overflow happens, we return an error in ha_partition::info() indicating so.   Note that callsites of ha_partition::update_next_auto_inc_val(), which calls ha_partition::info() with HA_STATUS_AUTO, do not handle any returned error. upstream/bb-10.5-mdev-24610-memory-se dae79d0b2b230aad2f2bd740ef4ce1ada4914cd6 MDEV-24610 MEMORY SE: check overflow in info calls with HA_STATUS_AUTO

            I'd fix the MEMORY engine here to work like other engines.

            --- a/storage/heap/hp_info.c
            +++ b/storage/heap/hp_info.c
            @@ -40,6 +40,10 @@ int heap_info(reg1 HP_INFO *info,reg2 HEAPINFO *x, int flag )
               x->errkey          = info->errkey;
               x->create_time     = info->s->create_time;
               if (flag & HA_STATUS_AUTO)
            +  {
                 x->auto_increment= info->s->auto_increment + 1;
            +    if (!x->auto_increment)                    /* This shouldn't happen */
            +      x->auto_increment= ~(ulonglong) 0;
            +  }
               DBUG_RETURN(0);
             } /* heap_info */
            
            

            holyfoot Alexey Botchkov added a comment - I'd fix the MEMORY engine here to work like other engines. --- a/storage/heap/hp_info.c +++ b/storage/heap/hp_info.c @@ - 40 , 6 + 40 , 10 @@ int heap_info(reg1 HP_INFO *info,reg2 HEAPINFO *x, int flag ) x->errkey = info->errkey; x->create_time = info->s->create_time; if (flag & HA_STATUS_AUTO) + { x->auto_increment= info->s->auto_increment + 1 ; + if (!x->auto_increment) /* This shouldn't happen */ + x->auto_increment= ~(ulonglong) 0 ; + } DBUG_RETURN( 0 ); } /* heap_info */
            ycp Yuchen Pei added a comment -

            Thanks holyfoot, ptal at the updated patch

            c0034e75351 upstream/bb-10.5-mdev-24610-memory-se MDEV-24610 MEMORY SE: check overflow in info calls with HA_STATUS_AUTO
            

            ycp Yuchen Pei added a comment - Thanks holyfoot , ptal at the updated patch c0034e75351 upstream/bb-10.5-mdev-24610-memory-se MDEV-24610 MEMORY SE: check overflow in info calls with HA_STATUS_AUTO

            ok to push.

            holyfoot Alexey Botchkov added a comment - ok to push.
            ycp Yuchen Pei added a comment -

            Thanks for the review - pushed c4020b541c25b8f8bed2dd2b58d8d7a3a3122495 to 10.5

            ycp Yuchen Pei added a comment - Thanks for the review - pushed c4020b541c25b8f8bed2dd2b58d8d7a3a3122495 to 10.5

            People

              ycp Yuchen Pei
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              6 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.