Bug #74288 Assertion `part_share->partitions_share_refs->num_parts >= m_tot_parts' failed.
Submitted: 9 Oct 2014 4:01 Modified: 11 Mar 2015 14:19
Reporter: Roel Van de Paar (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S1 (Critical)
Version:5.6.22, 5.7.6 OS:Any
Assigned to: CPU Architecture:Any

[9 Oct 2014 4:01] Roel Van de Paar
Description:
===================== Debug Error Log
2014-10-10 00:50:28 7f3f68f4d700  InnoDB: Error; possible reasons:
InnoDB: 1) Table rename would cause two FOREIGN KEY constraints
InnoDB: to have the same internal name in case-insensitive comparison.
InnoDB: 2) table `test`.`t1` /* Partition `p9` */ exists in the InnoDB internal data
InnoDB: dictionary though MySQL is trying to rename table `test`.`t1` /* Temporary Partition `p9` */ to it.
InnoDB: Have you deleted the .frm file and not used DROP TABLE?
InnoDB: You can look for further help from
InnoDB: http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting.html
InnoDB: If table `test`.`t1` /* Partition `p9` */ is a temporary table #sql..., then it can be that
InnoDB: there are still queries running on the table, and it will be
InnoDB: dropped automatically when the queries end.
InnoDB: You can drop the orphaned table inside InnoDB by
InnoDB: creating an InnoDB table with the same name in another
InnoDB: database and copying the .frm file to the current database.
InnoDB: Then MySQL thinks the table exists, and DROP TABLE will
InnoDB: succeed.
2014-10-10 00:50:28 17882 [ERROR] Failed to execute action for entry = 24 from ddl log

===================== Optimized CLI output
mysql> ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
ERROR 1050 (42S01): Table './test/t1#P#p0' already exists

Optimized does not crash, but gives error above + error log looks similar to debug server error log (except the assertion)

===================== GDB Backtrace
#0  0x00007f401b86d771 in pthread_kill () from /lib64/libpthread.so.0
#1  0x0000000000a9035e in my_write_core (sig=6) at /bzr/mysql-5.6/mysys/stacktrace.c:422
#2  0x0000000000723688 in handle_fatal_signal (sig=6) at /bzr/mysql-5.6/sql/signal_handler.cc:230
#3  <signal handler called>
#4  0x00007f401a6795c9 in raise () from /lib64/libc.so.6
#5  0x00007f401a67acd8 in abort () from /lib64/libc.so.6
#6  0x00007f401a672536 in __assert_fail_base () from /lib64/libc.so.6
#7  0x00007f401a6725e2 in __assert_fail () from /lib64/libc.so.6
#8  0x0000000000e07d4a in ha_partition::set_ha_share_ref (this=0x7f3f480afd20, ha_share_arg=0x7f3f4806ba10) at /bzr/mysql-5.6/sql/ha_partition.cc:3084
#9  0x000000000088e814 in open_table_from_share (thd=0x3554840, share=0x7f3f4806b710, alias=0x7f3f480c1460 "t1", db_stat=39, prgflag=44, ha_open_flags=0, outpar
am=0x7f3f4807b970, is_create_table=false) at /bzr/mysql-5.6/sql/table.cc:2131
#10 0x0000000000763e64 in open_table (thd=0x3554840, table_list=0x7f3f480c0ef0, ot_ctx=0x7f3f68f48800) at /bzr/mysql-5.6/sql/sql_base.cc:3159
#11 0x0000000000764aaf in Locked_tables_list::reopen_tables (this=0x3556858, thd=0x3554840) at /bzr/mysql-5.6/sql/sql_base.cc:3610
#12 0x00000000009c537b in handle_alter_part_error (lpt=0x7f3f68f48c40, action_completed=true, drop_partition=false, frm_install=false, close_table=false) at /bz
r/mysql-5.6/sql/sql_partition.cc:6845
#13 0x00000000009c65d8 in fast_alter_partition_table (thd=0x3554840, table=0x7f3f4807b970, alter_info=0x7f3f68f4a690, create_info=0x7f3f68f4a720, table_list=0x7
f3f48006e58, db=0x7f3f480073b8 "test", table_name=0x7f3f48006e20 "t1") at /bzr/mysql-5.6/sql/sql_partition.cc:7256
#14 0x0000000000841bd1 in mysql_alter_table (thd=0x3554840, new_db=0x7f3f480073b8 "test", new_name=0x0, create_info=0x7f3f68f4a720, table_list=0x7f3f48006e58, a
lter_info=0x7f3f68f4a690, order_num=0, order=0x0, ignore=false) at /bzr/mysql-5.6/sql/sql_table.cc:8109
#15 0x000000000098177f in Sql_cmd_alter_table::execute (this=0x7f3f48007610, thd=0x3554840) at /bzr/mysql-5.6/sql/sql_alter.cc:313
#16 0x00000000007d5ea3 in mysql_execute_command (thd=0x3554840) at /bzr/mysql-5.6/sql/sql_parse.cc:4945
#17 0x00000000007d8fa4 in mysql_parse (thd=0x3554840, rawbuf=0x7f3f48006d50 "ALTER TABLE t1 ADD PARTITION PARTITIONS 2", length=41, parser_state=0x7f3f68f4beb0)
 at /bzr/mysql-5.6/sql/sql_parse.cc:6245
#18 0x00000000007cc557 in dispatch_command (command=COM_QUERY, thd=0x3554840, packet=0x9213741 "ALTER TABLE t1 ADD PARTITION PARTITIONS 2", packet_length=41) at
 /bzr/mysql-5.6/sql/sql_parse.cc:1332
#19 0x00000000007cb646 in do_command (thd=0x3554840) at /bzr/mysql-5.6/sql/sql_parse.cc:1034
#20 0x0000000000793a61 in do_handle_one_connection (thd_arg=0x3554840) at /bzr/mysql-5.6/sql/sql_connect.cc:982
#21 0x000000000079354a in handle_one_connection (arg=0x3554840) at /bzr/mysql-5.6/sql/sql_connect.cc:898
#22 0x0000000000ade888 in pfs_spawn_thread (arg=0x91a6960) at /bzr/mysql-5.6/storage/perfschema/pfs.cc:1860
#23 0x00007f401b868df3 in start_thread () from /lib64/libpthread.so.0
#24 0x00007f401a73a01d in clone () from /lib64/libc.so.6

How to repeat:
===================== Testcase
DROP DATABASE test;CREATE DATABASE test;USE test;
CREATE TABLE t1(c1 INT,c2 CHAR)PARTITION BY KEY(c1) PARTITIONS 10;
lock tables t1 write,t1 as t0 write,t1 as t2 read;
alter table t1 add d decimal(0,0);
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
[9 Oct 2014 5:48] Umesh Shastry
Hello Roel,

Thank you for the bug report and test case.
Observed that only debug build asserts.

Thanks,
Umesh
[9 Oct 2014 5:48] Umesh Shastry
// with optimized

mysql> DROP DATABASE test;CREATE DATABASE test;USE test;
Query OK, 0 rows affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
mysql> CREATE TABLE t1(c1 INT,c2 CHAR)PARTITION BY KEY(c1) PARTITIONS 10;
Query OK, 0 rows affected (0.22 sec)

mysql> lock tables t1 write,t1 as t0 write,t1 as t2 read;
Query OK, 0 rows affected (0.00 sec)

mysql> alter table t1 add d decimal(0,0);
Query OK, 0 rows affected (0.47 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
ERROR 1050 (42S01): Table './test/t1#P#p0' already exists
mysql>
mysql> show variables like '%version%';
+-------------------------+---------------------------------------------------------+
| Variable_name           | Value                                                   |
+-------------------------+---------------------------------------------------------+
| innodb_version          | 5.6.22                                                  |
| protocol_version        | 10                                                      |
| slave_type_conversions  |                                                         |
| version                 | 5.6.22-enterprise-commercial-advanced                   |
| version_comment         | MySQL Enterprise Server - Advanced Edition (Commercial) |
| version_compile_machine | x86_64                                                  |
| version_compile_os      | Linux                                                   |
+-------------------------+---------------------------------------------------------+
7 rows in set (0.00 sec)

// With debug builds

mysql> DROP DATABASE test;CREATE DATABASE test;USE test;
Query OK, 1 row affected (0.51 sec)

Query OK, 1 row affected (0.00 sec)

Database changed
mysql> CREATE TABLE t1(c1 INT,c2 CHAR)PARTITION BY KEY(c1) PARTITIONS 10;
Query OK, 0 rows affected (0.34 sec)

mysql> lock tables t1 write,t1 as t0 write,t1 as t2 read;
Query OK, 0 rows affected (0.01 sec)

mysql> alter table t1 add d decimal(0,0);
Query OK, 0 rows affected (0.71 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
ERROR 2013 (HY000): Lost connection to MySQL server during query

//

(gdb) bt
#0  0x0000003bf260c8ac in pthread_kill () from /lib64/libpthread.so.0
#1  0x0000000000afe982 in my_write_core (sig=6) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/mysys/stacktrace.c:422
#2  0x000000000077e6cc in handle_fatal_signal (sig=6) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/signal_handler.cc:230
#3  <signal handler called>
#4  0x0000003bf2232635 in raise () from /lib64/libc.so.6
#5  0x0000003bf2233e15 in abort () from /lib64/libc.so.6
#6  0x0000003bf222b75e in __assert_fail_base () from /lib64/libc.so.6
#7  0x0000003bf222b820 in __assert_fail () from /lib64/libc.so.6
#8  0x0000000000e7f215 in ha_partition::set_ha_share_ref (this=0x7f40100a0100, ha_share_arg=0x7f401005dcf0)
    at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/ha_partition.cc:3119
#9  0x00000000008ef736 in open_table_from_share (thd=0x95512d0, share=0x7f401005d9f0, alias=0x7f4010087b60 "t1", db_stat=39, prgflag=44, ha_open_flags=0, outparam=0x7f401001c7c0,
    is_create_table=false) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/table.cc:2131
#10 0x00000000007c0617 in open_table (thd=0x95512d0, table_list=0x7f40100875f0, ot_ctx=0x7f402d53daa0)
    at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_base.cc:3159
#11 0x00000000007c1243 in Locked_tables_list::reopen_tables (this=0x95532e8, thd=0x95512d0) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_base.cc:3610
#12 0x0000000000a2ed7e in handle_alter_part_error (lpt=0x7f402d53ded0, action_completed=true, drop_partition=false, frm_install=false, close_table=false)
    at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_partition.cc:6845
#13 0x0000000000a2ffd6 in fast_alter_partition_table (thd=0x95512d0, table=0x7f401001c7c0, alter_info=0x7f402d53ff70, create_info=0x7f402d53fe90, table_list=0x7f40100050d8,
    db=0x7f4010005638 "test", table_name=0x7f40100050a0 "t1") at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_partition.cc:7256
#14 0x00000000008a2036 in mysql_alter_table (thd=0x95512d0, new_db=0x7f4010005638 "test", new_name=0x0, create_info=0x7f402d53fe90, table_list=0x7f40100050d8, alter_info=0x7f402d53ff70,
    order_num=0, order=0x0, ignore=false) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_table.cc:8109
#15 0x00000000009e99d6 in Sql_cmd_alter_table::execute (this=0x7f4010005890, thd=0x95512d0) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_alter.cc:313
#16 0x0000000000834385 in mysql_execute_command (thd=0x95512d0) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_parse.cc:4945
#17 0x00000000008375d1 in mysql_parse (thd=0x95512d0, rawbuf=0x7f4010004fd0 "ALTER TABLE t1 ADD PARTITION PARTITIONS 2", length=41, parser_state=0x7f402d541680)
    at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_parse.cc:6245
#18 0x000000000082a3a2 in dispatch_command (command=COM_QUERY, thd=0x95512d0, packet=0x968f7d1 "ALTER TABLE t1 ADD PARTITION PARTITIONS 2", packet_length=41)
    at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_parse.cc:1332
#19 0x0000000000829407 in do_command (thd=0x95512d0) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_parse.cc:1034
#20 0x00000000007f0887 in do_handle_one_connection (thd_arg=0x95512d0) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_connect.cc:982
#21 0x00000000007f0358 in handle_one_connection (arg=0x95512d0) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/sql/sql_connect.cc:898
#22 0x0000000000e5c19d in pfs_spawn_thread (arg=0x9572a40) at /export/home/pb2/build/sb_0-13146752-1409933888.09/mysqlcom-pro-5.6.22/storage/perfschema/pfs.cc:1860
#23 0x0000003bf26079d1 in start_thread () from /lib64/libpthread.so.0
#24 0x0000003bf22e886d in clone () from /lib64/libc.so.6
[9 Oct 2014 5:55] Umesh Shastry
// 5.7.6

(gdb) bt
#0  0x0000003bf260c8ac in pthread_kill () from /lib64/libpthread.so.0
#1  0x0000000000e794c5 in my_write_core (sig=6) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/mysys/stacktrace.c:247
#2  0x000000000086cb4e in handle_fatal_signal (sig=6) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/signal_handler.cc:219
#3  <signal handler called>
#4  0x0000003bf2232635 in raise () from /lib64/libc.so.6
#5  0x0000003bf2233e15 in abort () from /lib64/libc.so.6
#6  0x0000003bf222b75e in __assert_fail_base () from /lib64/libc.so.6
#7  0x0000003bf222b820 in __assert_fail () from /lib64/libc.so.6
#8  0x00000000012a8965 in ha_partition::set_ha_share_ref (this=0x7fe730028e40, ha_share_arg=0x7fe730037678)
    at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/ha_partition.cc:3165
#9  0x0000000000c72b86 in open_table_from_share (thd=0x7fe730000cf0, share=0x7fe730037370, alias=0x7fe730076ce8 "t1", db_stat=39, prgflag=44, ha_open_flags=0, outparam=0x7fe7300ac670,
    is_create_table=false) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/table.cc:2163
#10 0x0000000000b230db in open_table (thd=0x7fe730000cf0, table_list=0x7fe730076760, ot_ctx=0x7fe7ec38c870) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_base.cc:3417
#11 0x0000000000b23dab in Locked_tables_list::reopen_tables (this=0x7fe730002d48, thd=0x7fe730000cf0) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_base.cc:3883
#12 0x0000000000d9d228 in handle_alter_part_error (lpt=0x7fe7ec38cc80, action_completed=true, drop_partition=false, frm_install=false, close_table=false)
    at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_partition.cc:6860
#13 0x0000000000d9e470 in fast_alter_partition_table (thd=0x7fe730000cf0, table=0x7fe730073720, alter_info=0x7fe7ec38ed40, create_info=0x7fe7ec38ec60, table_list=0x7fe730005c40,
    db=0x7fe7300061b8 "test", table_name=0x7fe730005c08 "t1") at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_partition.cc:7271
#14 0x0000000000c22b08 in mysql_alter_table (thd=0x7fe730000cf0, new_db=0x7fe7300061b8 "test", new_name=0x0, create_info=0x7fe7ec38ec60, table_list=0x7fe730005c40, alter_info=0x7fe7ec38ed40)
    at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_table.cc:8320
#15 0x0000000000d6854f in Sql_cmd_alter_table::execute (this=0x7fe730006418, thd=0x7fe730000cf0) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_alter.cc:315
#16 0x0000000000ba8698 in mysql_execute_command (thd=0x7fe730000cf0) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_parse.cc:4815
#17 0x0000000000baa012 in mysql_parse (thd=0x7fe730000cf0, parser_state=0x7fe7ec390660) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_parse.cc:5427
#18 0x0000000000b9dec7 in dispatch_command (command=COM_QUERY, thd=0x7fe730000cf0, packet=0x7fe730009871 "ALTER TABLE t1 ADD PARTITION PARTITIONS 2", packet_length=41)
    at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_parse.cc:1250
#19 0x0000000000b9cb7b in do_command (thd=0x7fe730000cf0) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/sql_parse.cc:834
#20 0x0000000000caa2d8 in handle_connection (arg=0xd372d40) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/sql/conn_handler/connection_handler_per_thread.cc:298
#21 0x0000000001241f24 in pfs_spawn_thread (arg=0xd359b20) at /pb2/build/sb_0-13146106-1409929295.44/mysqlcom-pro-5.7.6-m16/storage/perfschema/pfs.cc:2137
#22 0x0000003bf26079d1 in start_thread () from /lib64/libpthread.so.0
#23 0x0000003bf22e886d in clone () from /lib64/libc.so.6
[11 Mar 2015 14:19] Jon Stephens
Documented fix in the MySQL 5.6.25 and 5.7.7 changelogs as follows:

    Executing an ALTER TABLE on a partitioned table on which a write lock
    was in effect could cause subsequent SQL statements on this table to
    fail.

See also BUG#74451.

Closed.
[16 Mar 2015 12:50] Daniel Price
Posted by developer:
 
This bug is also fixed in trunk (5.8.0). Updated changelog entry to include 5.8.0. 

mysql-trunk$ git show 63b1b64359e87e492aa3f01e5e7b35409012d765
commit 63b1b64359e87e492aa3f01e5e7b35409012d765
Author: Mattias Jonsson <mattias.jonsson@oracle.com>
Date:   Tue Feb 24 21:37:44 2015 +0100

    Bug#19784790: ASSERTION `PART_SHARE->PARTITIONS_SHARE_REFS->NUM_PARTS
                  >= M_TOT_PARTS' FAILED.
    
    Problem in handle_alter_part_error(),
    result in altered partition_info object was still used
    if table was under LOCK TABLES.
    
    Solution was to always close and destroy all table
    and table_share instances if exclusive mdl lock was
    possible.
    If not succeeding in get an exlusive lock (only possible
    during rollback of DDL), at least close and destroy this
    table instance.
[23 Jun 2015 15:11] Laurynas Biveinis
commit 9c02b7d6670b0698669e3ea7fff57c0bf197208b
Author: Mattias Jonsson <mattias.jonsson@oracle.com>
Date:   Tue Feb 24 21:37:44 2015 +0100

    Bug#19784790: ASSERTION `PART_SHARE->PARTITIONS_SHARE_REFS->NUM_PARTS
                  >= M_TOT_PARTS' FAILED.
    
    Problem in handle_alter_part_error(),
    result in altered partition_info object was still used
    if table was under LOCK TABLES.
    
    Solution was to always close and destroy all table
    and table_share instances if exclusive mdl lock was
    possible.
    If not succeeding in get an exlusive lock (only possible
    during rollback of DDL), at least close and destroy this
    table instance.
    
    rb#7361.
    Approved by Mikael and Aditya.