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

Unexpected ER_ROW_IS_REFERENCED_2 or server crash in row_ins_foreign_report_err upon DELETE from versioned table with FK

    Details

      Description

      First, non-crashing test case, as it is much more important than the crashing one (normal operation fails, without switching off FOREIGN_KEY_CHECKS):

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (a INT, KEY(a)) ENGINE=InnoDB;
      INSERT INTO t1 VALUES (1);
       
      CREATE TABLE t2 (b INT, FOREIGN KEY (b) REFERENCES t1(a)) ENGINE=InnoDB WITH SYSTEM VERSIONING;
      INSERT INTO t2 VALUES (1),(1);
       
      DELETE FROM t2;
       
      # Cleanup
      DROP TABLE t2, t1;
      

      DELETE unexpectedly fails:

      10.3 4cdb72f2

      DELETE FROM t2;
      bug.fk1 'innodb'                         [ fail ]
              Test ended at 2019-10-12 01:25:45
       
      CURRENT_TEST: bug.fk1
      mysqltest: At line 9: query 'DELETE FROM t2' failed: 1451: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`))
      

      The crashing case is basically the same, but it uses a non-existing table for the FK reference:

      --source include/have_innodb.inc
       
      SET FOREIGN_KEY_CHECKS= 0;
      CREATE TABLE t2 (b INT, FOREIGN KEY (b) REFERENCES t1(a)) ENGINE=InnoDB WITH SYSTEM VERSIONING;
      INSERT INTO t2 VALUES (1),(1);
       
      SET FOREIGN_KEY_CHECKS= 1;
      DELETE FROM t2;
       
      # Cleanup
      DROP TABLE t2;
      

      10.3 4cdb72f2

      #3  <signal handler called>
      #4  0x000055fb6ddba7b8 in id_name_t::operator() (this=0x10) at /data/src/10.3/storage/innobase/include/dict0mem.h:525
      #5  0x000055fb6df03342 in row_ins_foreign_report_err (errstr=0x55fb6e6d6b43 "Trying to delete or update", thr=0x7f478c06e150, foreign=0x7f478c0a5ee8, rec=0x7f47da8c008e "\200", entry=0x7f478c06f398) at /data/src/10.3/storage/innobase/row/row0ins.cc:823
      #6  0x000055fb6df060db in row_ins_check_foreign_constraint (check_ref=0, foreign=0x7f478c0a5ee8, table=0x7f478c00ca08, entry=0x7f478c06f398, thr=0x7f478c06e150) at /data/src/10.3/storage/innobase/row/row0ins.cc:1894
      #7  0x000055fb6df06648 in row_ins_check_foreign_constraints (table=0x7f478c00ca08, index=0x7f478c0a4b98, pk=false, entry=0x7f478c06f398, thr=0x7f478c06e150, check_ref=false) at /data/src/10.3/storage/innobase/row/row0ins.cc:2042
      #8  0x000055fb6df0a3b4 in row_ins_sec_index_entry (index=0x7f478c0a4b98, entry=0x7f478c06f398, thr=0x7f478c06e150, check_ref=false) at /data/src/10.3/storage/innobase/row/row0ins.cc:3288
      #9  0x000055fb6df9e8f5 in row_upd_sec_index_entry (node=0x7f478c06de18, thr=0x7f478c06e150) at /data/src/10.3/storage/innobase/row/row0upd.cc:2532
      #10 0x000055fb6df9eb54 in row_upd_sec_step (node=0x7f478c06de18, thr=0x7f478c06e150) at /data/src/10.3/storage/innobase/row/row0upd.cc:2560
      #11 0x000055fb6dfa18f3 in row_upd (node=0x7f478c06de18, thr=0x7f478c06e150) at /data/src/10.3/storage/innobase/row/row0upd.cc:3327
      #12 0x000055fb6dfa1d40 in row_upd_step (thr=0x7f478c06e150) at /data/src/10.3/storage/innobase/row/row0upd.cc:3442
      #13 0x000055fb6df33506 in row_update_for_mysql (prebuilt=0x7f478c06d2e8) at /data/src/10.3/storage/innobase/row/row0mysql.cc:1888
      #14 0x000055fb6dd9f49f in ha_innobase::update_row (this=0x7f478c06cb38, old_row=0x7f478c0082b8 "\375\001", new_row=0x7f478c0082a0 "\375\001") at /data/src/10.3/storage/innobase/handler/ha_innodb.cc:8850
      #15 0x000055fb6db7e80e in handler::ha_update_row (this=0x7f478c06cb38, old_data=0x7f478c0082b8 "\375\001", new_data=0x7f478c0082a0 "\375\001") at /data/src/10.3/sql/handler.cc:6478
      #16 0x000055fb6dd25c47 in TABLE::delete_row (this=0x7f478c06bef0) at /data/src/10.3/sql/sql_delete.cc:257
      #17 0x000055fb6dd22e4a in mysql_delete (thd=0x7f478c000b00, table_list=0x7f478c0128e0, conds=0x0, order_list=0x7f478c0053c8, limit=18446744073709551615, options=0, result=0x0) at /data/src/10.3/sql/sql_delete.cc:750
      #18 0x000055fb6d859255 in mysql_execute_command (thd=0x7f478c000b00) at /data/src/10.3/sql/sql_parse.cc:4653
      #19 0x000055fb6d863d81 in mysql_parse (thd=0x7f478c000b00, rawbuf=0x7f478c012818 "DELETE FROM t2", length=14, parser_state=0x7f47da12f5e0, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:7829
      #20 0x000055fb6d8509bb in dispatch_command (command=COM_QUERY, thd=0x7f478c000b00, packet=0x7f478c15fe41 "DELETE FROM t2", packet_length=14, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1855
      #21 0x000055fb6d84f303 in do_command (thd=0x7f478c000b00) at /data/src/10.3/sql/sql_parse.cc:1400
      #22 0x000055fb6d9c6014 in do_handle_one_connection (connect=0x55fb71ab63e0) at /data/src/10.3/sql/sql_connect.cc:1403
      #23 0x000055fb6d9c5d76 in handle_one_connection (arg=0x55fb71ab63e0) at /data/src/10.3/sql/sql_connect.cc:1308
      #24 0x000055fb6e3732ec in pfs_spawn_thread (arg=0x55fb719fb9d0) at /data/src/10.3/storage/perfschema/pfs.cc:1862
      #25 0x00007f47e692b4a4 in start_thread (arg=0x7f47da130700) at pthread_create.c:456
      #26 0x00007f47e4e72d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      All of debug, non-debug and ASAN builds crash the same way.

      The problem was introduced in 10.3 by this commit:

      commit 75ba5c815d0272b35a28225d495a4a03fe63d29f
      Author: Aleksey Midenkov
      Date:   Wed May 30 13:19:03 2018 +0300
       
          MDEV-16210 FK constraints on versioned tables use historical rows, which may cause constraint violation
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                midenok Aleksey Midenkov
                Reporter:
                elenst Elena Stepanova
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: