Skip to content

Commit

Permalink
ddl: Fixed partition interval from DayMinute to just Minute. (#57738)
Browse files Browse the repository at this point in the history
close #57698
  • Loading branch information
mjonss authored Nov 28, 2024
1 parent 2950725 commit cc59ab0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
42 changes: 42 additions & 0 deletions tests/integrationtest/r/ddl/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
8 changes: 8 additions & 0 deletions tests/integrationtest/t/ddl/partition.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit cc59ab0

Please sign in to comment.