1+ set @@session.time_zone='+00:00';
12#
23# MDEV-25529 Auto-create: Pre-existing historical data is not partitioned as specified by ALTER
34#
@@ -57,7 +58,7 @@ select *, row_start, row_end from t1 partition (p4);
5758x row_start row_end
5859select *, row_start, row_end from t1 partition (pn);
5960x row_start row_end
60- 4 2000-01-01 02:00:00.000000 2038-01-19 06 :14:07.999999
61+ 4 2000-01-01 02:00:00.000000 2038-01-19 03 :14:07.999999
6162set timestamp= default;
6263ALTER table t1 partition by system_time
6364interval 1 hour starts '2000-01-01 00:00:00';
@@ -77,7 +78,7 @@ select *, row_start, row_end from t1 partition (p4);
7778x row_start row_end
7879select *, row_start, row_end from t1 partition (pn);
7980x row_start row_end
80- 4 2000-01-01 02:00:00.000000 2038-01-19 06 :14:07.999999
81+ 4 2000-01-01 02:00:00.000000 2038-01-19 03 :14:07.999999
8182alter TABLE t1 partition by system_time
8283interval 1 hour;
8384select *, row_start, row_end from t1 partition (p0);
@@ -96,7 +97,7 @@ select *, row_start, row_end from t1 partition (p4);
9697x row_start row_end
9798select *, row_start, row_end from t1 partition (pn);
9899x row_start row_end
99- 4 2000-01-01 02:00:00.000000 2038-01-19 06 :14:07.999999
100+ 4 2000-01-01 02:00:00.000000 2038-01-19 03 :14:07.999999
100101set @@system_versioning_alter_history= keep;
101102alter table t1 remove partitioning;
102103select *, row_start, row_end from t1 for system_time all;
@@ -105,7 +106,7 @@ x row_start row_end
1051061 2000-01-01 00:10:00.220000 2000-01-01 01:00:00.000000
1061072 2000-01-01 01:00:00.000000 2000-01-01 01:30:00.000000
1071083 2000-01-01 01:30:00.000000 2000-01-01 02:00:00.000000
108- 4 2000-01-01 02:00:00.000000 2038-01-19 06 :14:07.999999
109+ 4 2000-01-01 02:00:00.000000 2038-01-19 03 :14:07.999999
109110alter table t1 PARTITION by system_time interval 1 hour auto;
110111show create table t1;
111112Table Create Table
@@ -132,7 +133,7 @@ x row_start row_end
1321333 2000-01-01 01:30:00.000000 2000-01-01 02:00:00.000000
133134select *, row_start, row_end from t1 partition (pn);
134135x row_start row_end
135- 4 2000-01-01 02:00:00.000000 2038-01-19 06 :14:07.999999
136+ 4 2000-01-01 02:00:00.000000 2038-01-19 03 :14:07.999999
136137alter table t1 remove partitioning;
137138alter table t1 partition by SYSTEM_TIME interval 1 hour starts '2000-01-01 00:00:00' auto;
138139show create table t1;
@@ -160,7 +161,7 @@ x row_start row_end
1601613 2000-01-01 01:30:00.000000 2000-01-01 02:00:00.000000
161162select *, row_start, row_end from t1 partition (pn);
162163x row_start row_end
163- 4 2000-01-01 02:00:00.000000 2038-01-19 06 :14:07.999999
164+ 4 2000-01-01 02:00:00.000000 2038-01-19 03 :14:07.999999
164165set timestamp= unix_timestamp('2000-01-02 03:01:23.456');
165166delete from t1;
166167alter table t1 remove partitioning;
@@ -394,6 +395,85 @@ t1 CREATE TABLE `t1` (
394395) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
395396 PARTITION BY SYSTEM_TIME INTERVAL 9 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO
396397PARTITIONS 7
398+ # Year/month interval
399+ delete history from t1;
400+ alter table t1 remove partitioning;
401+ set timestamp= unix_timestamp('2000-01-01 00:00:00');
402+ insert t1 values (77);
403+ delete from t1;
404+ set timestamp= unix_timestamp('2003-10-01 00:00:00');
405+ insert t1 values (88);
406+ delete from t1;
407+ alter table t1 partition by system_time interval 11 month auto force;
408+ show create table t1;
409+ Table Create Table
410+ t1 CREATE TABLE `t1` (
411+ `x` int(11) DEFAULT NULL,
412+ `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
413+ `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
414+ KEY `row_end` (`row_end`,`row_start`),
415+ KEY `row_start` (`row_start`),
416+ KEY `row_end_2` (`row_end`,`x`),
417+ KEY `x` (`x`,`row_end`),
418+ KEY `row_end_3` (`row_end`),
419+ PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
420+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
421+ PARTITION BY SYSTEM_TIME INTERVAL 11 MONTH STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO
422+ PARTITIONS 6
423+ alter table t1 partition by system_time interval 1 year auto force;
424+ Warnings:
425+ Warning 4193 `t1`: STARTS timestamp 2003-10-01 00:00:00 is above earliest history date 2000-01-01 00:00:00 and was set to 2000-01-01 00:00:00
426+ show create table t1;
427+ Table Create Table
428+ t1 CREATE TABLE `t1` (
429+ `x` int(11) DEFAULT NULL,
430+ `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
431+ `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
432+ KEY `row_end` (`row_end`,`row_start`),
433+ KEY `row_start` (`row_start`),
434+ KEY `row_end_2` (`row_end`,`x`),
435+ KEY `x` (`x`,`row_end`),
436+ KEY `row_end_3` (`row_end`),
437+ PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
438+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
439+ PARTITION BY SYSTEM_TIME INTERVAL 1 YEAR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO
440+ PARTITIONS 5
441+ # No history
442+ delete history from t1;
443+ set timestamp= unix_timestamp('2000-01-01 00:00:00');
444+ alter table t1 partition by system_time interval 1 hour auto force;
445+ show create table t1;
446+ Table Create Table
447+ t1 CREATE TABLE `t1` (
448+ `x` int(11) DEFAULT NULL,
449+ `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
450+ `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
451+ KEY `row_end` (`row_end`,`row_start`),
452+ KEY `row_start` (`row_start`),
453+ KEY `row_end_2` (`row_end`,`x`),
454+ KEY `x` (`x`,`row_end`),
455+ KEY `row_end_3` (`row_end`),
456+ PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
457+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
458+ PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO
459+ PARTITIONS 5
460+ insert t1 values (99);
461+ alter table t1 partition by system_time interval 1 hour auto force;
462+ show create table t1;
463+ Table Create Table
464+ t1 CREATE TABLE `t1` (
465+ `x` int(11) DEFAULT NULL,
466+ `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
467+ `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
468+ KEY `row_end` (`row_end`,`row_start`),
469+ KEY `row_start` (`row_start`),
470+ KEY `row_end_2` (`row_end`,`x`),
471+ KEY `x` (`x`,`row_end`),
472+ KEY `row_end_3` (`row_end`),
473+ PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
474+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
475+ PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR STARTS TIMESTAMP'2000-01-01 00:00:00' AUTO
476+ PARTITIONS 5
397477# Slow scan warning
398478create or replace table t1 (x int,
399479row_start timestamp(6) as row start invisible,
0 commit comments