删除版本表中的特定历史记录?

时间:2018-11-08 13:15:59

标签: database mariadb database-administration

我正在使用MariaDB 10.3。是否可以删除特定记录的历史记录?我遇到的情况是,一旦删除记录,我就必须删除所有记录(包括历史记录)。

请考虑下表:

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) DEFAULT NULL,
  `start_trxid` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
  `end_trxid` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
  PRIMARY KEY (`id`,`end_trxid`),
  PERIOD FOR SYSTEM_TIME (`start_trxid`, `end_trxid`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING

并考虑针对该表运行以下命令:

insert into users (name, email) values ('cory', 'name@corycollier.com'), ('bob', 'bob@gmail.com');
UPDATE users set name='Cory' where id=1;
UPDATE users set name='Cory Collier' where id=1;
UPDATE users set name='Cory C' where id=1;
UPDATE users set name='Cory' where id=1;

这使我拥有以下历史记录:

select * from (select * from users FOR SYSTEM_TIME BETWEEN (NOW() - INTERVAL 1 DAY) and (NOW())) as history where id=1;
+----+--------------+-----------------------------+-------------+----------------------+
| id | name         | email                       | start_trxid | end_trxid            |
+----+--------------+-----------------------------+-------------+----------------------+
|  1 | cory         | corycollier@corycollier.com |      697377 |               697384 |
|  1 | Cory Collier | corycollier@corycollier.com |      697384 |               697391 |
|  1 | Cory C       | corycollier@corycollier.com |      697391 |               697394 |
|  1 | Cory         | corycollier@corycollier.com |      697394 |               697401 |

我无法删除该用户的历史记录。我想。

0 个答案:

没有答案