From 82f0215882dc64be667d12080d5a10354027854c Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 26 Nov 2024 14:29:03 +0100 Subject: [PATCH 1/2] Fixed partition interval from DayMinute to just Minute. --- pkg/ddl/partition.go | 2 +- pkg/ddl/tests/partition/db_partition_test.go | 44 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/pkg/ddl/partition.go b/pkg/ddl/partition.go index 43bcd1a785001..bb38a26755816 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/pkg/ddl/tests/partition/db_partition_test.go b/pkg/ddl/tests/partition/db_partition_test.go index 18f1999063d84..be1e66581f0d8 100644 --- a/pkg/ddl/tests/partition/db_partition_test.go +++ b/pkg/ddl/tests/partition/db_partition_test.go @@ -3694,3 +3694,47 @@ func TestTruncateNumberOfPhases(t *testing.T) { dom.Reload() require.Equal(t, int64(4), dom.InfoSchema().SchemaMetaVersion()-schemaVersion) } +func TestPartitionByIntervalMinute(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(`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');`) + tk.MustQuery(`show create table t`).Check(testkit.Rows("" + + "t CREATE TABLE `t` (\n" + + " `a` int(11) NOT NULL,\n" + + " `b` varchar(20) NOT NULL,\n" + + " `c` datetime NOT NULL\n" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" + + "PARTITION BY RANGE COLUMNS(`c`)\n" + + "(PARTITION `P_LT_2024-01-01 00:00:00` VALUES LESS THAN ('2024-01-01 00:00:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:01:00` VALUES LESS THAN ('2024-01-01 00:01:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:02:00` VALUES LESS THAN ('2024-01-01 00:02:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:03:00` VALUES LESS THAN ('2024-01-01 00:03:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:04:00` VALUES LESS THAN ('2024-01-01 00:04:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:05:00` VALUES LESS THAN ('2024-01-01 00:05:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:06:00` VALUES LESS THAN ('2024-01-01 00:06:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:07:00` VALUES LESS THAN ('2024-01-01 00:07:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:08:00` VALUES LESS THAN ('2024-01-01 00:08:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:09:00` VALUES LESS THAN ('2024-01-01 00:09:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:10:00` VALUES LESS THAN ('2024-01-01 00:10:00'))")) + tk.MustExec(`alter table t first partition less than ('2024-01-01 00:02:00')`) + tk.MustExec(`alter table t last partition less than ('2024-01-01 00:12:00')`) + tk.MustQuery(`show create table t`).Check(testkit.Rows("" + + "t CREATE TABLE `t` (\n" + + " `a` int(11) NOT NULL,\n" + + " `b` varchar(20) NOT NULL,\n" + + " `c` datetime NOT NULL\n" + + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" + + "PARTITION BY RANGE COLUMNS(`c`)\n" + + "(PARTITION `P_LT_2024-01-01 00:02:00` VALUES LESS THAN ('2024-01-01 00:02:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:03:00` VALUES LESS THAN ('2024-01-01 00:03:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:04:00` VALUES LESS THAN ('2024-01-01 00:04:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:05:00` VALUES LESS THAN ('2024-01-01 00:05:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:06:00` VALUES LESS THAN ('2024-01-01 00:06:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:07:00` VALUES LESS THAN ('2024-01-01 00:07:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:08:00` VALUES LESS THAN ('2024-01-01 00:08:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:09:00` VALUES LESS THAN ('2024-01-01 00:09:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:10:00` VALUES LESS THAN ('2024-01-01 00:10:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:11:00` VALUES LESS THAN ('2024-01-01 00:11:00'),\n" + + " PARTITION `P_LT_2024-01-01 00:12:00` VALUES LESS THAN ('2024-01-01 00:12:00'))")) +} From 957f2d485e5034979aa52f28f61d72cfa29b6229 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 26 Nov 2024 14:35:35 +0100 Subject: [PATCH 2/2] Using integration test instead of unit test --- pkg/ddl/tests/partition/db_partition_test.go | 44 -------------------- tests/integrationtest/r/ddl/partition.result | 42 +++++++++++++++++++ tests/integrationtest/t/ddl/partition.test | 8 ++++ 3 files changed, 50 insertions(+), 44 deletions(-) diff --git a/pkg/ddl/tests/partition/db_partition_test.go b/pkg/ddl/tests/partition/db_partition_test.go index be1e66581f0d8..18f1999063d84 100644 --- a/pkg/ddl/tests/partition/db_partition_test.go +++ b/pkg/ddl/tests/partition/db_partition_test.go @@ -3694,47 +3694,3 @@ func TestTruncateNumberOfPhases(t *testing.T) { dom.Reload() require.Equal(t, int64(4), dom.InfoSchema().SchemaMetaVersion()-schemaVersion) } -func TestPartitionByIntervalMinute(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`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');`) - tk.MustQuery(`show create table t`).Check(testkit.Rows("" + - "t CREATE TABLE `t` (\n" + - " `a` int(11) NOT NULL,\n" + - " `b` varchar(20) NOT NULL,\n" + - " `c` datetime NOT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" + - "PARTITION BY RANGE COLUMNS(`c`)\n" + - "(PARTITION `P_LT_2024-01-01 00:00:00` VALUES LESS THAN ('2024-01-01 00:00:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:01:00` VALUES LESS THAN ('2024-01-01 00:01:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:02:00` VALUES LESS THAN ('2024-01-01 00:02:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:03:00` VALUES LESS THAN ('2024-01-01 00:03:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:04:00` VALUES LESS THAN ('2024-01-01 00:04:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:05:00` VALUES LESS THAN ('2024-01-01 00:05:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:06:00` VALUES LESS THAN ('2024-01-01 00:06:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:07:00` VALUES LESS THAN ('2024-01-01 00:07:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:08:00` VALUES LESS THAN ('2024-01-01 00:08:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:09:00` VALUES LESS THAN ('2024-01-01 00:09:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:10:00` VALUES LESS THAN ('2024-01-01 00:10:00'))")) - tk.MustExec(`alter table t first partition less than ('2024-01-01 00:02:00')`) - tk.MustExec(`alter table t last partition less than ('2024-01-01 00:12:00')`) - tk.MustQuery(`show create table t`).Check(testkit.Rows("" + - "t CREATE TABLE `t` (\n" + - " `a` int(11) NOT NULL,\n" + - " `b` varchar(20) NOT NULL,\n" + - " `c` datetime NOT NULL\n" + - ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\n" + - "PARTITION BY RANGE COLUMNS(`c`)\n" + - "(PARTITION `P_LT_2024-01-01 00:02:00` VALUES LESS THAN ('2024-01-01 00:02:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:03:00` VALUES LESS THAN ('2024-01-01 00:03:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:04:00` VALUES LESS THAN ('2024-01-01 00:04:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:05:00` VALUES LESS THAN ('2024-01-01 00:05:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:06:00` VALUES LESS THAN ('2024-01-01 00:06:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:07:00` VALUES LESS THAN ('2024-01-01 00:07:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:08:00` VALUES LESS THAN ('2024-01-01 00:08:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:09:00` VALUES LESS THAN ('2024-01-01 00:09:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:10:00` VALUES LESS THAN ('2024-01-01 00:10:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:11:00` VALUES LESS THAN ('2024-01-01 00:11:00'),\n" + - " PARTITION `P_LT_2024-01-01 00:12:00` VALUES LESS THAN ('2024-01-01 00:12:00'))")) -} 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;