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

foreign key on delete cascade stale entries with query cache enabled

Details

    Description

      On tables with foreign key on delete cascade, the data is kept when the referenced item is deleted. However it cannot be deleted or altered and on optimize on the table the data is suddenly gone.

      test case:

      create table t1 ( id int unsigned auto_increment, primary key(id) ) engine=innodb;
      create table t2 ( t2id int unsigned, id int unsigned, primary key(t2id, id), foreign key (`id`) references t1(`id`) on delete cascade ) engine=innodb;
       
      insert into t1 values (1);
      insert into t2 values (1,1);
       
      select * from t1;
      +----+
      | id |
      +----+
      |  1 |
      +----+
      1 row in set (0.00 sec)
       
      select * from t2;
      +------+----+
      | t2id | id |
      +------+----+
      |    1 |  1 |
      +------+----+
      1 row in set (0.00 sec)
       
      delete from t1;
      Query OK, 1 row affected (0.00 sec)
       
      select * from t2;
      +------+----+
      | t2id | id |
      +------+----+
      |    1 |  1 |
      +------+----+
      1 row in set (0.00 sec)
       
       delete from t2;
      Query OK, 0 rows affected (0.00 sec)
       
      select * from t2;
      +------+----+
      | t2id | id |
      +------+----+
      |    1 |  1 |
      +------+----+
      1 row in set (0.00 sec)
       
       optimize table t2;
      +----------------------+----------+----------+-------------------------------------------------------------------+
      | Table                | Op       | Msg_type | Msg_text                                                          |
      +----------------------+----------+----------+-------------------------------------------------------------------+
      | xxxxxxx_xxxxxxxxx.t2 | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
      | xxxxxxx_xxxxxxxxx.t2 | optimize | status   | OK                                                                |
      +----------------------+----------+----------+-------------------------------------------------------------------+
      2 rows in set (0.04 sec)
       
      select * from t2;
      Empty set (0.00 sec)
      
      

      Attachments

        Activity

          dicode Tim Westervoorde created issue -
          dicode Tim Westervoorde made changes -
          Field Original Value New Value
          Description On tables with foreign key on delete cascade, the data is kept when the referenced item is deleted. However it cannot be deleted or altered and on optimize on the table the data is suddenly gone.

          test case:
          {{create table t1 ( id int unsigned auto_increment, primary key(id) ) engine=innodb;
          create table t2 ( t2id int unsigned, id int unsigned, primary key(t2id, id), foreign key (`id`) references t1(`id`) on delete cascade ) engine=innodb;

          insert into t1 values (1);
          insert into t2 values (1,1);

          select * from t1;
          +----+
          | id |
          +----+
          | 1 |
          +----+
          1 row in set (0.00 sec)

          select * from t2;
          +------+----+
          | t2id | id |
          +------+----+
          | 1 | 1 |
          +------+----+
          1 row in set (0.00 sec)

          delete from t1;
          Query OK, 1 row affected (0.00 sec)

          select * from t2;
          +------+----+
          | t2id | id |
          +------+----+
          | 1 | 1 |
          +------+----+
          1 row in set (0.00 sec)

           delete from t2;
          Query OK, 0 rows affected (0.00 sec)

          select * from t2;
          +------+----+
          | t2id | id |
          +------+----+
          | 1 | 1 |
          +------+----+
          1 row in set (0.00 sec)

           optimize table t2;
          +----------------------+----------+----------+-------------------------------------------------------------------+
          | Table | Op | Msg_type | Msg_text |
          +----------------------+----------+----------+-------------------------------------------------------------------+
          | xxxxxxx_xxxxxxxxx.t2 | optimize | note | Table does not support optimize, doing recreate + analyze instead |
          | xxxxxxx_xxxxxxxxx.t2 | optimize | status | OK |
          +----------------------+----------+----------+-------------------------------------------------------------------+
          2 rows in set (0.04 sec)

          select * from t2;
          Empty set (0.00 sec)

          }}
          On tables with foreign key on delete cascade, the data is kept when the referenced item is deleted. However it cannot be deleted or altered and on optimize on the table the data is suddenly gone.

          test case:

          {code:mysql}
          create table t1 ( id int unsigned auto_increment, primary key(id) ) engine=innodb;
          create table t2 ( t2id int unsigned, id int unsigned, primary key(t2id, id), foreign key (`id`) references t1(`id`) on delete cascade ) engine=innodb;

          insert into t1 values (1);
          insert into t2 values (1,1);

          select * from t1;
          +----+
          | id |
          +----+
          | 1 |
          +----+
          1 row in set (0.00 sec)

          select * from t2;
          +------+----+
          | t2id | id |
          +------+----+
          | 1 | 1 |
          +------+----+
          1 row in set (0.00 sec)

          delete from t1;
          Query OK, 1 row affected (0.00 sec)

          select * from t2;
          +------+----+
          | t2id | id |
          +------+----+
          | 1 | 1 |
          +------+----+
          1 row in set (0.00 sec)

           delete from t2;
          Query OK, 0 rows affected (0.00 sec)

          select * from t2;
          +------+----+
          | t2id | id |
          +------+----+
          | 1 | 1 |
          +------+----+
          1 row in set (0.00 sec)

           optimize table t2;
          +----------------------+----------+----------+-------------------------------------------------------------------+
          | Table | Op | Msg_type | Msg_text |
          +----------------------+----------+----------+-------------------------------------------------------------------+
          | xxxxxxx_xxxxxxxxx.t2 | optimize | note | Table does not support optimize, doing recreate + analyze instead |
          | xxxxxxx_xxxxxxxxx.t2 | optimize | status | OK |
          +----------------------+----------+----------+-------------------------------------------------------------------+
          2 rows in set (0.04 sec)

          select * from t2;
          Empty set (0.00 sec)

          {code}
          elenst Elena Stepanova made changes -
          Status Open [ 1 ] Confirmed [ 10101 ]
          elenst Elena Stepanova made changes -
          Component/s Query Cache [ 10120 ]
          Component/s Storage Engine - InnoDB [ 10129 ]
          Fix Version/s 10.2 [ 14601 ]
          Affects Version/s 10.2 [ 14601 ]
          Assignee Oleksandr Byelkin [ sanja ]
          Labels innodb 10.2-ga
          Summary foreign key on delete cascade stale entries foreign key on delete cascade stale entries with query cache enabled
          sanja Oleksandr Byelkin made changes -
          Status Confirmed [ 10101 ] In Progress [ 3 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Sprint 10.2.6 [ 158 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Rank Ranked higher
          ratzpo Rasmus Johansson (Inactive) made changes -
          Sprint 10.2.6 [ 158 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Rank Ranked higher
          sanja Oleksandr Byelkin made changes -
          Assignee Oleksandr Byelkin [ sanja ] Marko Mäkelä [ marko ]
          Status In Progress [ 3 ] In Review [ 10002 ]
          marko Marko Mäkelä made changes -
          Assignee Marko Mäkelä [ marko ] Oleksandr Byelkin [ sanja ]
          Status In Review [ 10002 ] Stalled [ 10000 ]
          sanja Oleksandr Byelkin made changes -
          Status Stalled [ 10000 ] In Progress [ 3 ]
          sanja Oleksandr Byelkin made changes -
          Assignee Oleksandr Byelkin [ sanja ] Marko Mäkelä [ marko ]
          Status In Progress [ 3 ] In Review [ 10002 ]
          sanja Oleksandr Byelkin made changes -
          Assignee Marko Mäkelä [ marko ] Oleksandr Byelkin [ sanja ]
          sanja Oleksandr Byelkin made changes -
          Status In Review [ 10002 ] Stalled [ 10000 ]
          sanja Oleksandr Byelkin made changes -
          Fix Version/s 10.2.6 [ 22527 ]
          Fix Version/s 10.2 [ 14601 ]
          Resolution Fixed [ 1 ]
          Status Stalled [ 10000 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 80297 ] MariaDB v4 [ 151945 ]

          People

            sanja Oleksandr Byelkin
            dicode Tim Westervoorde
            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.