Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-29849

Assertion `lock->trx == this' failed in drop.cc:163

Details

    Description

      origin/10.6 ab0190101b0587e0e03b2d75a967050b9a85fd1b 2022-10-21T10:02:54+03:00
       
      When executing some RQG test fiddling with FOREIGN KEYs I hit
      | [rr 1908875 679014]mysqld: /data/Server/10.6C/storage/innobase/dict/drop.cc:163: dberr_t trx_t::drop_table(const dict_table_t&): Assertion `lock->trx == this' failed.
       
      (rr) bt
      #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
      #1  0x00003a157a182859 in __GI_abort () at abort.c:79
      #2  0x00003a157a182729 in __assert_fail_base (fmt=0x3a157a318588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55c1fd25e440 "lock->trx == this", file=0x55c1fd25dde0 "/data/Server/10.6C/storage/innobase/dict/drop.cc", 
          line=163, function=<optimized out>) at assert.c:92
      #3  0x00003a157a193f36 in __GI___assert_fail (assertion=0x55c1fd25e440 "lock->trx == this", file=0x55c1fd25dde0 "/data/Server/10.6C/storage/innobase/dict/drop.cc", line=163, 
          function=0x55c1fd25e2e0 "dberr_t trx_t::drop_table(const dict_table_t&)") at assert.c:101
      #4  0x000055c1fc21acc5 in trx_t::drop_table (this=0x73670f596440, table=...) at /data/Server/10.6C/storage/innobase/dict/drop.cc:163
      #5  0x000055c1fbb7f9a8 in ha_innobase::truncate (this=0x61d0011602b8) at /data/Server/10.6C/storage/innobase/handler/ha_innodb.cc:13999
      #6  0x000055c1fb29c284 in handler::ha_truncate (this=0x61d0011602b8) at /data/Server/10.6C/sql/handler.cc:5083
      #7  0x000055c1faf2977f in Sql_cmd_truncate_table::handler_truncate (this=0x62b0000c4a88, thd=0x62b0000bd218, table_ref=0x62b0000c4368, is_tmp_table=false) at /data/Server/10.6C/sql/sql_truncate.cc:255
      #8  0x000055c1faf2aef7 in Sql_cmd_truncate_table::truncate_table (this=0x62b0000c4a88, thd=0x62b0000bd218, table_ref=0x62b0000c4368) at /data/Server/10.6C/sql/sql_truncate.cc:507
      #9  0x000055c1faf2b364 in Sql_cmd_truncate_table::execute (this=0x62b0000c4a88, thd=0x62b0000bd218) at /data/Server/10.6C/sql/sql_truncate.cc:573
      #10 0x000055c1faac67cc in mysql_execute_command (thd=0x62b0000bd218, is_called_from_prepared_stmt=false) at /data/Server/10.6C/sql/sql_parse.cc:5997
      #11 0x000055c1faad27d1 in mysql_parse (thd=0x62b0000bd218, rawbuf=0x62b0000c4238 "TRUNCATE TABLE child /* E_R Thread1 QNO 899 CON_ID 16 */", length=56, parser_state=0x640009c479b0) at /data/Server/10.6C/sql/sql_parse.cc:8016
      #12 0x000055c1faaab2b4 in dispatch_command (command=COM_QUERY, thd=0x62b0000bd218, packet=0x629000bfe219 "TRUNCATE TABLE child /* E_R Thread1 QNO 899 CON_ID 16 */ ", packet_length=57, blocking=true)
          at /data/Server/10.6C/sql/sql_parse.cc:1896
      #13 0x000055c1faaa8815 in do_command (thd=0x62b0000bd218, blocking=true) at /data/Server/10.6C/sql/sql_parse.cc:1409
      #14 0x000055c1faea2e66 in do_handle_one_connection (connect=0x608000003238, put_in_cache=true) at /data/Server/10.6C/sql/sql_connect.cc:1416
      #15 0x000055c1faea27ee in handle_one_connection (arg=0x608000002d38) at /data/Server/10.6C/sql/sql_connect.cc:1318
      #16 0x0000751a0b860609 in start_thread (arg=<optimized out>) at pthread_create.c:477
      #17 0x00003a157a27f293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      (rr)
       
      pluto:/data/results/1666377533/TBR-1181$ _RR_TRACE_DIR=./1/rr/ rr replay --mark-stdio
       
      How to replay the problem
      ----------------------------------------
      git clone https://github.com/mleich1/rqg --branch experimental RQG
      make a MariaDB build with ASAN and install in <somewhere>
       
      cd <RQG>
      ./REPLAY_SIMP.sh TBR-1181.cfg /Server_bin/10.6_asan
           The first 
      

      Attachments

        1. TBR-1181.cfg
          43 kB
        2. TBR-1600.yy
          0.7 kB
        3. TBR-1600.zz
          1 kB

        Issue Links

          Activity

            I am getting a double-assertion-failure on 10.6+, one of parallel assertions looks somewhat similar to this one, hopefully it's the same problem. It also involves FK tampering and TRUNCATE.
            The test case is non-deterministic, run with --repeat=N. It usually fails for me within 5-10 attempts, but sometimes it gets out of luck and takes longer.

            --source include/have_innodb.inc
            --source include/have_sequence.inc
             
            CREATE TABLE A (
              pk int,
              a varchar(8),
              b varchar(8),
              c datetime,
              key(a),
              primary key (pk)
            ) ENGINE=InnoDB;
             
            CREATE TABLE B (pk INT PRIMARY KEY, d DATETIME, KEY(d)) ENGINE=InnoDB;
            INSERT INTO B SELECT seq, '0000-00-00 00:00:00' FROM seq_1_to_50;
             
            --connect (con1,localhost,root,,test)
            ALTER TABLE A ADD KEY test_idx(b), ADD CONSTRAINT f1 FOREIGN KEY (b) REFERENCES A (a), ADD FOREIGN KEY (c) REFERENCES B (d);
            SET FOREIGN_KEY_CHECKS=0;
            DROP INDEX test_idx ON A;
            SET FOREIGN_KEY_CHECKS=1;
            --error ER_CANNOT_ADD_FOREIGN
            TRUNCATE TABLE A;
            --send
              DELETE FROM B;
             
            --connection default
            --error ER_CANNOT_ADD_FOREIGN
            TRUNCATE TABLE A;
             
            --connection con1
            --reap
            DROP TABLE A, B;
            

            Note there are two thread stack traces, each with its own assertion failure

            10.6 c92c1615

            Thread 1 (Thread 0x7fb971b7b700 (LWP 3804225)):
            #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
            #1  0x00007fb980792537 in __GI_abort () at abort.c:79
            #2  0x00007fb98079240f in __assert_fail_base (fmt=0x7fb98090a6a8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x558045d62880 "lock->trx == trx", file=0x558045d5c820 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/lock/lock0lock.cc", line=4154, function=<optimized out>) at assert.c:92
            #3  0x00007fb9807a1662 in __GI___assert_fail (assertion=0x558045d62880 "lock->trx == trx", file=0x558045d5c820 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/lock/lock0lock.cc", line=4154, function=0x558045d62f20 "void lock_release_on_rollback(trx_t*, dict_table_t*)") at assert.c:101
            #4  0x0000558044810a99 in lock_release_on_rollback (trx=0x7fb977334940, table=0x61800004cd20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/lock/lock0lock.cc:4154
            #5  0x0000558044e4bd03 in row_undo_ins_remove_clust_rec (node=0x61b0000b7d20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0uins.cc:153
            #6  0x0000558044e4ebbf in row_undo_ins (node=0x61b0000b7d20, thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0uins.cc:608
            #7  0x0000558044a9b475 in row_undo (node=0x61b0000b7d20, thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0undo.cc:401
            #8  0x0000558044a9b957 in row_undo_step (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0undo.cc:452
            #9  0x000055804494323e in que_thr_step (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/que/que0que.cc:651
            #10 0x00005580449435fd in que_run_threads_low (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/que/que0que.cc:709
            #11 0x000055804494379b in que_run_threads (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/que/que0que.cc:729
            #12 0x0000558044b38a10 in trx_t::rollback_low (this=0x7fb977334940, savept=0x0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/trx/trx0roll.cc:125
            #13 0x0000558044b32b38 in trx_rollback_for_mysql_low (trx=0x7fb977334940) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/trx/trx0roll.cc:196
            #14 0x0000558044b331de in trx_rollback_for_mysql (trx=0x7fb977334940) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/trx/trx0roll.cc:231
            #15 0x00005580446dc9af in ha_innobase::create (this=0x61d0000ef6b8, name=0x6190000ea750 "test/A", form=0x6190000e9298, create_info=0x7fb971b78900, file_per_table=true, trx=0x7fb977334940) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/handler/ha_innodb.cc:13285
            #16 0x00005580446aa1d1 in ha_innobase::truncate (this=0x61d0000ef6b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/handler/ha_innodb.cc:14019
            #17 0x0000558043d84282 in handler::ha_truncate (this=0x61d0000ef6b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/handler.cc:5083
            #18 0x0000558043a1b5c6 in Sql_cmd_truncate_table::handler_truncate (this=0x62b0000c4a38, thd=0x62b0000bd218, table_ref=0x62b0000c4318, is_tmp_table=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_truncate.cc:255
            #19 0x0000558043a1cd18 in Sql_cmd_truncate_table::truncate_table (this=0x62b0000c4a38, thd=0x62b0000bd218, table_ref=0x62b0000c4318) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_truncate.cc:507
            #20 0x0000558043a1d166 in Sql_cmd_truncate_table::execute (this=0x62b0000c4a38, thd=0x62b0000bd218) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_truncate.cc:573
            #21 0x00005580435bbd2f in mysql_execute_command (thd=0x62b0000bd218, is_called_from_prepared_stmt=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:5997
            #22 0x00005580435c7b57 in mysql_parse (thd=0x62b0000bd218, rawbuf=0x62b0000c4238 "TRUNCATE TABLE A", length=16, parser_state=0x7fb971b79a20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:8016
            #23 0x00005580435a0610 in dispatch_command (command=COM_QUERY, thd=0x62b0000bd218, packet=0x62900028a219 "TRUNCATE TABLE A", packet_length=16, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1896
            #24 0x000055804359da8e in do_command (thd=0x62b0000bd218, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1409
            #25 0x0000558043994caf in do_handle_one_connection (connect=0x608000003338, put_in_cache=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1416
            #26 0x0000558043994670 in handle_one_connection (arg=0x6080000032b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1318
            #27 0x00005580444b1832 in pfs_spawn_thread (arg=0x617000007418) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/perfschema/pfs.cc:2201
            #28 0x00007fb980c7fea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
            #29 0x00007fb98086caef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
             
            Thread 7 (Thread 0x7fb970e80700 (LWP 3804229)):
            #0  0x00007fb980860def in __GI___poll (fds=0x558047dea240 <poll_fds>, nfds=1, timeout=500) at ../sysdeps/unix/sysv/linux/poll.c:29
            #1  0x00007fb98127f1b2 in __interceptor_poll (fds=0x558047dea240 <poll_fds>, nfds=1, timeout=500) at ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3904
            #2  0x000055804506f90f in addr_resolve (ptr=0x43df1, loc=0x7fb970e79600) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/my_addr_resolve.c:245
            #3  0x000055804506fe5e in my_addr_resolve (ptr=0x7fb981266df1 <__interceptor_backtrace(void**, int)+49>, loc=0x7fb970e79600) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/my_addr_resolve.c:336
            #4  0x00005580450139f6 in print_with_addr_resolve (addrs=0x7fb970e796c0, n=32) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/stacktrace.c:197
            #5  0x0000558045013ce5 in my_print_stacktrace (stack_bottom=0x7fb970e7fb70 "\030\302\017", thread_stack=1048576, silent=0 '\000') at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/stacktrace.c:216
            #6  0x0000558043d5ddbd in handle_fatal_signal (sig=6) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/signal_handler.cc:233
            #7  <signal handler called>
            #8  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
            #9  0x00007fb980792537 in __GI_abort () at abort.c:79
            #10 0x00007fb98079240f in __assert_fail_base (fmt=0x7fb98090a6a8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x558045fad300 "mode == 16 || mode == 12", file=0x558045fa9960 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc", line=2523, function=<optimized out>) at assert.c:92
            #11 0x00007fb9807a1662 in __GI___assert_fail (assertion=0x558045fad300 "mode == 16 || mode == 12", file=0x558045fa9960 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc", line=2523, function=0x558045facf00 "buf_block_t* buf_page_get_low(page_id_t, ulint, ulint, buf_block_t*, ulint, mtr_t*, dberr_t*, bool)") at assert.c:101
            #12 0x0000558044c39991 in buf_page_get_low (page_id=..., zip_size=0, rw_latch=1, guess=0x7fb9762ab2a0, mode=10, mtr=0x7fb970e7bfa0, err=0x7fb970e7aa40, allow_ibuf_merge=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc:2523
            #13 0x0000558044c3be9d in buf_page_get_gen (page_id=..., zip_size=0, rw_latch=1, guess=0x7fb9762ab2a0, mode=10, mtr=0x7fb970e7bfa0, err=0x7fb970e7aa40, allow_ibuf_merge=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc:2962
            #14 0x0000558044bda64c in btr_cur_search_to_nth_level (index=0x616000bbe720, level=0, tuple=0x6170000d2138, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7fb970e7bb90, mtr=0x7fb970e7bfa0, autoinc=0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/btr/btr0cur.cc:1571
            #15 0x00005580446d4753 in btr_pcur_open_low (index=0x616000bbe720, level=0, tuple=0x6170000d2138, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7fb970e7bb90, autoinc=0, mtr=0x7fb970e7bfa0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/include/btr0pcur.inl:341
            #16 0x00005580449c2cb6 in row_ins_check_foreign_constraint (check_ref=0, foreign=0x616000bd1c20, table=0x61800004b520, entry=0x6170000d2138, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0ins.cc:1626
            #17 0x0000558044aa3f9e in row_upd_check_references_constraints (node=0x620000016bd0, pcur=0x7fb970e7c720, table=0x61800004b520, index=0x6160009ee020, offsets=0x61a0000c3790, thr=0x62400010c1a0, mtr=0x7fb970e7ca10) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:252
            #18 0x0000558044aae308 in row_upd_sec_index_entry (node=0x620000016bd0, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2043
            #19 0x0000558044aaeac1 in row_upd_sec_step (node=0x620000016bd0, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2095
            #20 0x0000558044ab383d in row_upd (node=0x620000016bd0, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2819
            #21 0x0000558044ab4002 in row_upd_step (thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2934
            #22 0x0000558044a12775 in row_update_for_mysql (prebuilt=0x620000016120) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0mysql.cc:1690
            #23 0x000055804468e0b6 in ha_innobase::delete_row (this=0x61d00028b4b8, record=0x6190000e1fc8 "\375\"") at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/handler/ha_innodb.cc:8773
            #24 0x0000558043d98fcb in handler::ha_delete_row (this=0x61d00028b4b8, buf=0x6190000e1fc8 "\375\"") at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/handler.cc:7713
            #25 0x00005580441b969a in TABLE::delete_row (this=0x6190000e1a98) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_delete.cc:281
            #26 0x00005580441b2090 in mysql_delete (thd=0x62b0000fc218, table_list=0x62b000103328, conds=0x0, order_list=0x62b000101090, limit=18446744073709551582, options=0, result=0x0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_delete.cc:830
            #27 0x00005580435b336c in mysql_execute_command (thd=0x62b0000fc218, is_called_from_prepared_stmt=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:4807
            #28 0x00005580435c7b57 in mysql_parse (thd=0x62b0000fc218, rawbuf=0x62b000103238 "DELETE FROM B", length=13, parser_state=0x7fb970e7ea20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:8016
            #29 0x00005580435a0610 in dispatch_command (command=COM_QUERY, thd=0x62b0000fc218, packet=0x62900033e219 "DELETE FROM B", packet_length=13, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1896
            #30 0x000055804359da8e in do_command (thd=0x62b0000fc218, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1409
            #31 0x0000558043994caf in do_handle_one_connection (connect=0x6080000033b8, put_in_cache=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1416
            #32 0x0000558043994670 in handle_one_connection (arg=0x6080000033b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1318
            #33 0x00005580444b1832 in pfs_spawn_thread (arg=0x617000007798) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/perfschema/pfs.cc:2201
            #34 0x00007fb980c7fea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
            #35 0x00007fb98086caef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
            

            Also, interchangeably with the two above, a third assertion failure occurs, which looks much like MDEV-18421.

            Neither is new, all occur at least on 10.6.8.

            elenst Elena Stepanova added a comment - I am getting a double-assertion-failure on 10.6+, one of parallel assertions looks somewhat similar to this one, hopefully it's the same problem. It also involves FK tampering and TRUNCATE. The test case is non-deterministic, run with --repeat=N. It usually fails for me within 5-10 attempts, but sometimes it gets out of luck and takes longer. --source include/have_innodb.inc --source include/have_sequence.inc   CREATE TABLE A ( pk int , a varchar (8), b varchar (8), c datetime, key (a), primary key (pk) ) ENGINE=InnoDB;   CREATE TABLE B (pk INT PRIMARY KEY , d DATETIME, KEY (d)) ENGINE=InnoDB; INSERT INTO B SELECT seq, '0000-00-00 00:00:00' FROM seq_1_to_50;   --connect (con1,localhost,root,,test) ALTER TABLE A ADD KEY test_idx(b), ADD CONSTRAINT f1 FOREIGN KEY (b) REFERENCES A (a), ADD FOREIGN KEY (c) REFERENCES B (d); SET FOREIGN_KEY_CHECKS=0; DROP INDEX test_idx ON A; SET FOREIGN_KEY_CHECKS=1; --error ER_CANNOT_ADD_FOREIGN TRUNCATE TABLE A; --send DELETE FROM B;   --connection default --error ER_CANNOT_ADD_FOREIGN TRUNCATE TABLE A;   --connection con1 --reap DROP TABLE A, B; Note there are two thread stack traces, each with its own assertion failure 10.6 c92c1615 Thread 1 (Thread 0x7fb971b7b700 (LWP 3804225)): #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007fb980792537 in __GI_abort () at abort.c:79 #2 0x00007fb98079240f in __assert_fail_base (fmt=0x7fb98090a6a8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x558045d62880 "lock->trx == trx", file=0x558045d5c820 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/lock/lock0lock.cc", line=4154, function=<optimized out>) at assert.c:92 #3 0x00007fb9807a1662 in __GI___assert_fail (assertion=0x558045d62880 "lock->trx == trx", file=0x558045d5c820 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/lock/lock0lock.cc", line=4154, function=0x558045d62f20 "void lock_release_on_rollback(trx_t*, dict_table_t*)") at assert.c:101 #4 0x0000558044810a99 in lock_release_on_rollback (trx=0x7fb977334940, table=0x61800004cd20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/lock/lock0lock.cc:4154 #5 0x0000558044e4bd03 in row_undo_ins_remove_clust_rec (node=0x61b0000b7d20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0uins.cc:153 #6 0x0000558044e4ebbf in row_undo_ins (node=0x61b0000b7d20, thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0uins.cc:608 #7 0x0000558044a9b475 in row_undo (node=0x61b0000b7d20, thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0undo.cc:401 #8 0x0000558044a9b957 in row_undo_step (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0undo.cc:452 #9 0x000055804494323e in que_thr_step (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/que/que0que.cc:651 #10 0x00005580449435fd in que_run_threads_low (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/que/que0que.cc:709 #11 0x000055804494379b in que_run_threads (thr=0x6170000c6158) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/que/que0que.cc:729 #12 0x0000558044b38a10 in trx_t::rollback_low (this=0x7fb977334940, savept=0x0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/trx/trx0roll.cc:125 #13 0x0000558044b32b38 in trx_rollback_for_mysql_low (trx=0x7fb977334940) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/trx/trx0roll.cc:196 #14 0x0000558044b331de in trx_rollback_for_mysql (trx=0x7fb977334940) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/trx/trx0roll.cc:231 #15 0x00005580446dc9af in ha_innobase::create (this=0x61d0000ef6b8, name=0x6190000ea750 "test/A", form=0x6190000e9298, create_info=0x7fb971b78900, file_per_table=true, trx=0x7fb977334940) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/handler/ha_innodb.cc:13285 #16 0x00005580446aa1d1 in ha_innobase::truncate (this=0x61d0000ef6b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/handler/ha_innodb.cc:14019 #17 0x0000558043d84282 in handler::ha_truncate (this=0x61d0000ef6b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/handler.cc:5083 #18 0x0000558043a1b5c6 in Sql_cmd_truncate_table::handler_truncate (this=0x62b0000c4a38, thd=0x62b0000bd218, table_ref=0x62b0000c4318, is_tmp_table=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_truncate.cc:255 #19 0x0000558043a1cd18 in Sql_cmd_truncate_table::truncate_table (this=0x62b0000c4a38, thd=0x62b0000bd218, table_ref=0x62b0000c4318) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_truncate.cc:507 #20 0x0000558043a1d166 in Sql_cmd_truncate_table::execute (this=0x62b0000c4a38, thd=0x62b0000bd218) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_truncate.cc:573 #21 0x00005580435bbd2f in mysql_execute_command (thd=0x62b0000bd218, is_called_from_prepared_stmt=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:5997 #22 0x00005580435c7b57 in mysql_parse (thd=0x62b0000bd218, rawbuf=0x62b0000c4238 "TRUNCATE TABLE A", length=16, parser_state=0x7fb971b79a20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:8016 #23 0x00005580435a0610 in dispatch_command (command=COM_QUERY, thd=0x62b0000bd218, packet=0x62900028a219 "TRUNCATE TABLE A", packet_length=16, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1896 #24 0x000055804359da8e in do_command (thd=0x62b0000bd218, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1409 #25 0x0000558043994caf in do_handle_one_connection (connect=0x608000003338, put_in_cache=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1416 #26 0x0000558043994670 in handle_one_connection (arg=0x6080000032b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1318 #27 0x00005580444b1832 in pfs_spawn_thread (arg=0x617000007418) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/perfschema/pfs.cc:2201 #28 0x00007fb980c7fea7 in start_thread (arg=<optimized out>) at pthread_create.c:477 #29 0x00007fb98086caef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95   Thread 7 (Thread 0x7fb970e80700 (LWP 3804229)): #0 0x00007fb980860def in __GI___poll (fds=0x558047dea240 <poll_fds>, nfds=1, timeout=500) at ../sysdeps/unix/sysv/linux/poll.c:29 #1 0x00007fb98127f1b2 in __interceptor_poll (fds=0x558047dea240 <poll_fds>, nfds=1, timeout=500) at ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:3904 #2 0x000055804506f90f in addr_resolve (ptr=0x43df1, loc=0x7fb970e79600) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/my_addr_resolve.c:245 #3 0x000055804506fe5e in my_addr_resolve (ptr=0x7fb981266df1 <__interceptor_backtrace(void**, int)+49>, loc=0x7fb970e79600) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/my_addr_resolve.c:336 #4 0x00005580450139f6 in print_with_addr_resolve (addrs=0x7fb970e796c0, n=32) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/stacktrace.c:197 #5 0x0000558045013ce5 in my_print_stacktrace (stack_bottom=0x7fb970e7fb70 "\030\302\017", thread_stack=1048576, silent=0 '\000') at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/mysys/stacktrace.c:216 #6 0x0000558043d5ddbd in handle_fatal_signal (sig=6) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/signal_handler.cc:233 #7 <signal handler called> #8 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #9 0x00007fb980792537 in __GI_abort () at abort.c:79 #10 0x00007fb98079240f in __assert_fail_base (fmt=0x7fb98090a6a8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x558045fad300 "mode == 16 || mode == 12", file=0x558045fa9960 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc", line=2523, function=<optimized out>) at assert.c:92 #11 0x00007fb9807a1662 in __GI___assert_fail (assertion=0x558045fad300 "mode == 16 || mode == 12", file=0x558045fa9960 "/home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc", line=2523, function=0x558045facf00 "buf_block_t* buf_page_get_low(page_id_t, ulint, ulint, buf_block_t*, ulint, mtr_t*, dberr_t*, bool)") at assert.c:101 #12 0x0000558044c39991 in buf_page_get_low (page_id=..., zip_size=0, rw_latch=1, guess=0x7fb9762ab2a0, mode=10, mtr=0x7fb970e7bfa0, err=0x7fb970e7aa40, allow_ibuf_merge=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc:2523 #13 0x0000558044c3be9d in buf_page_get_gen (page_id=..., zip_size=0, rw_latch=1, guess=0x7fb9762ab2a0, mode=10, mtr=0x7fb970e7bfa0, err=0x7fb970e7aa40, allow_ibuf_merge=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/buf/buf0buf.cc:2962 #14 0x0000558044bda64c in btr_cur_search_to_nth_level (index=0x616000bbe720, level=0, tuple=0x6170000d2138, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7fb970e7bb90, mtr=0x7fb970e7bfa0, autoinc=0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/btr/btr0cur.cc:1571 #15 0x00005580446d4753 in btr_pcur_open_low (index=0x616000bbe720, level=0, tuple=0x6170000d2138, mode=PAGE_CUR_GE, latch_mode=1, cursor=0x7fb970e7bb90, autoinc=0, mtr=0x7fb970e7bfa0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/include/btr0pcur.inl:341 #16 0x00005580449c2cb6 in row_ins_check_foreign_constraint (check_ref=0, foreign=0x616000bd1c20, table=0x61800004b520, entry=0x6170000d2138, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0ins.cc:1626 #17 0x0000558044aa3f9e in row_upd_check_references_constraints (node=0x620000016bd0, pcur=0x7fb970e7c720, table=0x61800004b520, index=0x6160009ee020, offsets=0x61a0000c3790, thr=0x62400010c1a0, mtr=0x7fb970e7ca10) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:252 #18 0x0000558044aae308 in row_upd_sec_index_entry (node=0x620000016bd0, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2043 #19 0x0000558044aaeac1 in row_upd_sec_step (node=0x620000016bd0, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2095 #20 0x0000558044ab383d in row_upd (node=0x620000016bd0, thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2819 #21 0x0000558044ab4002 in row_upd_step (thr=0x62400010c1a0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0upd.cc:2934 #22 0x0000558044a12775 in row_update_for_mysql (prebuilt=0x620000016120) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/row/row0mysql.cc:1690 #23 0x000055804468e0b6 in ha_innobase::delete_row (this=0x61d00028b4b8, record=0x6190000e1fc8 "\375\"") at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/innobase/handler/ha_innodb.cc:8773 #24 0x0000558043d98fcb in handler::ha_delete_row (this=0x61d00028b4b8, buf=0x6190000e1fc8 "\375\"") at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/handler.cc:7713 #25 0x00005580441b969a in TABLE::delete_row (this=0x6190000e1a98) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_delete.cc:281 #26 0x00005580441b2090 in mysql_delete (thd=0x62b0000fc218, table_list=0x62b000103328, conds=0x0, order_list=0x62b000101090, limit=18446744073709551582, options=0, result=0x0) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_delete.cc:830 #27 0x00005580435b336c in mysql_execute_command (thd=0x62b0000fc218, is_called_from_prepared_stmt=false) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:4807 #28 0x00005580435c7b57 in mysql_parse (thd=0x62b0000fc218, rawbuf=0x62b000103238 "DELETE FROM B", length=13, parser_state=0x7fb970e7ea20) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:8016 #29 0x00005580435a0610 in dispatch_command (command=COM_QUERY, thd=0x62b0000fc218, packet=0x62900033e219 "DELETE FROM B", packet_length=13, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1896 #30 0x000055804359da8e in do_command (thd=0x62b0000fc218, blocking=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_parse.cc:1409 #31 0x0000558043994caf in do_handle_one_connection (connect=0x6080000033b8, put_in_cache=true) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1416 #32 0x0000558043994670 in handle_one_connection (arg=0x6080000033b8) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/sql/sql_connect.cc:1318 #33 0x00005580444b1832 in pfs_spawn_thread (arg=0x617000007798) at /home/jenkins/workspace/sandbox-elenst/Nightly-Build-CS/src/storage/perfschema/pfs.cc:2201 #34 0x00007fb980c7fea7 in start_thread (arg=<optimized out>) at pthread_create.c:477 #35 0x00007fb98086caef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 Also, interchangeably with the two above, a third assertion failure occurs, which looks much like MDEV-18421 . Neither is new, all occur at least on 10.6.8.

            There is some prior analysis from rr record traces in MDEV-18421 and MDEV-29504. In the latter, I wrote the following:

            I can’t think of any low-performance-overhead InnoDB work-around of the missing MDL on DDL. The costly dict_table_t::n_foreign_key_checks_running was removed as part of MDEV-21175.

            marko Marko Mäkelä added a comment - There is some prior analysis from rr record traces in MDEV-18421 and MDEV-29504 . In the latter, I wrote the following: I can’t think of any low-performance-overhead InnoDB work-around of the missing MDL on DDL. The costly dict_table_t::n_foreign_key_checks_running was removed as part of MDEV-21175 .

            Here the MDL prelocking doesn't happen, because for both A (in TRUNCATE) and B (in DELETE), table->file->referenced_by_foreign_key() returns 0. That is, InnoDB says that these tables have no foreign keys, thus the server doesn't lock them.
            Why InnoDB is doing that?

            serg Sergei Golubchik added a comment - Here the MDL prelocking doesn't happen, because for both A (in TRUNCATE ) and B (in DELETE ), table->file->referenced_by_foreign_key() returns 0. That is, InnoDB says that these tables have no foreign keys, thus the server doesn't lock them. Why InnoDB is doing that?

            The first TRUNCATE TABLE A will discard the FOREIGN KEY constraints from the old instance of the table A:

            10.6 ab0190101b0587e0e03b2d75a967050b9a85fd1b

            #6  0x000056252fb1fe3c in std::for_each<std::_Rb_tree_const_iterator<dict_foreign_t*>, dict_foreign_remove_partial> (__first=0x7f5b98025960, __last=0x2, __f=...) at /usr/include/c++/12/bits/stl_algo.h:3787
            #7  0x000056252fb12f03 in dict_table_rename_in_cache (table=0x7f5b980242f0, new_name=..., replace_new_file=false) at storage/innobase/dict/dict0dict.cc:1586
            #8  0x000056252f9a0c39 in row_rename_table_for_mysql (old_name=0x7f5bac0942a0 "test/A", new_name=0x7f5bac0940a0 "test/#sql-ib20", trx=0x7f5bbe501180, use_fk=false)
                at storage/innobase/row/row0mysql.cc:2853
            #9  0x000056252f7db95e in innobase_rename_table (trx=0x7f5bbe501180, from=0x7f5b98026ff0 "&\200\271\365\a", to=0x7f5b98029450 "test/#sql-ib20", use_fk=false)
                at storage/innobase/handler/ha_innodb.cc:13790
            #10 0x000056252f7dc5d1 in ha_innobase::truncate (this=0x7f5b9802c7a0) at storage/innobase/handler/ha_innodb.cc:13995
            

            There was an attempt to load FOREIGN KEY constraints for the new (empty) table:

            #0  dict_load_foreign (table_name=0x7f5bac0942a0 "test/A", uncommitted=false, col_names=0x0, trx_id=48, check_recursive=false, check_charsets=true, id=..., ignore_err=DICT_ERR_IGNORE_NONE, 
                fk_tables=std::deque with 0 elements) at storage/innobase/dict/dict0load.cc:2854
            #1  0x000056252fb2f40a in dict_load_foreigns (table_name=0x7f5bac0942a0 "test/A", col_names=0x0, trx_id=48, check_charsets=true, ignore_err=DICT_ERR_IGNORE_NONE, fk_tables=std::deque with 0 elements)
                at storage/innobase/dict/dict0load.cc:3162
            #2  0x000056252f7d89f3 in create_table_info_t::create_table (this=0x7f5bac094240, create_fk=false) at storage/innobase/handler/ha_innodb.cc:12829
            #3  0x000056252f7f6dbd in ha_innobase::create (this=0x7f5b9802c7a0, name=0x7f5b98029478 "test/A", form=0x7f5b9801c2a8, create_info=0x7f5bac0947b0, file_per_table=true, trx=0x7f5bbe501180)
                at storage/innobase/handler/ha_innodb.cc:13280
            #4  0x000056252f7dc875 in ha_innobase::truncate (this=0x7f5b9802c7a0) at storage/innobase/handler/ha_innodb.cc:14019
            

            This constraint was not loaded (DB_CANNOT_ADD_CONSTRAINT) due to the missing index. This is too strict; we can in fact allow the underlying indexes to be missing ever since MDEV-17187 was fixed.

            The error will lead to the rollback of the TRUNCATE operation, and the invocation of dict_table_open_on_name() to restore the old table definition. That error handling code path is missing a call to dict_load_foreigns(), that is, the FOREIGN KEY constraint was not restored.

            marko Marko Mäkelä added a comment - The first TRUNCATE TABLE A will discard the FOREIGN KEY constraints from the old instance of the table A : 10.6 ab0190101b0587e0e03b2d75a967050b9a85fd1b #6 0x000056252fb1fe3c in std::for_each<std::_Rb_tree_const_iterator<dict_foreign_t*>, dict_foreign_remove_partial> (__first=0x7f5b98025960, __last=0x2, __f=...) at /usr/include/c++/12/bits/stl_algo.h:3787 #7 0x000056252fb12f03 in dict_table_rename_in_cache (table=0x7f5b980242f0, new_name=..., replace_new_file=false) at storage/innobase/dict/dict0dict.cc:1586 #8 0x000056252f9a0c39 in row_rename_table_for_mysql (old_name=0x7f5bac0942a0 "test/A", new_name=0x7f5bac0940a0 "test/#sql-ib20", trx=0x7f5bbe501180, use_fk=false) at storage/innobase/row/row0mysql.cc:2853 #9 0x000056252f7db95e in innobase_rename_table (trx=0x7f5bbe501180, from=0x7f5b98026ff0 "&\200\271\365\a", to=0x7f5b98029450 "test/#sql-ib20", use_fk=false) at storage/innobase/handler/ha_innodb.cc:13790 #10 0x000056252f7dc5d1 in ha_innobase::truncate (this=0x7f5b9802c7a0) at storage/innobase/handler/ha_innodb.cc:13995 There was an attempt to load FOREIGN KEY constraints for the new (empty) table: #0 dict_load_foreign (table_name=0x7f5bac0942a0 "test/A", uncommitted=false, col_names=0x0, trx_id=48, check_recursive=false, check_charsets=true, id=..., ignore_err=DICT_ERR_IGNORE_NONE, fk_tables=std::deque with 0 elements) at storage/innobase/dict/dict0load.cc:2854 #1 0x000056252fb2f40a in dict_load_foreigns (table_name=0x7f5bac0942a0 "test/A", col_names=0x0, trx_id=48, check_charsets=true, ignore_err=DICT_ERR_IGNORE_NONE, fk_tables=std::deque with 0 elements) at storage/innobase/dict/dict0load.cc:3162 #2 0x000056252f7d89f3 in create_table_info_t::create_table (this=0x7f5bac094240, create_fk=false) at storage/innobase/handler/ha_innodb.cc:12829 #3 0x000056252f7f6dbd in ha_innobase::create (this=0x7f5b9802c7a0, name=0x7f5b98029478 "test/A", form=0x7f5b9801c2a8, create_info=0x7f5bac0947b0, file_per_table=true, trx=0x7f5bbe501180) at storage/innobase/handler/ha_innodb.cc:13280 #4 0x000056252f7dc875 in ha_innobase::truncate (this=0x7f5b9802c7a0) at storage/innobase/handler/ha_innodb.cc:14019 This constraint was not loaded ( DB_CANNOT_ADD_CONSTRAINT ) due to the missing index. This is too strict; we can in fact allow the underlying indexes to be missing ever since MDEV-17187 was fixed. The error will lead to the rollback of the TRUNCATE operation, and the invocation of dict_table_open_on_name() to restore the old table definition. That error handling code path is missing a call to dict_load_foreigns() , that is, the FOREIGN KEY constraint was not restored.

            The following change would make the TRUNCATE TABLE succeed if it is executed while foreign_key_checks=0 is in effect:

            diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
            --- a/storage/innobase/handler/ha_innodb.cc
            +++ b/storage/innobase/handler/ha_innodb.cc
            @@ -12824,15 +12824,18 @@ int create_table_info_t::create_table(bool create_fk)
             	dberr_t err = create_fk ? create_foreign_keys() : DB_SUCCESS;
             
             	if (err == DB_SUCCESS) {
            +		const dict_err_ignore_t ignore_err = create_fk
            +			? DICT_ERR_IGNORE_NONE : DICT_ERR_IGNORE_FK_NOKEY;
            +
             		/* Check that also referencing constraints are ok */
             		dict_names_t	fk_tables;
             		err = dict_load_foreigns(m_table_name, nullptr,
             					 m_trx->id, true,
            -					 DICT_ERR_IGNORE_NONE, fk_tables);
            +					 ignore_err, fk_tables);
             		while (err == DB_SUCCESS && !fk_tables.empty()) {
             			dict_sys.load_table(
             				{fk_tables.front(), strlen(fk_tables.front())},
            -				DICT_ERR_IGNORE_NONE);
            +				ignore_err);
             			fk_tables.pop_front();
             		}
             	}
            

            With this change, the first TRUNCATE will succeed if it is executed before SET FOREIGN_KEY_CHECKS=1, but the test case would still occasionally crash, because ha_innobase::referenced_by_foreign_key() for DELETE FROM B would report that no constraints exist. dict_load_foreign() must actually load the constraints for which some underlying indexes are missing.

            marko Marko Mäkelä added a comment - The following change would make the TRUNCATE TABLE succeed if it is executed while foreign_key_checks=0 is in effect: diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -12824,15 +12824,18 @@ int create_table_info_t::create_table(bool create_fk) dberr_t err = create_fk ? create_foreign_keys() : DB_SUCCESS; if (err == DB_SUCCESS) { + const dict_err_ignore_t ignore_err = create_fk + ? DICT_ERR_IGNORE_NONE : DICT_ERR_IGNORE_FK_NOKEY; + /* Check that also referencing constraints are ok */ dict_names_t fk_tables; err = dict_load_foreigns(m_table_name, nullptr, m_trx->id, true, - DICT_ERR_IGNORE_NONE, fk_tables); + ignore_err, fk_tables); while (err == DB_SUCCESS && !fk_tables.empty()) { dict_sys.load_table( {fk_tables.front(), strlen(fk_tables.front())}, - DICT_ERR_IGNORE_NONE); + ignore_err); fk_tables.pop_front(); } } With this change, the first TRUNCATE will succeed if it is executed before SET FOREIGN_KEY_CHECKS=1 , but the test case would still occasionally crash, because ha_innobase::referenced_by_foreign_key() for DELETE FROM B would report that no constraints exist. dict_load_foreign() must actually load the constraints for which some underlying indexes are missing.

            The dict_load_foreigns() call in the above patch will add the entry back to the dict_table_t::referenced_set of table B.

            The remaining intermittent failure that I can only reproduce without rr is for the second TRUNCATE, which would be executed while foreign key checks are enabled. Momentarily during the execution of TRUNCATE TABLE A, ha_innobase::referenced_by_foreign_key() could return false for the table B. That is, the DELETE would be wrongly allowed to proceed while the TRUNCATE is in progress.

            This race should remain even if I fixed the TRUNCATE error handling (which I did not do yet).

            We seem to need some locking in ha_innobase::referenced_by_foreign_key() to guarantee consistent results.

            marko Marko Mäkelä added a comment - The dict_load_foreigns() call in the above patch will add the entry back to the dict_table_t::referenced_set of table B . The remaining intermittent failure that I can only reproduce without rr is for the second TRUNCATE , which would be executed while foreign key checks are enabled. Momentarily during the execution of TRUNCATE TABLE A , ha_innobase::referenced_by_foreign_key() could return false for the table B . That is, the DELETE would be wrongly allowed to proceed while the TRUNCATE is in progress. This race should remain even if I fixed the TRUNCATE error handling (which I did not do yet). We seem to need some locking in ha_innobase::referenced_by_foreign_key() to guarantee consistent results.

            The fix will involve some refactoring of table creation as well as TRUNCATE TABLE in InnoDB. Therefore it is less risky to delay the fix until after the scheduled quarterly releases.

            marko Marko Mäkelä added a comment - The fix will involve some refactoring of table creation as well as TRUNCATE TABLE in InnoDB. Therefore it is less risky to delay the fix until after the scheduled quarterly releases.

            Closed together with MDEV-29504.

            marko Marko Mäkelä added a comment - Closed together with MDEV-29504 .

            People

              marko Marko Mäkelä
              mleich Matthias Leich
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.