[MDEV-25467] DELETE HISTORY behavior for active rows is not documented Created: 2021-04-20  Updated: 2021-04-22  Resolved: 2021-04-22

Status: Closed
Project: MariaDB Server
Component/s: Documentation, Versioned Tables
Affects Version/s: 10.3, 10.4, 10.5, 10.6
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Ian Gilfillan
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-25468 DELETE HISTORY may delete current dat... Closed

 Description   

So far I couldn't find an answer in the KB to what DELETE HISTORY is meant to do if BEFORE SYSTEM_TIME specifies a value greater than ROW END of the active records.
For example:

--source include/have_innodb.inc
 
SET SESSION TIME_ZONE= '+00:00';
 
CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=InnoDB WITH SYSTEM VERSIONING;
INSERT INTO t1 VALUES (1),(2);
 
SELECT pk, row_end FROM t1;
DELETE HISTORY FROM t1 BEFORE SYSTEM_TIME '2039-01-01';
SELECT pk FROM t1;
SELECT pk FROM t1 FOR SYSTEM_TIME ALL;
DROP TABLE t1;

It is not a trivial question, because unless it is defined by the standard (which I also can't find), there are different possible outcomes, each of which is logically justifiable:

  • DELETE HISTORY doesn't touch active rows at all, regardless the ROW END (because it only affects historical records, and active ones are not that);
  • DELETE HISTORY purges everything (because it affects all records with ROW END less than the specified SYSTEM_TIME, and it includes active rows);
  • DELETE HISTORY drops the historical records and deletes previously active records (because it does DELETE, which for historical records means elimination, while for active records it means moving them to history).

Currently the server uses the last option, which seems the least obvious, although still explainable:

10.3 7588049374

 
MariaDB [test]> INSERT INTO t1 VALUES (1),(2);
Query OK, 2 rows affected (0.013 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> SELECT pk, row_end FROM t1;
+----+----------------------------+
| pk | row_end                    |
+----+----------------------------+
|  1 | 2038-01-19 03:14:07.999999 |
|  2 | 2038-01-19 03:14:07.999999 |
+----+----------------------------+
2 rows in set (0.001 sec)
 
MariaDB [test]> DELETE HISTORY FROM t1 BEFORE SYSTEM_TIME '2039-01-01';
Query OK, 2 rows affected (0.013 sec)
 
MariaDB [test]> select pk from t1;
Empty set (0.001 sec)
 
MariaDB [test]> select pk from t1 for system_time all;
+----+
| pk |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.001 sec)

If it's intended, please document it. If it's not intended, please fix and then document the intended behavior.



 Comments   
Comment by Aleksey Midenkov [ 2021-04-21 ]

1-st variant is the only one justfiable: DELETE HISTORY doesn't touch active rows at all, regardless the ROW END (because it only affects historical records, and active ones are not that).

For deleting current rows there is DELETE command. To delete current rows AND history one must issue 2 commands: DELETE and DELETE HISTORY.

serg Please approve.

Comment by Sergei Golubchik [ 2021-04-22 ]

yes, I agree. DELETE HISTORY deletes history only.

Generated at Thu Feb 08 09:37:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.