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

null field is created with CREATE..SELECT

    XMLWordPrintable

    Details

      Description

      CREATE TABLE t1 SELECT NULL UNION SELECT NULL;
      SHOW CREATE TABLE t1;
      

      results in

      CREATE TABLE `t1` (
        `NULL` null DEFAULT NULL
      ) ENGINE=MEMORY DEFAULT CHARSET=latin1
      

      The null type is not supposed for a user's use. BINARY(0) should be created instead, like in the following case:

      CREATE OR REPLACE TABLE t2 SELECT NULL;
      SHOW CREATE TABLE t2;
      

      Result:

      CREATE TABLE `t2` (
        `NULL` binary(0) DEFAULT NULL
      ) ENGINE=MEMORY DEFAULT CHARSET=latin1
      

      Original report

      Assertion `l_offset >= 0 && table->s->rec_buff_length - l_offset > 0' failed in Field::ptr_in_record and errno: 168 "Unknown (generic) error from engine" from InnoDB on ALTER

      SET storage_engine=MEMORY;
      CREATE TABLE t5 SELECT NULL UNION SELECT NULL;
      ALTER TABLE t5 ADD INDEX (`PRIMARY`);
      

      Leads to:

      10.6.0 9118fd360a3da0bba521caf2a35c424968235ac4 (Debug)

      mysqld: /test/10.6_dbg/sql/field.h:1155: const uchar* Field::ptr_in_record(const uchar*) const: Assertion `l_offset >= 0 && table->s->rec_buff_length - l_offset > 0' 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 0x147124605700 (LWP 350916))]
      (gdb) bt
      #0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
      #1  0x000055b158bd60d7 in my_write_core (sig=sig@entry=6) at /test/10.6_dbg/mysys/stacktrace.c:424
      #2  0x000055b15836aab1 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  0x00001471271c3859 in __GI_abort () at abort.c:79
      #6  0x00001471271c3729 in __assert_fail_base (fmt=0x147127359588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55b158d5ed70 "l_offset >= 0 && table->s->rec_buff_length - l_offset > 0", file=0x55b158d1b63c "/test/10.6_dbg/sql/field.h", line=1155, function=<optimized out>) at assert.c:92
      #7  0x00001471271d4f36 in __GI___assert_fail (assertion=assertion@entry=0x55b158d5ed70 "l_offset >= 0 && table->s->rec_buff_length - l_offset > 0", file=file@entry=0x55b158d1b63c "/test/10.6_dbg/sql/field.h", line=line@entry=1155, function=function@entry=0x55b158d5ed38 "const uchar* Field::ptr_in_record(const uchar*) const") at assert.c:101
      #8  0x000055b15834a238 in Field::ptr_in_record (record=<optimized out>, this=0x1470e0044558) at /test/10.6_dbg/sql/field.h:1155
      #9  Column_definition::Column_definition (this=0x1470e0013220, thd=0x1470e0000db8, old_field=<optimized out>, orig_field=0x1470e0044558) at /test/10.6_dbg/sql/field.cc:10815
      #10 0x000055b158170e10 in Create_field::Create_field (orig_field=0x1470e0044558, old_field=0x1470e0044558, thd=0x1470e0000db8, this=0x1470e0013220) at /test/10.6_dbg/sql/field.h:5605
      #11 mysql_prepare_alter_table (thd=thd@entry=0x1470e0000db8, table=table@entry=0x1470e00440a8, create_info=create_info@entry=0x1471246034a0, alter_info=alter_info@entry=0x1471246033d0, alter_ctx=alter_ctx@entry=0x147124602890) at /test/10.6_dbg/sql/sql_table.cc:8523
      #12 0x000055b158181030 in mysql_alter_table (thd=thd@entry=0x1470e0000db8, new_db=new_db@entry=0x1470e0005828, new_name=new_name@entry=0x1470e0005c28, create_info=create_info@entry=0x1471246034a0, table_list=<optimized out>, table_list@entry=0x1470e00127b8, alter_info=alter_info@entry=0x1471246033d0, order_num=0, order=0x0, ignore=false, if_exists=false) at /test/10.6_dbg/sql/sql_table.cc:10352
      #13 0x000055b158207640 in Sql_cmd_alter_table::execute (this=<optimized out>, thd=0x1470e0000db8) at /test/10.6_dbg/sql/structs.h:559
      #14 0x000055b1580ab4c6 in mysql_execute_command (thd=thd@entry=0x1470e0000db8) at /test/10.6_dbg/sql/sql_parse.cc:5858
      #15 0x000055b158092072 in mysql_parse (thd=thd@entry=0x1470e0000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x1471246043d0) at /test/10.6_dbg/sql/sql_parse.cc:7881
      #16 0x000055b1580a01ec in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x1470e0000db8, packet=packet@entry=0x1470e0008d39 "ALTER TABLE t5 ADD INDEX (`PRIMARY`)", packet_length=packet_length@entry=36) at /test/10.6_dbg/sql/sql_class.h:1293
      #17 0x000055b1580a352d in do_command (thd=0x1470e0000db8) at /test/10.6_dbg/sql/sql_parse.cc:1348
      #18 0x000055b1581ff7fc in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55b15a79eb78, put_in_cache=put_in_cache@entry=true) at /test/10.6_dbg/sql/sql_connect.cc:1410
      #19 0x000055b1581fff03 in handle_one_connection (arg=arg@entry=0x55b15a79eb78) at /test/10.6_dbg/sql/sql_connect.cc:1312
      #20 0x000055b1586b588f in pfs_spawn_thread (arg=0x55b15a6d9f58) at /test/10.6_dbg/storage/perfschema/pfs.cc:2201
      #21 0x00001471276d1609 in start_thread (arg=<optimized out>) at pthread_create.c:477
      #22 0x00001471272c0293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      

      Bug confirmed present in:
      MariaDB: 10.5.9 (dbg), 10.6.0 (dbg)

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

      InnoDB fails also, with errno 168:

      10.6.0 9118fd360a3da0bba521caf2a35c424968235ac4 (Debug)

      10.6.0>SET storage_engine=InnoDB;
      Query OK, 0 rows affected, 1 warning (0.000 sec)
       
      10.6.0>CREATE TABLE t5 SELECT NULL UNION SELECT NULL;
      ERROR 1005 (HY000): Can't create table `test`.`t5` (errno: 168 "Unknown (generic) error from engine")
      

      MyISAM fails in same way as Memory:

      10.6.0 9118fd360a3da0bba521caf2a35c424968235ac4 (Debug)

      mysqld: /test/10.6_dbg/sql/field.h:1155: const uchar* Field::ptr_in_record(const uchar*) const: Assertion `l_offset >= 0 && table->s->rec_buff_length - l_offset > 0' 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 0x151c20142700 (LWP 638377))]
      (gdb) bt
      #0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
      #1  0x00005573bc8800d7 in my_write_core (sig=sig@entry=6) at /test/10.6_dbg/mysys/stacktrace.c:424
      #2  0x00005573bc014ab1 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  0x0000151c22d00859 in __GI_abort () at abort.c:79
      #6  0x0000151c22d00729 in __assert_fail_base (fmt=0x151c22e96588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5573bca08d70 "l_offset >= 0 && table->s->rec_buff_length - l_offset > 0", file=0x5573bc9c563c "/test/10.6_dbg/sql/field.h", line=1155, function=<optimized out>) at assert.c:92
      #7  0x0000151c22d11f36 in __GI___assert_fail (assertion=assertion@entry=0x5573bca08d70 "l_offset >= 0 && table->s->rec_buff_length - l_offset > 0", file=file@entry=0x5573bc9c563c "/test/10.6_dbg/sql/field.h", line=line@entry=1155, function=function@entry=0x5573bca08d38 "const uchar* Field::ptr_in_record(const uchar*) const") at assert.c:101
      #8  0x00005573bbff4238 in Field::ptr_in_record (record=<optimized out>, this=0x151bdc044478) at /test/10.6_dbg/sql/field.h:1155
      #9  Column_definition::Column_definition (this=0x151bdc013220, thd=0x151bdc000db8, old_field=<optimized out>, orig_field=0x151bdc044478) at /test/10.6_dbg/sql/field.cc:10815
      #10 0x00005573bbe1ae10 in Create_field::Create_field (orig_field=0x151bdc044478, old_field=0x151bdc044478, thd=0x151bdc000db8, this=0x151bdc013220) at /test/10.6_dbg/sql/field.h:5605
      #11 mysql_prepare_alter_table (thd=thd@entry=0x151bdc000db8, table=table@entry=0x151bdc043fc8, create_info=create_info@entry=0x151c201404a0, alter_info=alter_info@entry=0x151c201403d0, alter_ctx=alter_ctx@entry=0x151c2013f890) at /test/10.6_dbg/sql/sql_table.cc:8523
      #12 0x00005573bbe2b030 in mysql_alter_table (thd=thd@entry=0x151bdc000db8, new_db=new_db@entry=0x151bdc005828, new_name=new_name@entry=0x151bdc005c28, create_info=create_info@entry=0x151c201404a0, table_list=<optimized out>, table_list@entry=0x151bdc0127b8, alter_info=alter_info@entry=0x151c201403d0, order_num=0, order=0x0, ignore=false, if_exists=false) at /test/10.6_dbg/sql/sql_table.cc:10352
      #13 0x00005573bbeb1640 in Sql_cmd_alter_table::execute (this=<optimized out>, thd=0x151bdc000db8) at /test/10.6_dbg/sql/structs.h:559
      #14 0x00005573bbd554c6 in mysql_execute_command (thd=thd@entry=0x151bdc000db8) at /test/10.6_dbg/sql/sql_parse.cc:5858
      #15 0x00005573bbd3c072 in mysql_parse (thd=thd@entry=0x151bdc000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x151c201413d0) at /test/10.6_dbg/sql/sql_parse.cc:7881
      #16 0x00005573bbd4a1ec in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x151bdc000db8, packet=packet@entry=0x151bdc008d39 "ALTER TABLE t5 ADD INDEX (`PRIMARY`)", packet_length=packet_length@entry=36) at /test/10.6_dbg/sql/sql_class.h:1293
      #17 0x00005573bbd4d52d in do_command (thd=0x151bdc000db8) at /test/10.6_dbg/sql/sql_parse.cc:1348
      #18 0x00005573bbea97fc in do_handle_one_connection (connect=<optimized out>, connect@entry=0x5573bf2629a8, put_in_cache=put_in_cache@entry=true) at /test/10.6_dbg/sql/sql_connect.cc:1410
      #19 0x00005573bbea9f03 in handle_one_connection (arg=arg@entry=0x5573bf2629a8) at /test/10.6_dbg/sql/sql_connect.cc:1312
      #20 0x00005573bc35f88f in pfs_spawn_thread (arg=0x5573bf18a898) at /test/10.6_dbg/storage/perfschema/pfs.cc:2201
      #21 0x0000151c2320e609 in start_thread (arg=<optimized out>) at pthread_create.c:477
      #22 0x0000151c22dfd293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      

      10.4 (dbg) does not fail:

      10.4.18 3454b5cf35a61e8f6cfab376638520dee4a50609 (Debug)

      10.4.18>ALTER TABLE t5 ADD INDEX (`PRIMARY`);
      ERROR 1072 (42000): Key column 'PRIMARY' doesn't exist in table
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              nikitamalyavin Nikita Malyavin
              Reporter:
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration