|
The scenario is the following:
1. "ALTER TABLE t2 NOWAIT ENGINE Aria" is blocked on the try to lock system dictionary when t2 is being closed before altering:
#15 0x0000564d79e3c827 in dict_sys_t::lock_wait (this=0x564d7aaf2440 <dict_sys>, file=0x564d7a4e02e0 "./storage/innobase/dict/dict0dict.cc", line=225)
|
at ./storage/innobase/dict/dict0dict.cc:1001
|
#16 0x0000564d79b2d2be in dict_sys_t::lock (this=0x564d7aaf2440 <dict_sys>, file=0x564d7a4e02e0 "./storage/innobase/dict/dict0dict.cc", line=225)
|
at ./storage/innobase/include/dict0dict.h:1525
|
#17 0x0000564d79e3b264 in dict_table_close (table=0x7f731498c888) at ./storage/innobase/dict/dict0dict.cc:225
|
#18 0x0000564d79cd1c56 in row_prebuilt_free (prebuilt=0x7f7314a723a8) at ./storage/innobase/row/row0mysql.cc:976
|
#19 0x0000564d79b05775 in ha_innobase::close (this=0x7f7314a71b00) at ./storage/innobase/handler/ha_innodb.cc:6352
|
#20 0x0000564d796d3873 in handler::ha_close (this=0x7f7314a71b00) at ./sql/handler.cc:3436
|
#21 0x0000564d794847e8 in closefrm (table=0x7f7314a711e8) at ./sql/table.cc:4537
|
#22 0x0000564d795ee9af in intern_close_table (table=0x7f7314a711e8) at ./sql/table_cache.cc:225
|
#23 0x0000564d795eeb29 in tc_remove_table (table=0x7f7314a711e8) at ./sql/table_cache.cc:263
|
#24 0x0000564d795ef619 in tc_release_table (table=0x7f7314a711e8) at ./sql/table_cache.cc:454
|
#25 0x0000564d7926ddf0 in close_thread_table (thd=0x7f7314005568, table_ptr=0x7f7314005660) at ./sql/sql_base.cc:1015
|
#26 0x0000564d7926d455 in close_all_tables_for_name (thd=0x7f7314005568, share=0x7f7314a0f330, extra=HA_EXTRA_NOT_USED, skip_table=0x0) at ./sql/sql_base.cc:770
|
#27 0x0000564d79436d33 in mysql_alter_table (thd=0x7f7314005568, new_db=0x7f731400a1d0, new_name=0x7f731400a628, create_info=0x7f73291f42d0, table_list=0x7f7314018c48, recreate_info=0x7f73291f41a0,
|
alter_info=0x7f73291f41e0, order_num=0, order=0x0, ignore=false, if_exists=false) at ./sql/sql_table.cc:10653
|
#28 0x0000564d794ef742 in Sql_cmd_alter_table::execute (this=0x7f7314019360, thd=0x7f7314005568) at ./sql/sql_alter.cc:553
|
#29 0x0000564d7932a400 in mysql_execute_command (thd=0x7f7314005568, is_called_from_prepared_stmt=false) at ./sql/sql_parse.cc:6014
|
#30 0x0000564d79330564 in mysql_parse (thd=0x7f7314005568, rawbuf=0x7f73140189d0 "ALTER TABLE t2 NOWAIT ENGINE Aria", length=33, parser_state=0x7f73291f5360) at ./sql/sql_parse.cc:8041
|
2. "CREATE OR REPLACE TABLE t3 (col3 INT) ENGINE=InnoDB;" locks mysql/innodb_table_stats:
(rr) fr 1
|
#1 0x0000564d79bc2aba in lock_table_create (table=0x7f7324002e38, type_mode=3, trx=0x7f7339907180, c_lock=0x0) at ./storage/innobase/lock/lock0lock.cc:3309
|
3309 lock->trx->lock.table_locks.push_back(lock);
|
(rr) p table->name
|
$22 = {m_name = 0x7f73240030f8 "mysql/innodb_table_stats", static part_suffix = "#P#"}
|
(rr) bt
|
#0 std::vector<ib_lock_t*, ut_allocator<ib_lock_t*, true> >::push_back (this=0x7f7339907970, __x=@0x7f7338063a58: 0x7f73399076d8) at /usr/include/c++/10/bits/stl_vector.h:1199
|
#1 0x0000564d79bc2aba in lock_table_create (table=0x7f7324002e38, type_mode=3, trx=0x7f7339907180, c_lock=0x0) at ./storage/innobase/lock/lock0lock.cc:3309
|
#2 0x0000564d79bc38d8 in lock_table_low (table=0x7f7324002e38, mode=LOCK_X, thr=0x7f7318126c98, trx=0x7f7339907180) at ./storage/innobase/lock/lock0lock.cc:3545
|
#3 0x0000564d79bc3bda in lock_table (table=0x7f7324002e38, fktable=0x0, mode=LOCK_X, thr=0x7f7318126c98) at ./storage/innobase/lock/lock0lock.cc:3604
|
#4 0x0000564d79bc455c in lock_table_for_trx (table=0x7f7324002e38, trx=0x7f7339907180, mode=LOCK_X, no_wait=false) at ./storage/innobase/lock/lock0lock.cc:3746
|
#5 0x0000564d79b1798f in ha_innobase::delete_table (this=0x7f7318033890, name=0x7f7338064300 "./test/t3#P#p0") at ./storage/innobase/handler/ha_innodb.cc:13635
|
#6 0x0000564d79a02105 in ha_partition::del_ren_table (this=0x7f7318032ff0, from=0x7f7338065700 "./test/t3", to=0x0) at ./sql/ha_partition.cc:2509
|
#7 0x0000564d799fcacf in ha_partition::delete_table (this=0x7f7318032ff0, name=0x7f7338065700 "./test/t3") at ./sql/ha_partition.cc:633
|
#8 0x0000564d796cbced in hton_drop_table (hton=0x564d7ca7b708, path=0x7f7338065700 "./test/t3") at ./sql/handler.cc:576
|
#9 0x0000564d796d23ed in ha_delete_table (thd=0x7f7318003598, hton=0x564d7ca7b708, path=0x7f7338065700 "./test/t3", db=0x7f73380654d0, alias=0x7f73380654e0, generate_warning=false)
|
at ./sql/handler.cc:3153
|
#10 0x0000564d7941aa48 in mysql_rm_table_no_locks (thd=0x7f7318003598, tables=0x7f7338065c50, current_db=0x7f7318003638, ddl_log_state=0x7f7338066710, if_exists=false, drop_temporary=false, drop_view=false,
|
drop_sequence=false, dont_log_query=true, dont_free_locks=true) at ./sql/sql_table.cc:1469
|
#11 0x0000564d79423b44 in create_table_impl (thd=0x7f7318003598, ddl_log_state_create=0x7f73380666f0, ddl_log_state_rm=0x7f7338066710, orig_db=..., orig_table_name=..., db=..., table_name=..., path=...,
|
options=..., create_info=0x7f73380669d0, alter_info=0x7f73380668e0, create_table_mode=0, is_trans=0x7f73380666ce, key_info=0x7f7338066430, key_count=0x7f7338066424, frm=0x7f7338066450)
|
at ./sql/sql_table.cc:4345
|
#12 0x0000564d794246e9 in mysql_create_table_no_lock (thd=0x7f7318003598, ddl_log_state_create=0x7f73380666f0, ddl_log_state_rm=0x7f7338066710, db=0x7f7318032440, table_name=0x7f7318032450,
|
create_info=0x7f73380669d0, alter_info=0x7f73380668e0, is_trans=0x7f73380666ce, create_table_mode=0, table_list=0x7f7318032428) at ./sql/sql_table.cc:4583
|
#13 0x0000564d79424c8f in mysql_create_table (thd=0x7f7318003598, create_table=0x7f7318032428, create_info=0x7f73380669d0, alter_info=0x7f73380668e0) at ./sql/sql_table.cc:4695
|
#14 0x0000564d7943b4ae in Sql_cmd_create_table_like::execute (this=0x7f73180323c8, thd=0x7f7318003598) at ./sql/sql_table.cc:11959
|
#15 0x0000564d7932a400 in mysql_execute_command (thd=0x7f7318003598, is_called_from_prepared_stmt=false) at ./sql/sql_parse.cc:6014
|
#16 0x0000564d79330564 in mysql_parse (thd=0x7f7318003598, rawbuf=0x7f7318032300 "CREATE OR REPLACE TABLE t3 (col3 INT) ENGINE=InnoDB", length=51, parser_state=0x7f7338067360)
|
at ./sql/sql_parse.cc:8041
|
3. "ALTER TABLE t2 NOWAIT ENGINE Aria" tries to drop t2 innodb table and requests X table lock on mysql.innodb_table_stats, but the lock conflicts with the lock, acquired on the previous step, and the transaction is finished with LOCK_WAIT_TIMEOUT error as NOWAIT keyword is used:
#0 0x0000564d79bc3605 in lock_table_enqueue_waiting (mode=3, table=0x7f7324002e38, thr=0x7f7314a79b98, c_lock=0x7f73399076d8) at ./storage/innobase/lock/lock0lock.cc:3474
|
#1 0x0000564d79bc38bb in lock_table_low (table=0x7f7324002e38, mode=LOCK_X, thr=0x7f7314a79b98, trx=0x7f7339907c80) at ./storage/innobase/lock/lock0lock.cc:3543
|
#2 0x0000564d79bc3bda in lock_table (table=0x7f7324002e38, fktable=0x0, mode=LOCK_X, thr=0x7f7314a79b98) at ./storage/innobase/lock/lock0lock.cc:3604
|
#3 0x0000564d79bc455c in lock_table_for_trx (table=0x7f7324002e38, trx=0x7f7339907c80, mode=LOCK_X, no_wait=false) at ./storage/innobase/lock/lock0lock.cc:3746
|
#4 0x0000564d79b1798f in ha_innobase::delete_table (this=0x7f731401afa8, name=0x7f73291f1c70 "./test/t2") at ./storage/innobase/handler/ha_innodb.cc:13635
|
#5 0x0000564d796cbced in hton_drop_table (hton=0x564d7ca91f58, path=0x7f73291f1c70 "./test/t2") at ./sql/handler.cc:576
|
#6 0x0000564d796d23ed in ha_delete_table (thd=0x7f7314005568, hton=0x564d7ca91f58, path=0x7f73291f1c70 "./test/t2", db=0x7f73291f34c0, alias=0x7f73291f34d0, generate_warning=false)
|
at ./sql/handler.cc:3153
|
#7 0x0000564d7941c1b5 in quick_rm_table (thd=0x7f7314005568, base=0x564d7ca91f58, db=0x7f73291f34c0, table_name=0x7f73291f34d0, flags=4, table_path=0x0) at ./sql/sql_table.cc:1916
|
#8 0x0000564d794372ca in mysql_alter_table (thd=0x7f7314005568, new_db=0x7f731400a1d0, new_name=0x7f731400a628, create_info=0x7f73291f42d0, table_list=0x7f7314018c48, recreate_info=0x7f73291f41a0,
|
alter_info=0x7f73291f41e0, order_num=0, order=0x0, ignore=false, if_exists=false) at ./sql/sql_table.cc:10772
|
#9 0x0000564d794ef742 in Sql_cmd_alter_table::execute (this=0x7f7314019360, thd=0x7f7314005568) at ./sql/sql_alter.cc:553
|
#10 0x0000564d7932a400 in mysql_execute_command (thd=0x7f7314005568, is_called_from_prepared_stmt=false) at ./sql/sql_parse.cc:6014
|
#11 0x0000564d79330564 in mysql_parse (thd=0x7f7314005568, rawbuf=0x7f73140189d0 "ALTER TABLE t2 NOWAIT ENGINE Aria", length=33, parser_state=0x7f73291f5360) at ./sql/sql_parse.cc:8041
|
Note that "test/t2" record was not deleted from sys_tables, as it should be deleted after the lock on mysql.innodb_table_stats is acquired.
4. CREATE OR REPLACE TABLE t2 LIKE t1; gets duplicate key error as "test/t2" record was not deleted from sys_tables:
Thread 2 hit Breakpoint 7, row_ins_duplicate_error_in_clust (flags=0, cursor=0x7f4e800993b0, entry=0x7f4e5805ea28, thr=0x7f4e582aa688) at ./storage/innobase/row/row0ins.cc:2403
|
2403 err = DB_DUPLICATE_KEY;
|
(rr) bt
|
#0 row_ins_duplicate_error_in_clust (flags=0, cursor=0x7f4e800993b0, entry=0x7f4e5805ea28, thr=0x7f4e582aa688) at ./storage/innobase/row/row0ins.cc:2403
|
#1 0x0000555d9d720adb in row_ins_clust_index_entry_low (flags=0, mode=BTR_MODIFY_LEAF, index=0x555da05594c8, n_uniq=1, entry=0x7f4e5805ea28, n_ext=0, thr=0x7f4e582aa688)
|
at ./storage/innobase/row/row0ins.cc:2815
|
#2 0x0000555d9d72218a in row_ins_clust_index_entry (index=0x555da05594c8, entry=0x7f4e5805ea28, thr=0x7f4e582aa688, n_ext=0) at ./storage/innobase/row/row0ins.cc:3239
|
#3 0x0000555d9d7226ec in row_ins_index_entry (index=0x555da05594c8, entry=0x7f4e5805ea28, thr=0x7f4e582aa688) at ./storage/innobase/row/row0ins.cc:3365
|
#4 0x0000555d9d722fc6 in row_ins_index_entry_step (node=0x7f4e5805e2a0, thr=0x7f4e582aa688) at ./storage/innobase/row/row0ins.cc:3533
|
#5 0x0000555d9d7234b8 in row_ins (node=0x7f4e5805e2a0, thr=0x7f4e582aa688) at ./storage/innobase/row/row0ins.cc:3658
|
#6 0x0000555d9d723c20 in row_ins_step (thr=0x7f4e582aa688) at ./storage/innobase/row/row0ins.cc:3787
|
#7 0x0000555d9d6dba92 in que_thr_step (thr=0x7f4e582aa688) at ./storage/innobase/que/que0que.cc:567
|
#8 0x0000555d9d6dbe44 in que_run_threads_low (thr=0x7f4e582aa688) at ./storage/innobase/que/que0que.cc:644
|
#9 0x0000555d9d6dbf5c in que_run_threads (thr=0x7f4e582aa688) at ./storage/innobase/que/que0que.cc:664
|
#10 0x0000555d9d747074 in row_create_table_for_mysql (table=0x7f4e649497c8, trx=0x7f4e80f38180) at ./storage/innobase/row/row0mysql.cc:2110
|
#11 0x0000555d9d5a33ea in create_table_info_t::create_table_def (this=0x7f4e8009a290) at ./storage/innobase/handler/ha_innodb.cc:10957
|
#12 0x0000555d9d586d14 in create_table_info_t::create_table (this=0x7f4e8009a290, create_fk=true) at ./storage/innobase/handler/ha_innodb.cc:12794
|
#13 0x0000555d9d588381 in ha_innobase::create (this=0x7f4e582a91d0, name=0x7f4e8009bcb0 "./test/t2", form=0x7f4e8009a810, create_info=0x7f4e8009c150, file_per_table=true, trx=0x7f4e80f38180)
|
at ./storage/innobase/handler/ha_innodb.cc:13301
|
#14 0x0000555d9d5887a5 in ha_innobase::create (this=0x7f4e582a91d0, name=0x7f4e8009bcb0 "./test/t2", form=0x7f4e8009a810, create_info=0x7f4e8009c150)
|
at ./storage/innobase/handler/ha_innodb.cc:13345
|
#15 0x0000555d9d14d266 in handler::ha_create (this=0x7f4e582a91d0, name=0x7f4e8009bcb0 "./test/t2", form=0x7f4e8009a810, info_arg=0x7f4e8009c150) at ./sql/handler.cc:5505
|
#16 0x0000555d9d14eaf1 in ha_create_table (thd=0x7f4e58003598, path=0x7f4e8009bcb0 "./test/t2", db=0x7f4e58032b10 "test", table_name=0x7f4e580323d0 "t2", create_info=0x7f4e8009c150, frm=0x7f4e8009bca0,
|
skip_frm_file=false) at ./sql/handler.cc:5973
|
#17 0x0000555d9ce9621c in create_table_impl (thd=0x7f4e58003598, ddl_log_state_create=0x7f4e8009bf40, ddl_log_state_rm=0x7f4e8009bf60, orig_db=..., orig_table_name=..., db=..., table_name=..., path=...,
|
options=..., create_info=0x7f4e8009c150, alter_info=0x7f4e8009c060, create_table_mode=0, is_trans=0x7f4e8009bf13, key_info=0x7f4e8009bc80, key_count=0x7f4e8009bc74, frm=0x7f4e8009bca0)
|
at ./sql/sql_table.cc:4484
|
#18 0x0000555d9ce966e9 in mysql_create_table_no_lock (thd=0x7f4e58003598, ddl_log_state_create=0x7f4e8009bf40, ddl_log_state_rm=0x7f4e8009bf60, db=0x7f4e58032420, table_name=0x7f4e58032430,
|
create_info=0x7f4e8009c150, alter_info=0x7f4e8009c060, is_trans=0x7f4e8009bf13, create_table_mode=0, table_list=0x7f4e58032408) at ./sql/sql_table.cc:4583
|
#19 0x0000555d9ce98797 in mysql_create_like_table (thd=0x7f4e58003598, table=0x7f4e58032408, src_table=0x7f4e58032b50, create_info=0x7f4e8009d9d0) at ./sql/sql_table.cc:5207
|
#20 0x0000555d9cead237 in Sql_cmd_create_table_like::execute (this=0x7f4e580323a8, thd=0x7f4e58003598) at ./sql/sql_table.cc:11918
|
#21 0x0000555d9cd9c400 in mysql_execute_command (thd=0x7f4e58003598, is_called_from_prepared_stmt=false) at ./sql/sql_parse.cc:6014
|
#22 0x0000555d9cda2564 in mysql_parse (thd=0x7f4e58003598, rawbuf=0x7f4e58032300 "CREATE OR REPLACE TABLE t2 LIKE t1", length=34, parser_state=0x7f4e8009e360) at ./sql/sql_parse.cc:8041
|
#23 0x0000555d9cd8e878 in dispatch_command (command=COM_QUERY, thd=0x7f4e58003598, packet=0x7f4e5802a1a9 "CREATE OR REPLACE TABLE t2 LIKE t1", packet_length=34, blocking=true)
|
at ./sql/sql_parse.cc:1896
|
The opened question for me is why "CREATE OR REPLACE TABLE t2 LIKE t1" does not remove t2 when it gets duplicate key error.
The error is well reproducible with the test in the description on 10.6 and 11.2 with small change - allow to accept LOCK_WAIT_TIMEOUT error just before "--reap". I can't reproduce it If STATS_PERSISTENT=0 is added to the all tables created in the test, i.e. if persistent statistics update is switched off and there is no need to lock mysql.innodb_table_stats.
|