Bug #89087 Assertion `key->flags & 1' failed
Submitted: 1 Jan 22:26 Modified: 8 Feb 17:51
Reporter: Roel Van de Paar (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S6 (Debug Builds)
Version:5.7.20 OS:Any
Assigned to: CPU Architecture:Any

[1 Jan 22:26] Roel Van de Paar
Description:
Core was generated by `/sda/MS051217-mysql-5.7.20-linux-x86_64-debug/bin/mysqld --no-defaults --core-f'.
Program terminated with signal 6, Aborted.
#0  0x00007f13fde8a9b1 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:61
61	  val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
(gdb) bt
#0  0x00007f13fde8a9b1 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:61
#1  0x0000000001839a31 in my_write_core (sig=6) at /git/mysql-server_dbg/mysys/stacktrace.c:249
#2  0x0000000000e7f378 in handle_fatal_signal (sig=6) at /git/mysql-server_dbg/sql/signal_handler.cc:220
#3  <signal handler called>
#4  0x00007f13fc1a21f7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#5  0x00007f13fc1a38e8 in __GI_abort () at abort.c:90
#6  0x00007f13fc19b266 in __assert_fail_base (fmt=0x7f13fc2ede68 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x20c6745 "key->flags & 1", file=file@entry=0x20c6048 "/git/mysql-server_dbg/storage/innobase/handler/handler0alter.cc", 
    line=line@entry=2016, 
    function=function@entry=0x20ca3a0 <innobase_create_index_def(TABLE const*, st_key const*, unsigned long, bool, bool, index_def_t*, mem_block_info_t*)::__PRETTY_FUNCTION__> "void innobase_create_index_def(const TABLE*, const KEY*, ulint, bool, bool, index_def_t*, mem_heap_t*)") at assert.c:92
#7  0x00007f13fc19b312 in __GI___assert_fail (assertion=0x20c6745 "key->flags & 1", file=0x20c6048 "/git/mysql-server_dbg/storage/innobase/handler/handler0alter.cc", line=2016, 
    function=0x20ca3a0 <innobase_create_index_def(TABLE const*, st_key const*, unsigned long, bool, bool, index_def_t*, mem_block_info_t*)::__PRETTY_FUNCTION__> "void innobase_create_index_def(const TABLE*, const KEY*, ulint, bool, bool, index_def_t*, mem_heap_t*)")
    at assert.c:101
#8  0x00000000019addc2 in innobase_create_index_def (altered_table=0x7f13bfe04220, keys=0x7f13bfd90880, key_number=1, new_clustered=true, key_clustered=true, index=0x7f13c0126940, heap=0x7f13c0126718) at /git/mysql-server_dbg/storage/innobase/handler/handler0alter.cc:2016
#9  0x00000000019aecf6 in innobase_create_key_defs (heap=0x7f13c0126718, ha_alter_info=0x7f13fe47baa0, altered_table=0x7f13bfe04220, n_add=@0x7f13bfd90a98: 1, n_fts_add=@0x7f13fe47ad30: 0, got_default_clust=true, fts_doc_id_col=@0x7f13fe47ae90: 18446744073709551615, 
    add_fts_doc_id=@0x7f13fe47acbc: false, add_fts_doc_idx=@0x7f13fe47acb8: false) at /git/mysql-server_dbg/storage/innobase/handler/handler0alter.cc:2426
#10 0x00000000019b2ff9 in prepare_inplace_alter_table_dict (ha_alter_info=0x7f13fe47baa0, altered_table=0x7f13bfe04220, old_table=0x7f13bfd00e20, table_name=0x7f13c01265f5 "t1", flags=33, flags2=80, fts_doc_id_col=18446744073709551615, add_fts_doc_id=false, 
    add_fts_doc_id_idx=false) at /git/mysql-server_dbg/storage/innobase/handler/handler0alter.cc:4287
#11 0x00000000019b83d7 in ha_innobase::prepare_inplace_alter_table (this=0x7f13c0145830, altered_table=0x7f13bfe04220, ha_alter_info=0x7f13fe47baa0) at /git/mysql-server_dbg/storage/innobase/handler/handler0alter.cc:6085
#12 0x0000000000f0118f in handler::ha_prepare_inplace_alter_table (this=0x7f13c0145830, altered_table=0x7f13bfe04220, ha_alter_info=0x7f13fe47baa0) at /git/mysql-server_dbg/sql/handler.cc:4789
#13 0x0000000001594220 in mysql_inplace_alter_table (thd=0x7f13bfc12000, table_list=0x7f13bfd8fa10, table=0x7f13bfd00e20, altered_table=0x7f13bfe04220, ha_alter_info=0x7f13fe47baa0, inplace_supported=HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE, 
    target_mdl_request=0x7f13fe47b4e0, alter_ctx=0x7f13fe47c030) at /git/mysql-server_dbg/sql/sql_table.cc:7479
#14 0x00000000015994c2 in mysql_alter_table (thd=0x7f13bfc12000, new_db=0x7f13bfd8ff98 "test", new_name=0x0, create_info=0x7f13fe47ccd0, table_list=0x7f13bfd8fa10, alter_info=0x7f13fe47cc20) at /git/mysql-server_dbg/sql/sql_table.cc:9711
#15 0x000000000171126b in Sql_cmd_alter_table::execute (this=0x7f13bfd90140, thd=0x7f13bfc12000) at /git/mysql-server_dbg/sql/sql_alter.cc:316
#16 0x0000000001507885 in mysql_execute_command (thd=0x7f13bfc12000, first_level=true) at /git/mysql-server_dbg/sql/sql_parse.cc:4857
#17 0x00000000015095de in mysql_parse (thd=0x7f13bfc12000, parser_state=0x7f13fe47e550) at /git/mysql-server_dbg/sql/sql_parse.cc:5577
#18 0x00000000014fee90 in dispatch_command (thd=0x7f13bfc12000, com_data=0x7f13fe47ecb0, command=COM_QUERY) at /git/mysql-server_dbg/sql/sql_parse.cc:1461
#19 0x00000000014fdd82 in do_command (thd=0x7f13bfc12000) at /git/mysql-server_dbg/sql/sql_parse.cc:999
#20 0x000000000162e58c in handle_connection (arg=0x7f13d3317d20) at /git/mysql-server_dbg/sql/conn_handler/connection_handler_per_thread.cc:300
#21 0x000000000186617d in pfs_spawn_thread (arg=0x7f13e47dff20) at /git/mysql-server_dbg/storage/perfschema/pfs.cc:2190
#22 0x00007f13fde85e25 in start_thread (arg=0x7f13fe47f700) at pthread_create.c:308
#23 0x00007f13fc26534d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

2018-01-01T22:24:42.186586Z 0 [Note] /sda/MS051217-mysql-5.7.20-linux-x86_64-debug/bin/mysqld: ready for connections.
Version: '5.7.20-debug'  socket: '/sda/MS051217-mysql-5.7.20-linux-x86_64-debug/socket.sock'  port: 19348  MySQL Community Server (GPL)
2018-01-01T22:24:42.186599Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
2018-01-01T22:24:42.186618Z 0 [Note] Beginning of list of non-natively partitioned tables
2018-01-01T22:24:42.204441Z 0 [Note] End of list of non-natively partitioned tables
mysqld: /git/mysql-server_dbg/storage/innobase/handler/handler0alter.cc:2016: void innobase_create_index_def(const TABLE*, const KEY*, ulint, bool, bool, index_def_t*, mem_heap_t*): Assertion `key->flags & 1' failed.
22:24:50 UTC - mysqld got signal 6 ;

How to repeat:
CREATE DATABASE test;
USE test;
set sql_mode=4194304;
CREATE TABLE t1(c1 INT);
ALTER TABLE t1 ADD CONSTRAINT UNIQUE KEY i1(c1);
ALTER TABLE t1 CHANGE c1 c1 INT SIGNED NOT NULL,ADD KEY(c1);
[2 Jan 5:57] Umesh Shastry
Hello Roel,

Thank you for the report and test case.
Observed that 5.7.20 debug build is affected.

Thanks,
Umesh
[2 Jan 5:57] Umesh Shastry
-- 5.7.20 debug build affected

rm -rf 89087
bin/mysqld --initialize-insecure --basedir=$PWD --datadir=$PWD/89087 
bin/mysqld-debug --no-defaults --basedir=$PWD --datadir=$PWD/89087 --core-file --socket=/tmp/mysql_5720.sock --port=5720 --log-error=$PWD/89087/log.err 2>&1 &

(gdb) bt
#0  0x00007f7d5a0b6771 in pthread_kill () from /lib64/libpthread.so.0
#1  0x00000000018d6751 in my_write_core (sig=6) at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/mysys/stacktrace.c:249
#2  0x0000000000ed7e3a in handle_fatal_signal (sig=6) at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/signal_handler.cc:220
#3  <signal handler called>
#4  0x00007f7d58ab05d7 in raise () from /lib64/libc.so.6
#5  0x00007f7d58ab1cc8 in abort () from /lib64/libc.so.6
#6  0x00007f7d58aa9546 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007f7d58aa95f2 in __assert_fail () from /lib64/libc.so.6
#8  0x00000000019f2453 in innobase_create_index_def (altered_table=0x7f7cfc01ae00, keys=0x7f7cfc006e30, key_number=1, new_clustered=true, key_clustered=true,
    index=0x7f7cfc01c180, heap=0x7f7cfc01bf58) at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/storage/innobase/handler/handler0alter.cc:2016
#9  0x00000000019f33b3 in innobase_create_key_defs (heap=0x7f7cfc01bf58, ha_alter_info=0x7f7d380f9860, altered_table=0x7f7cfc01ae00, n_add=@0x7f7cfc007048: 1,
    n_fts_add=@0x7f7d380f8758: 0, got_default_clust=true, fts_doc_id_col=@0x7f7d380f88e0: 18446744073709551615, add_fts_doc_id=@0x7f7d380f86dc: false,
    add_fts_doc_idx=@0x7f7d380f86d8: false) at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/storage/innobase/handler/handler0alter.cc:2426
#10 0x00000000019f77a3 in prepare_inplace_alter_table_dict (ha_alter_info=0x7f7d380f9860, altered_table=0x7f7cfc01ae00, old_table=0x7f7cfc01a460,
    table_name=0x7f7cfc00f4f5 "t1", flags=33, flags2=80, fts_doc_id_col=18446744073709551615, add_fts_doc_id=false, add_fts_doc_id_idx=false)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/storage/innobase/handler/handler0alter.cc:4287
#11 0x00000000019fcd6a in ha_innobase::prepare_inplace_alter_table (this=0x7f7cfc00f720, altered_table=0x7f7cfc01ae00, ha_alter_info=0x7f7d380f9860)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/storage/innobase/handler/handler0alter.cc:6085
#12 0x0000000000f57f67 in handler::ha_prepare_inplace_alter_table (this=0x7f7cfc00f720, altered_table=0x7f7cfc01ae00, ha_alter_info=0x7f7d380f9860)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/handler.cc:4789
#13 0x0000000001621be2 in mysql_inplace_alter_table (thd=0x7f7cfc000b70, table_list=0x7f7cfc005fc0, table=0x7f7cfc01a460, altered_table=0x7f7cfc01ae00,
    ha_alter_info=0x7f7d380f9860, inplace_supported=HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE, target_mdl_request=0x7f7d380fa1f0, alter_ctx=0x7f7d380f8dc0)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/sql_table.cc:7479
#14 0x00000000016270f0 in mysql_alter_table (thd=0x7f7cfc000b70, new_db=0x7f7cfc006548 "test", new_name=0x0, create_info=0x7f7d380fac50, table_list=0x7f7cfc005fc0,
    alter_info=0x7f7d380fad50) at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/sql_table.cc:9711
#15 0x00000000017aa0d1 in Sql_cmd_alter_table::execute (this=0x7f7cfc0066f0, thd=0x7f7cfc000b70)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/sql_alter.cc:316
#16 0x0000000001592426 in mysql_execute_command (thd=0x7f7cfc000b70, first_level=true)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/sql_parse.cc:4857
#17 0x00000000015943b9 in mysql_parse (thd=0x7f7cfc000b70, parser_state=0x7f7d380fc690)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/sql_parse.cc:5577
#18 0x0000000001588d5e in dispatch_command (thd=0x7f7cfc000b70, com_data=0x7f7d380fce00, command=COM_QUERY)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/sql_parse.cc:1461
#19 0x0000000001587b61 in do_command (thd=0x7f7cfc000b70) at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/sql_parse.cc:999
#20 0x00000000016be3c0 in handle_connection (arg=0x4478290)
    at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/sql/conn_handler/connection_handler_per_thread.cc:300
#21 0x0000000001910aa4 in pfs_spawn_thread (arg=0x4467290) at /export/home/pb2/build/sb_0-24964902-1505322971.88/mysql-5.7.20/storage/perfschema/pfs.cc:2190
#22 0x00007f7d5a0b1df5 in start_thread () from /lib64/libpthread.so.0
#23 0x00007f7d58b7160d in clone () from /lib64/libc.so.6
[2 Jan 5:58] Umesh Shastry
-- 5.7.21 only debug build affected

(gdb) bt
#0  0x00007ff4791d3771 in pthread_kill () from /lib64/libpthread.so.0
#1  0x000000000185f6ad in my_write_core (sig=6) at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/mysys/stacktrace.c:249
#2  0x0000000000ea9966 in handle_fatal_signal (sig=6) at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/signal_handler.cc:220
#3  <signal handler called>
#4  0x00007ff477bcd5d7 in raise () from /lib64/libc.so.6
#5  0x00007ff477bcecc8 in abort () from /lib64/libc.so.6
#6  0x00007ff477bc6546 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007ff477bc65f2 in __assert_fail () from /lib64/libc.so.6
#8  0x00000000018ea602 in innobase_create_index_def (altered_table=0x7ff410277a60, keys=0x7ff410045110, key_number=1, new_clustered=true, key_clustered=true,
    index=0x7ff410038b90, heap=0x7ff410038968) at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/storage/innobase/handler/handler0alter.cc:2016
#9  0x00000000018eb536 in innobase_create_key_defs (heap=0x7ff410038968, ha_alter_info=0x7ff458626be0, altered_table=0x7ff410277a60, n_add=@0x7ff410045328: 1,
    n_fts_add=@0x7ff458625e70: 0, got_default_clust=true, fts_doc_id_col=@0x7ff458625fd0: 18446744073709551615, add_fts_doc_id=@0x7ff458625dfc: false,
    add_fts_doc_idx=@0x7ff458625df8: false) at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/storage/innobase/handler/handler0alter.cc:2426
#10 0x00000000018ef839 in prepare_inplace_alter_table_dict (ha_alter_info=0x7ff458626be0, altered_table=0x7ff410277a60, old_table=0x7ff4102705d0,
    table_name=0x7ff41028e785 "t1", flags=33, flags2=80, fts_doc_id_col=18446744073709551615, add_fts_doc_id=false, add_fts_doc_id_idx=false)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/storage/innobase/handler/handler0alter.cc:4287
#11 0x00000000018f4c17 in ha_innobase::prepare_inplace_alter_table (this=0x7ff410011d00, altered_table=0x7ff410277a60, ha_alter_info=0x7ff458626be0)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/storage/innobase/handler/handler0alter.cc:6086
#12 0x0000000000f2b1d3 in handler::ha_prepare_inplace_alter_table (this=0x7ff410011d00, altered_table=0x7ff410277a60, ha_alter_info=0x7ff458626be0)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/handler.cc:4789
#13 0x00000000015bc87c in mysql_inplace_alter_table (thd=0x7ff410047c60, table_list=0x7ff4100442a0, table=0x7ff4102705d0, altered_table=0x7ff410277a60,
    ha_alter_info=0x7ff458626be0, inplace_supported=HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE, target_mdl_request=0x7ff458626620, alter_ctx=0x7ff458627170)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/sql_table.cc:7480
#14 0x00000000015c1b12 in mysql_alter_table (thd=0x7ff410047c60, new_db=0x7ff410044828 "test", new_name=0x0, create_info=0x7ff458627e10, table_list=0x7ff4100442a0,
    alter_info=0x7ff458627d60) at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/sql_table.cc:9712
#15 0x0000000001738d21 in Sql_cmd_alter_table::execute (this=0x7ff4100449d0, thd=0x7ff410047c60)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/sql_alter.cc:316
#16 0x0000000001530880 in mysql_execute_command (thd=0x7ff410047c60, first_level=true)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/sql_parse.cc:4854
#17 0x0000000001532623 in mysql_parse (thd=0x7ff410047c60, parser_state=0x7ff458629690)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/sql_parse.cc:5582
#18 0x0000000001527ec6 in dispatch_command (thd=0x7ff410047c60, com_data=0x7ff458629df0, command=COM_QUERY)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/sql_parse.cc:1458
#19 0x0000000001526e09 in do_command (thd=0x7ff410047c60) at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/sql_parse.cc:999
#20 0x00000000016565d6 in handle_connection (arg=0x48b3da0)
    at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/sql/conn_handler/connection_handler_per_thread.cc:300
#21 0x0000000001cd3fcb in pfs_spawn_thread (arg=0x48c57c0) at /export/home/pb2/build/sb_0-25673884-1510161542.84/mysqlcom-pro-5.7.21/storage/perfschema/pfs.cc:2190
#22 0x00007ff4791cedf5 in start_thread () from /lib64/libpthread.so.0
#23 0x00007ff477c8e60d in clone () from /lib64/libc.so.6
(gdb)

[umshastr@hod03]/export/umesh/server/binaries/GABuilds/mysql-advanced-5.7.21-linux-x86_64: cat docs/INFO_SRC
commit: ddfbfcfdfcb4f77f72e459a293686a2be27af112
date: 2017-11-08 17:46:12 +0530
build-date: 2017-11-08 18:00:52 +0100
short: ddfbfcf
branch: mysql-5.7

MySQL source 5.7.21
[24 Jan 0:10] Jimmy Yang
Posted by developer:
 
Ok, here is the assertion:

2355			DBUG_ASSERT(key->flags & HA_NOSAME);
(gdb) p key->flags 
$1 = 0
(gdb)  p key
$2 = (const KEY *) 0x7fff70135be0
(gdb) p *key
$3 = {key_length = 4, flags = 0, actual_flags = 0, user_defined_key_parts = 1, 
  actual_key_parts = 1, unused_key_parts = 0, usable_key_parts = 1, 
  block_size = 0, algorithm = HA_KEY_ALG_BTREE, is_algorithm_explicit = false, 
  parser = 0x0, parser_name = {str = 0x0, length = 0}, 
  key_part = 0x7fff701abee8, name = 0x7fff70020718 "c1", rec_per_key = 0x0, 
  m_in_memory_estimate = 0, rec_per_key_float = 0x0, is_visible = true, 
  table = 0x0, comment = {str = 0x0, length = 0}}

The situation is in the last alter, server found index c1 can be chosen to be PRIMARY KEY, since it is a unique index on non-nullible column.
However, to be a cluster index, InnoDB assume server will set NOSAME flag on the key to specify that NO duplicate is allowed.

For some reason, server did not set this flag, so the assertion triggered.

So server/runtime needs to check why this flag is not set.
[8 Feb 17:51] Daniel Price
Posted by developer:
 
Fixed as of the upcoming 8.0.5 release, and here's the changelog entry:

An ALTER TABLE operation that modified the nullability of an indexed
column raised an assertion. InnoDB incorrectly assumed that a new primary
key must be added instead of created from an existing unique key.