Skip to content

Commit 07fade6

Browse files
committed
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.
1 parent e09e304 commit 07fade6

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

mysql-test/suite/versioning/r/partition.result

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,4 +726,25 @@ create or replace table t1 (a int) with system versioning;
726726
alter table t1 partition by system_time (partition pn current);
727727
ERROR HY000: Wrong partitions for `t1`: must have at least one HISTORY and exactly one last CURRENT
728728
drop table t1;
729+
#
730+
# MDEV-22247 History partition overflow leads to wrong SELECT result
731+
#
732+
set timestamp= unix_timestamp('2000-01-01 00:00:00');
733+
create or replace table t1 (x int) with system versioning
734+
partition by system_time interval 1 hour
735+
(partition p0 history, partition p1 history, partition pn current);
736+
insert into t1 values (0);
737+
update t1 set x= x + 1;
738+
set timestamp= unix_timestamp('2000-01-01 02:00:01');
739+
update t1 set x= x + 1;
740+
select *, row_start, row_end from t1 for system_time as of '2000-01-01 02:00:00';
741+
x row_start row_end
742+
1 2000-01-01 00:00:00.000000 2000-01-01 02:00:01.000000
743+
explain partitions select * from t1 for system_time as of '2000-01-01 02:00:00';
744+
id select_type table partitions type possible_keys key key_len ref rows Extra
745+
1 SIMPLE t1 p1,pn ALL NULL NULL NULL NULL # Using where
746+
explain partitions select * from t1;
747+
id select_type table partitions type possible_keys key key_len ref rows Extra
748+
1 SIMPLE t1 pn # NULL NULL NULL NULL # #
749+
drop table t1;
729750
# End of 10.3 tests

mysql-test/suite/versioning/t/partition.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,27 @@ alter table t1 partition by system_time (partition pn current);
706706
# Cleanup
707707
drop table t1;
708708

709+
--echo #
710+
--echo # MDEV-22247 History partition overflow leads to wrong SELECT result
711+
--echo #
712+
set timestamp= unix_timestamp('2000-01-01 00:00:00');
713+
create or replace table t1 (x int) with system versioning
714+
partition by system_time interval 1 hour
715+
(partition p0 history, partition p1 history, partition pn current);
716+
717+
insert into t1 values (0);
718+
update t1 set x= x + 1;
719+
720+
set timestamp= unix_timestamp('2000-01-01 02:00:01');
721+
update t1 set x= x + 1;
722+
723+
select *, row_start, row_end from t1 for system_time as of '2000-01-01 02:00:00';
724+
--replace_column 10 #
725+
explain partitions select * from t1 for system_time as of '2000-01-01 02:00:00';
726+
--replace_column 5 # 10 # 11 #
727+
explain partitions select * from t1;
728+
drop table t1;
729+
709730
--echo # End of 10.3 tests
710731

711732
--source suite/versioning/common_finish.inc

sql/sql_partition.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3737,6 +3737,17 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info,
37373737
if (part_func_value >= part_end_val &&
37383738
(loc_part_id < max_partition || !part_info->defined_max_value))
37393739
loc_part_id++;
3740+
if (part_info->part_type == VERSIONING_PARTITION &&
3741+
part_func_value < INT_MAX32 &&
3742+
loc_part_id > part_info->vers_info->hist_part->id)
3743+
{
3744+
/*
3745+
Historical query with AS OF point after the last history partition must
3746+
include last history partition because it can be overflown (contain
3747+
history rows out of right endpoint).
3748+
*/
3749+
loc_part_id= part_info->vers_info->hist_part->id;
3750+
}
37403751
}
37413752
else
37423753
{

0 commit comments

Comments
 (0)