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

FK checks on a bitemporal FK parent's FOR PORTION OF split are incorrectly affected by the FK action: RESTRICT spuriously rejects the operation with ER_ROW_IS_REFERENCED_2, while CASCADE spuriously fires and can corrupt child data

    XMLWordPrintable

Details

    • Can result in unexpected behaviour

    Description

      DELETE ... FOR PORTION OF on a bitemporal FK parent raises ER_ROW_IS_REFERENCED_2, even though the referenced ID is still valid through the remaining portions

      CREATE TABLE parent (id INT,s DATE, e DATE, PERIOD FOR appTIME(s, e), UNIQUE (id, appTIME WITHOUT OVERLAPS)) ENGINE=InnoDB WITH SYSTEM VERSIONING;
      CREATE TABLE child (cid INT PRIMARY KEY,parent_id INT,FOREIGN KEY(parent_id) REFERENCES parent (id)) ENGINE=InnoDB;
      INSERT INTO parent (id, s, e) VALUES (1, '2000-01-01', '2099-01-01');
      INSERT INTO child (cid, parent_id) VALUES (1, 1);
      DELETE FROM parent FOR PORTION OF appTIME FROM '2010-01-01' TO '2020-01-01' WHERE id=1;
      

      CLI Output

      10.11.19-dbg>create table parent ( id int,s date, e date, period for apptime(s, e), unique(id, apptime without overlaps)) engine=innodb with system versioning;
      Query OK, 0 rows affected (0.015 sec)
       
      10.11.19-dbg>create table child (cid int primary key,parent_id int,foreign key (parent_id) references parent(id)) engine=innodb;
      Query OK, 0 rows affected (0.011 sec)
       
      10.11.19-dbg>insert into parent (id, s, e) values (1, '2000-01-01', '2099-01-01');
      Query OK, 1 row affected (0.002 sec)
       
      10.11.19-dbg>insert into child (cid, parent_id) values (1, 1);
      Query OK, 1 row affected (0.001 sec)
       
      10.11.19-dbg>delete from parent for portion of apptime from '2010-01-01' to '2020-01-01' where id = 1;
      ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))
      10.11.19-dbg>
      

      Attachments

        Activity

          People

            midenok Aleksey Midenkov
            ramesh Ramesh Sivaraman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 1h
                1h

                Git Integration

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