Bug #82321 ALTER table failure with DUPLICATE key crash post index build crashes
Submitted: 22 Jul 2016 9:45 Modified: 22 Jul 2016 11:26
Reporter: Krunal Bauskar Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S2 (Serious)
Version:5.6.31 OS:Any
Assigned to: CPU Architecture:Any

[22 Jul 2016 9:45] Krunal Bauskar
Description:
ALTER TABLE failure with DUPLICATE key error post alter table index build crashes server.

How to repeat:

1. Start mysqld with --debug_sync_timeout=1000

2. Open connection-1

use test;
create table t1 (id int, a int, unique key uk(a)) engine = innodb;
insert into t1 select 1, 1;
insert into t1 select 2, 2;
SET DEBUG_SYNC = 'inplace_after_index_build SIGNAL s1 WAIT_FOR s2';
alter table t1 add b int, ALGORITHM=inplace;

3. Open connection-1a.

use test;
SET DEBUG_SYNC = 'now WAIT_FOR s1';
insert into t1 select 3, 1;
SET DEBUG_SYNC = 'now SIGNAL s2';

You will hit following error.

Suggested fix:
Check this bug http://bugs.mysql.com/bug.php?id=82320

Both are related expect that crashing at different point but has same problem.
[22 Jul 2016 11:26] MySQL Verification Team
Hello Krunal,

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

Thanks,
Umesh
[22 Jul 2016 11:27] MySQL Verification Team
-- 5.6.31

(gdb) bt
#0  0x00007f4e36a8f771 in pthread_kill () from /lib64/libpthread.so.0
#1  0x0000000000ae497f in my_write_core (sig=6) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/mysys/stacktrace.c:422
#2  0x000000000074724e in handle_fatal_signal (sig=6) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/signal_handler.cc:230
#3  <signal handler called>
#4  0x00007f4e356955d7 in raise () from /lib64/libc.so.6
#5  0x00007f4e35696cc8 in abort () from /lib64/libc.so.6
#6  0x00007f4e3568e546 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007f4e3568e5f2 in __assert_fail () from /lib64/libc.so.6
#8  0x0000000000b2422b in commit_try_rebuild (ha_alter_info=0x7f4e0c383810, ctx=0x7f4dd80060c0, altered_table=0x7f4dd8040590, old_table=0x7f4dd80449b0, trx=0x7f4dd80422c8,
    table_name=0x7f4dd803bb65 "t1") at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/storage/innobase/handler/handler0alter.cc:4920
#9  0x0000000000b18565 in ha_innobase::commit_inplace_alter_table (this=0x7f4dd80452a0, altered_table=0x7f4dd8040590, ha_alter_info=0x7f4e0c383810, commit=true)
    at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/storage/innobase/handler/handler0alter.cc:5621
#10 0x0000000000651c94 in handler::ha_commit_inplace_alter_table (this=0x7f4dd80452a0, altered_table=0x7f4dd8040590, ha_alter_info=0x7f4e0c383810, commit=true)
    at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/handler.cc:4387
#11 0x000000000086c1e5 in mysql_inplace_alter_table (thd=0x2cd2de0, table_list=0x7f4dd80050d8, table=0x7f4dd80449b0, altered_table=0x7f4dd8040590, ha_alter_info=0x7f4e0c383810,
    inplace_supported=HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE, target_mdl_request=0x7f4e0c384170, alter_ctx=0x7f4e0c382d60)
    at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_table.cc:6685
#12 0x000000000086dc9f in mysql_alter_table (thd=0x2cd2de0, new_db=0x7f4dd8005638 "test", new_name=0x0, create_info=0x7f4e0c384c10, table_list=0x7f4dd80050d8, alter_info=0x7f4e0c384cf0,
    order_num=0, order=0x0, ignore=false) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_table.cc:8511
#13 0x00000000009c0c35 in Sql_cmd_alter_table::execute (this=0x7f4dd8005708, thd=0x2cd2de0) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_alter.cc:313
#14 0x0000000000803cf1 in mysql_execute_command (thd=0x2cd2de0) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_parse.cc:4975
#15 0x000000000080468a in mysql_parse (thd=0x2cd2de0, rawbuf=0x7f4dd8004fd0 "alter table t1 add b int, ALGORITHM=inplace", length=43, parser_state=0x7f4e0c386700)
    at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_parse.cc:6385
#16 0x000000000080628b in dispatch_command (command=COM_QUERY, thd=0x2cd2de0, packet=0x2e02471 "alter table t1 add b int, ALGORITHM=inplace", packet_length=43)
    at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_parse.cc:1339
#17 0x0000000000807b13 in do_command (thd=0x2cd2de0) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_parse.cc:1036
#18 0x00000000007bc759 in do_handle_one_connection (thd_arg=0x2cd2de0) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_connect.cc:982
#19 0x00000000007bc81f in handle_one_connection (arg=0x2cd2de0) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/sql/sql_connect.cc:898
#20 0x0000000000d90b32 in pfs_spawn_thread (arg=0x2de4050) at /export/home/pb2/build/sb_0-18928004-1463437877.21/mysqlcom-pro-5.6.31/storage/perfschema/pfs.cc:1860
#21 0x00007f4e36a8adf5 in start_thread () from /lib64/libpthread.so.0
#22 0x00007f4e3575660d in clone () from /lib64/libc.so.6
(gdb)