[MDEV-29838] SELECT without FOR SYSTEM_TIME is not the same as AS OF CURRENT_TIMESTAMP Created: 2022-10-20  Updated: 2022-10-24  Resolved: 2022-10-24

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

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


 Description   

System versioning documentation in the KB says:

If the FOR SYSTEM_TIME clause is not used, the table will show the current data, as if one had specified FOR SYSTEM_TIME AS OF CURRENT_TIMESTAMP

It is not true. Select without FOR SYSTEM_TIME (and when system_versioning_asof=DEFAULT) shows records which have max timestamp in the row end field. It is not always the same as as of current_timestamp.

In a normal situation, both only exclude records which have row end in the past.
However, one can insert historical records with row end in the future, too. It was possible before, via @@timestamp modification, and is going to be even simpler now with MDEV-16546. The example below is applicable to any active server version.

create or replace table t (a int) with system versioning;
set @@timestamp = unix_timestamp('2022-02-02');
insert into t values (1);
set @@timestamp = unix_timestamp('2033-03-03');
delete from t;
set @@timestamp = default;
 
select a, row_start, row_end from t for system_time all;
select a, row_start, row_end from t;
select a, row_start, row_end from t for system_time as of current_timestamp;
 
# Cleanup
drop table t;

So, here for system_time all naturally returns the record:

10.3 3a62ff7e

a	row_start	row_end
1	2022-02-02 00:00:00.000000	2033-03-03 00:00:00.000000

for system_time as of current_timestamp does too

select a, row_start, row_end from t for system_time as of current_timestamp;
a	row_start	row_end
1	2022-02-02 00:00:00.000000	2033-03-03 00:00:00.000000

but plain select does not:

select a, row_start, row_end from t;
a	row_start	row_end

According to serg, it should work as it does now, in which case documentation needs to be updated. I don't have any good suggestions for how it should be described. Explaining that row end should be from_unixtime(2147483647.999999) for the record to be shown by SELECT seems somewhat awkward for documentation. I'll leave it to professionals to invent something.


Generated at Thu Feb 08 10:11:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.