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

DELETE of rows in child tables are not logged in the binary log

    XMLWordPrintable

Details

    Description

      When we have InnoDB tables with foreign key constraints (ON DELETE CASCADE) defined, deleting rows from the parent table will (correctly) delete rows from the child table. But the rows deleted from the child table do not appear in the binary log, and will thus not be replicated downstream.

      This is a problem, since downstream slaves may or may not have the same foreign keys defined. Or they may use a storage engine which does not do foreign keys (e.g. MyISAM or TokuDB...). As a result, the slave will drift out of sync with the master...

      For example:

      CREATE TABLE author (
      	id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
      	name VARCHAR(100) NOT NULL
      ) ENGINE = InnoDB;
       
      CREATE TABLE book (
      	id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
      	title VARCHAR(200) NOT NULL,
      	author_id SMALLINT UNSIGNED NOT NULL,
      	CONSTRAINT `fk_book_author`
      		FOREIGN KEY (author_id) REFERENCES author (id)
      		ON DELETE CASCADE
      		ON UPDATE RESTRICT
      ) ENGINE = InnoDB;
       
      insert into author
        set name = 'H.P. Lovecraft'
      ;
       
      insert into book
        set title = 'Dagon',
        author_id = @@last_insert_id;
       
      select * from author;
       
      select * from book;
       
      delete from author where name = 'H.P. Lovecraft';
       
      select * from author;
       
      select * from book;
      

      The above behaves as expected on the master - the row in the book table is correctly deleted.

      But it does not appear in the binary log!

      Attachments

        Activity

          People

            greenman Ian Gilfillan
            jorginator Karl E. Jørgensen
            Votes:
            0 Vote for this issue
            Watchers:
            4 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.