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

FK constraint fails upon referenced table eviction

    XMLWordPrintable

Details

    Description

      With the following sync point added:

      diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc
      --- a/storage/innobase/row/row0ins.cc	(revision 05cd10b74cffe882d04c6dd3333ef0beec2b41c2)
      +++ b/storage/innobase/row/row0ins.cc	(date 1669546784733)
      @@ -1944,6 +1944,7 @@
       			dict_table_t*	referenced_table
       						= foreign->referenced_table;
       
      +			DEBUG_SYNC_C("row_ins_check_fk_ref_table_loaded");
       			if (referenced_table == NULL) {
       
       				ref_table = dict_table_open_on_name(
      

      The following test fails to insert a row in a child table, however the opposite is expected:

      --source include/have_innodb.inc
       
      create table t1 (a int, key(a), b int) engine=innodb;
      create table t2 (a int key references t1(a), b int) engine=innodb;
      insert t1 values (1, 1);
      set autocommit =0;
      set global innodb_evict_tables_on_commit_debug=1;
       
       
      begin;
      insert t1 values (20000, 1);
       
      --connect bug, localhost, root
      set debug_sync="row_ins_check_fk_ref_table_loaded signal open wait_for go";
      send
      insert t2 values(1,1);
       
      --connect purge, localhost, root
      FLUSH TABLES;
       
      --connection default
      set debug_sync="now wait_for open";
      commit;
      set debug_sync="now signal go";
      --connection bug
      reap;
      --connection default
       
      # Cleanup
      set debug_sync= reset;
      drop table t2, t1;
      

      actual result, rev. 05cd10b74c

      mysqltest: At line 26: query 'reap' failed: ER_NO_REFERENCED_ROW_2 (1452): 
      Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT 
      `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
      

      The effect may be much more severe with real eviction, but I didn't succeed to simulate it with just innodb_evict_tables_on_commit_debug

      Attachments

        Issue Links

          Activity

            People

              nikitamalyavin Nikita Malyavin
              nikitamalyavin Nikita Malyavin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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