Commit 07fade6d authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-22247 History partition overflow leads to wrong SELECT result

Historical query with AS OF point after the last history partition
must include last history partition because it can be overflown
(contain history rows out of right endpoint).

Move left point back to hist_part->id in that case.
parent e09e304b
...@@ -726,4 +726,25 @@ create or replace table t1 (a int) with system versioning; ...@@ -726,4 +726,25 @@ create or replace table t1 (a int) with system versioning;
alter table t1 partition by system_time (partition pn current); alter table t1 partition by system_time (partition pn current);
ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT
drop table t1; drop table t1;
#
# MDEV-22247 History partition overflow leads to wrong SELECT result
#
set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (x int) with system versioning
partition by system_time interval 1 hour
(partition p0 history, partition p1 history, partition pn current);
insert into t1 values (0);
update t1 set x= x + 1;
set timestamp= unix_timestamp('2000-01-01 02:00:01');
update t1 set x= x + 1;
select *, row_start, row_end from t1 for system_time as of '2000-01-01 02:00:00';
x row_start row_end
1 2000-01-01 00:00:00.000000 2000-01-01 02:00:01.000000
explain partitions select * from t1 for system_time as of '2000-01-01 02:00:00';
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,pn ALL NULL NULL NULL NULL # Using where
explain partitions select * from t1;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 pn # NULL NULL NULL NULL # #
drop table t1;
# End of 10.3 tests # End of 10.3 tests
...@@ -706,6 +706,27 @@ alter table t1 partition by system_time (partition pn current); ...@@ -706,6 +706,27 @@ alter table t1 partition by system_time (partition pn current);
# Cleanup # Cleanup
drop table t1; drop table t1;
--echo #
--echo # MDEV-22247 History partition overflow leads to wrong SELECT result
--echo #
set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (x int) with system versioning
partition by system_time interval 1 hour
(partition p0 history, partition p1 history, partition pn current);
insert into t1 values (0);
update t1 set x= x + 1;
set timestamp= unix_timestamp('2000-01-01 02:00:01');
update t1 set x= x + 1;
select *, row_start, row_end from t1 for system_time as of '2000-01-01 02:00:00';
--replace_column 10 #
explain partitions select * from t1 for system_time as of '2000-01-01 02:00:00';
--replace_column 5 # 10 # 11 #
explain partitions select * from t1;
drop table t1;
--echo # End of 10.3 tests --echo # End of 10.3 tests
--source suite/versioning/common_finish.inc --source suite/versioning/common_finish.inc
...@@ -3737,6 +3737,17 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info, ...@@ -3737,6 +3737,17 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
if (part_func_value >= part_end_val && if (part_func_value >= part_end_val &&
(loc_part_id < max_partition || !part_info->defined_max_value)) (loc_part_id < max_partition || !part_info->defined_max_value))
loc_part_id++; loc_part_id++;
if (part_info->part_type == VERSIONING_PARTITION &&
part_func_value < INT_MAX32 &&
loc_part_id > part_info->vers_info->hist_part->id)
{
/*
Historical query with AS OF point after the last history partition must
include last history partition because it can be overflown (contain
history rows out of right endpoint).
*/
loc_part_id= part_info->vers_info->hist_part->id;
}
} }
else else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment