diff --git a/pkg/ddl/partition.go b/pkg/ddl/partition.go index f7be3609ea440..108cc53011620 100644 --- a/pkg/ddl/partition.go +++ b/pkg/ddl/partition.go @@ -1037,7 +1037,7 @@ func generatePartitionDefinitionsFromInterval(ctx expression.BuildContext, partO return dbterror.ErrGeneralUnsupportedDDL.GenWithStackByArgs("INTERVAL partitioning, currently requires FIRST and LAST partitions to be defined") } switch partOptions.Interval.IntervalExpr.TimeUnit { - case ast.TimeUnitInvalid, ast.TimeUnitYear, ast.TimeUnitQuarter, ast.TimeUnitMonth, ast.TimeUnitWeek, ast.TimeUnitDay, ast.TimeUnitHour, ast.TimeUnitDayMinute, ast.TimeUnitSecond: + case ast.TimeUnitInvalid, ast.TimeUnitYear, ast.TimeUnitQuarter, ast.TimeUnitMonth, ast.TimeUnitWeek, ast.TimeUnitDay, ast.TimeUnitHour, ast.TimeUnitMinute, ast.TimeUnitSecond: default: return dbterror.ErrGeneralUnsupportedDDL.GenWithStackByArgs("INTERVAL partitioning, only supports YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE and SECOND as time unit") } diff --git a/tests/integrationtest/r/ddl/partition.result b/tests/integrationtest/r/ddl/partition.result index adfec8fb8846a..0fecd412ae507 100644 --- a/tests/integrationtest/r/ddl/partition.result +++ b/tests/integrationtest/r/ddl/partition.result @@ -401,3 +401,45 @@ ALTER TABLE tp1 PARTITION BY RANGE (id) (PARTITION `P_LT_200` VALUES LESS THAN ( PARTITION `P_LT_500` VALUES LESS THAN (500), PARTITION `P_LT_600` VALUES LESS THAN (600)); drop table tp1; +DROP TABLE IF EXISTS t; +CREATE TABLE t (a int NOT NULL, b varchar(20) NOT NULL, c datetime NOT NULL ) PARTITION BY RANGE COLUMNS (c) INTERVAL (1 MINUTE) FIRST PARTITION LESS THAN ('2024-01-01') LAST PARTITION LESS THAN ('2024-01-01 00:10:00'); +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `a` int NOT NULL, + `b` varchar(20) NOT NULL, + `c` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY RANGE COLUMNS(`c`) +(PARTITION `P_LT_2024-01-01 00:00:00` VALUES LESS THAN ('2024-01-01 00:00:00'), + PARTITION `P_LT_2024-01-01 00:01:00` VALUES LESS THAN ('2024-01-01 00:01:00'), + PARTITION `P_LT_2024-01-01 00:02:00` VALUES LESS THAN ('2024-01-01 00:02:00'), + PARTITION `P_LT_2024-01-01 00:03:00` VALUES LESS THAN ('2024-01-01 00:03:00'), + PARTITION `P_LT_2024-01-01 00:04:00` VALUES LESS THAN ('2024-01-01 00:04:00'), + PARTITION `P_LT_2024-01-01 00:05:00` VALUES LESS THAN ('2024-01-01 00:05:00'), + PARTITION `P_LT_2024-01-01 00:06:00` VALUES LESS THAN ('2024-01-01 00:06:00'), + PARTITION `P_LT_2024-01-01 00:07:00` VALUES LESS THAN ('2024-01-01 00:07:00'), + PARTITION `P_LT_2024-01-01 00:08:00` VALUES LESS THAN ('2024-01-01 00:08:00'), + PARTITION `P_LT_2024-01-01 00:09:00` VALUES LESS THAN ('2024-01-01 00:09:00'), + PARTITION `P_LT_2024-01-01 00:10:00` VALUES LESS THAN ('2024-01-01 00:10:00')) +ALTER TABLE t FIRST PARTITION LESS THAN ('2024-01-01 00:02:00'); +ALTER TABLE t LAST PARTITION LESS THAN ('2024-01-01 00:12:00'); +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `a` int NOT NULL, + `b` varchar(20) NOT NULL, + `c` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +PARTITION BY RANGE COLUMNS(`c`) +(PARTITION `P_LT_2024-01-01 00:02:00` VALUES LESS THAN ('2024-01-01 00:02:00'), + PARTITION `P_LT_2024-01-01 00:03:00` VALUES LESS THAN ('2024-01-01 00:03:00'), + PARTITION `P_LT_2024-01-01 00:04:00` VALUES LESS THAN ('2024-01-01 00:04:00'), + PARTITION `P_LT_2024-01-01 00:05:00` VALUES LESS THAN ('2024-01-01 00:05:00'), + PARTITION `P_LT_2024-01-01 00:06:00` VALUES LESS THAN ('2024-01-01 00:06:00'), + PARTITION `P_LT_2024-01-01 00:07:00` VALUES LESS THAN ('2024-01-01 00:07:00'), + PARTITION `P_LT_2024-01-01 00:08:00` VALUES LESS THAN ('2024-01-01 00:08:00'), + PARTITION `P_LT_2024-01-01 00:09:00` VALUES LESS THAN ('2024-01-01 00:09:00'), + PARTITION `P_LT_2024-01-01 00:10:00` VALUES LESS THAN ('2024-01-01 00:10:00'), + PARTITION `P_LT_2024-01-01 00:11:00` VALUES LESS THAN ('2024-01-01 00:11:00'), + PARTITION `P_LT_2024-01-01 00:12:00` VALUES LESS THAN ('2024-01-01 00:12:00')) diff --git a/tests/integrationtest/t/ddl/partition.test b/tests/integrationtest/t/ddl/partition.test index 98cf1208c67c0..8fa808f8cfceb 100644 --- a/tests/integrationtest/t/ddl/partition.test +++ b/tests/integrationtest/t/ddl/partition.test @@ -198,3 +198,11 @@ create table tp1(id int); ALTER TABLE tp1 PARTITION BY RANGE (id) INTERVAL (100) FIRST PARTITION LESS THAN (200) LAST PARTITION LESS THAN (600); select QUERY from information_schema.ddl_jobs limit 1; drop table tp1; + +# Minute interval partitioning, #57698 +DROP TABLE IF EXISTS t; +CREATE TABLE t (a int NOT NULL, b varchar(20) NOT NULL, c datetime NOT NULL ) PARTITION BY RANGE COLUMNS (c) INTERVAL (1 MINUTE) FIRST PARTITION LESS THAN ('2024-01-01') LAST PARTITION LESS THAN ('2024-01-01 00:10:00'); +SHOW CREATE TABLE t; +ALTER TABLE t FIRST PARTITION LESS THAN ('2024-01-01 00:02:00'); +ALTER TABLE t LAST PARTITION LESS THAN ('2024-01-01 00:12:00'); +SHOW CREATE TABLE t;