From 7fc6661a3415117c3bd0ed8ff7f49ea004216b37 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Wed, 3 Aug 2022 15:56:06 +0800 Subject: [PATCH] ddl: invalid multiple MAXVALUE partitions (#36329) (#36345) (#36447) close pingcap/tidb#36329 --- ddl/db_partition_test.go | 8 ++++++++ ddl/ddl_api.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ddl/db_partition_test.go b/ddl/db_partition_test.go index c17c9a648790f..16d2f22214925 100644 --- a/ddl/db_partition_test.go +++ b/ddl/db_partition_test.go @@ -550,6 +550,14 @@ create table log_message_1 ( "partition p1 values less than ('A'));", dbterror.ErrRangeNotIncreasing, }, + { + "create table t(d datetime)" + + "partition by range columns (d) (" + + "partition p0 values less than ('2022-01-01')," + + "partition p1 values less than (MAXVALUE), " + + "partition p2 values less than (MAXVALUE));", + dbterror.ErrRangeNotIncreasing, + }, { "CREATE TABLE t1(c0 INT) PARTITION BY HASH((NOT c0)) PARTITIONS 2;", dbterror.ErrPartitionFunctionIsNotAllowed, diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 27e509439d652..7c867b9b0b3d6 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2704,7 +2704,7 @@ func checkTwoRangeColumns(ctx sessionctx.Context, curr, prev *model.PartitionDef } for i := 0; i < len(pi.Columns); i++ { // Special handling for MAXVALUE. - if strings.EqualFold(curr.LessThan[i], partitionMaxValue) { + if strings.EqualFold(curr.LessThan[i], partitionMaxValue) && !strings.EqualFold(prev.LessThan[i], partitionMaxValue) { // If current is maxvalue, it certainly >= previous. return true, nil }