|
DELETE HISTORY deletes by (end_time) and there is no such index in above example. You must have both indexes by each of system fields to benefit from indexed historical queries:
create table t1(
|
x int primary key,
|
row_start timestamp(6) as row start invisible,
|
row_end timestamp(6) as row end invisible,
|
index (row_start),
|
index (row_end),
|
period for system_time (row_start, row_end)
|
) with system versioning;
|
insert into t1 values (1), (2), (3), (5), (6), (7);
|
explain select * from t1 for system_time as of '2021-01-01 00:00:00';
|
explain select * from t1 for system_time from '2020-01-01 00:00:00' to '2021-01-01 00:00:00';
|
explain select * from t1 for system_time between '2020-01-01 00:00:00' and '2021-01-01 00:00:00';
|
explain delete history from t1 before system_time '2021-10-09 08:07:06';
|
drop table t1;
|
explain select * from t1 for system_time as of '2021-01-01 00:00:00';
|
id select_type table type possible_keys key key_len ref rows Extra
|
1 SIMPLE t1 range row_start,row_end row_start 7 NULL 1 Using index condition; Using where
|
explain select * from t1 for system_time from '2020-01-01 00:00:00' to '2021-01-01 00:00:00';
|
id select_type table type possible_keys key key_len ref rows Extra
|
1 SIMPLE t1 range row_start,row_end row_start 7 NULL 1 Using index condition; Using where
|
explain select * from t1 for system_time between '2020-01-01 00:00:00' and '2021-01-01 00:00:00';
|
id select_type table type possible_keys key key_len ref rows Extra
|
1 SIMPLE t1 range row_start,row_end row_start 7 NULL 1 Using index condition; Using where
|
explain delete history from t1 before system_time '2021-10-09 08:07:06';
|
id select_type table type possible_keys key key_len ref rows Extra
|
1 SIMPLE t1 range row_end row_end 7 NULL 1 Using where
|
|