[MDEV-17432] Assertion `lock_trx_has_sys_table_locks(trx) == 0' failed upon ALTER TABLE .. ADD FOREIGN KEY Created: 2018-10-11  Updated: 2018-12-03  Resolved: 2018-12-02

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Storage Engine - InnoDB
Affects Version/s: 10.4.0
Fix Version/s: 10.4.1, 10.2.20, 10.3.12

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Thirunarayanan Balathandayuthapani
Resolution: Fixed Votes: 0
Labels: affects-tests

Issue Links:
Relates
relates to MDEV-17859 Operating system errors in file opera... Closed

 Description   

--source include/have_innodb.inc
CREATE TABLE t5 (i1 int, v1 varchar(1), KEY v1 (v1,i1), FULLTEXT KEY v1_2 (v1)) ENGINE=InnoDB ;
ALTER TABLE t5 ADD FOREIGN KEY x (v1) REFERENCES t5 (vcol2) ;

 10.4 f545e3cfa9fcc6b706a6e0ee6f2af2124e514e18
10.4/storage/innobase/row/row0mysql.cc:3481: dberr_t row_drop_table_for_mysql(const char*, trx_t*, enum_sql_command, bool, bool): Assertion `lock_trx_has_sys_table_locks(trx) == 0' failed.
181012 11:06:31 [ERROR] mysqld got signal 6 ;
 
Server version: 10.4.0-MariaDB-debug-log
linux/raise.c:54(__GI_raise)[0x7fad04548428]
stdlib/abort.c:91(__GI_abort)[0x7fad0454a02a]
assert/assert.c:92(__assert_fail_base)[0x7fad04540bd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7fad04540c82]
row/row0mysql.cc:3484(row_drop_table_for_mysql(char const*, trx_t*, enum_sql_command, bool, bool))[0x555c100c01d6]
row/row0mysql.cc:2693(row_table_add_foreign_constraints(trx_t*, char const*, unsigned long, char const*, bool))[0x555c100bc626]
handler/ha_innodb.cc:12389(create_table_info_t::create_table(bool))[0x555c0fe3bfae]
handler/ha_innodb.cc:12585(ha_innobase::create(char const*, TABLE*, HA_CREATE_INFO*, bool, trx_t*))[0x555c0fe67a38]
handler/ha_innodb.cc:12632(ha_innobase::create(char const*, TABLE*, HA_CREATE_INFO*))[0x555c0fe3ce14]
sql/handler.cc:4595(handler::ha_create(char const*, TABLE*, HA_CREATE_INFO*))[0x555c0f6161d0]
sql/handler.cc:4969(ha_create_table(THD*, char const*, char const*, char const*, HA_CREATE_INFO*, st_mysql_const_unsigned_lex_string*))[0x555c0f618fef]
sql/sql_table.cc:9760(mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool))[0x555c0f1395dd]
sql/sql_alter.cc:497(Sql_cmd_alter_table::execute(THD*))[0x555c0f277208]
sql/sql_parse.cc:6288(mysql_execute_command(THD*))[0x555c0ef30b73]
sql/sql_parse.cc:8087(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x555c0ef3b389]
sql/sql_parse.cc:1852(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x555c0ef1629b]
sql/sql_parse.cc:1395(do_command(THD*))[0x555c0ef13433]
sql/sql_connect.cc:1402(do_handle_one_connection(CONNECT*))[0x555c0f26869a]
sql/sql_connect.cc:1309(handle_one_connection)[0x555c0f268077]
perfschema/pfs.cc:1864(pfs_spawn_thread)[0x555c1057412b]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7fad051856ba]
x86_64/clone.S:111(clone)[0x7fad0461a41d]
 
Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (0x62b00007e288): ALTER TABLE t5 ADD FOREIGN KEY x (v1) REFERENCES t5 (vcol2)
Connection ID (thread ID): 9
Status: NOT_KILLED



 Comments   
Comment by Marko Mäkelä [ 2018-11-23 ]

This does not crash in 10.3:

10.3 06e5f28f9f132aee0413701baf05cc518964debf

mysqltest: At line 3: query 'ALTER TABLE t5 ADD FOREIGN KEY x (v1) REFERENCES t5 (vcol2) ' failed: 1005: Can't create table `test`.`#sql-84d7_9` (errno: 150 "Foreign key constraint is incorrectly formed")

By allowing the use of ALGORITHM=INPLACE (by disabling foreign key checks) we get a better error message:

--source include/have_innodb.inc
set foreign_key_checks=0;
CREATE TABLE t5 (i1 int, v1 varchar(1), KEY v1 (v1,i1), FULLTEXT KEY v1_2 (v1)) ENGINE=InnoDB ;
ALTER TABLE t5 ADD FOREIGN KEY x (v1) REFERENCES t5 (vcol2) ;
DROP TABLE t5;

mysqltest: At line 4: query 'ALTER TABLE t5 ADD FOREIGN KEY x (v1) REFERENCES t5 (vcol2) ' failed: 1822: Failed to add the foreign key constaint. Missing index for constraint 'x' in the referenced table 't5'

On 10.4, the latter test gives the same error, but with ALGORITHM=COPY the operation does fail as described.

Something could have changed in the way how row_drop_table_for_mysql() is being invoked.

Comment by Marko Mäkelä [ 2018-12-03 ]

Due to MDEV-17859, also the 10.2 and 10.3 branches were affected. But, there was no affected 10.2 or 10.3 release. The only affected release is 10.4.0.

Generated at Thu Feb 08 08:36:25 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.