diff --git a/ddl/partition.go b/ddl/partition.go index 2a16e6b357699..675c9aa3779ab 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -524,7 +524,7 @@ func checkPartitionValuesIsInt(ctx sessionctx.Context, def *ast.PartitionDefinit switch val.Kind() { case types.KindUint64, types.KindNull: case types.KindInt64: - if !ctx.GetSessionVars().SQLMode.HasNoUnsignedSubtractionMode() && mysql.HasUnsignedFlag(tp.Flag) && val.GetInt64() < 0 { + if mysql.HasUnsignedFlag(tp.Flag) && val.GetInt64() < 0 { return ErrPartitionConstDomain.GenWithStackByArgs() } default: @@ -666,8 +666,7 @@ func checkRangePartitionValue(ctx sessionctx.Context, tblInfo *model.TableInfo) if strings.EqualFold(defs[len(defs)-1].LessThan[0], partitionMaxValue) { defs = defs[:len(defs)-1] } - // treat partition value under NoUnsignedSubtractionMode as signed - isUnsigned := isColUnsigned(cols, pi) && !ctx.GetSessionVars().SQLMode.HasNoUnsignedSubtractionMode() + isUnsigned := isColUnsigned(cols, pi) var prevRangeValue interface{} for i := 0; i < len(defs); i++ { if strings.EqualFold(defs[i].LessThan[0], partitionMaxValue) { diff --git a/table/tables/partition_test.go b/table/tables/partition_test.go index b8a14dc5e997d..8e8449013217c 100644 --- a/table/tables/partition_test.go +++ b/table/tables/partition_test.go @@ -19,6 +19,7 @@ import ( . "github.com/pingcap/check" "github.com/pingcap/parser/model" "github.com/pingcap/tidb/ddl" + mysql "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx/binloginfo" "github.com/pingcap/tidb/table" @@ -447,41 +448,27 @@ func (ts *testSuite) TestCreatePartitionTableNotSupport(c *C) { c.Assert(ddl.ErrPartitionFunctionIsNotAllowed.Equal(err), IsTrue) } -// issue 24880 -func (ts *testSuite) TestRangePartitionUnderNoUnsignedSub(c *C) { +func (ts *testSuite) TestRangePartitionUnderNoUnsigned(c *C) { tk := testkit.NewTestKitWithInit(c, ts.store) tk.MustExec("use test") + tk.MustExec("drop table if exists t2;") tk.MustExec("drop table if exists tu;") + defer tk.MustExec("drop table if exists t2;") + defer tk.MustExec("drop table if exists tu;") tk.MustExec("SET @@sql_mode='NO_UNSIGNED_SUBTRACTION';") - tk.MustExec(`CREATE TABLE tu (c1 BIGINT UNSIGNED) PARTITION BY RANGE(c1 - 10) ( - PARTITION p0 VALUES LESS THAN (-5), - PARTITION p1 VALUES LESS THAN (0), - PARTITION p2 VALUES LESS THAN (5), - PARTITION p3 VALUES LESS THAN (10), - PARTITION p4 VALUES LESS THAN (MAXVALUE) - );`) - // currently not support insert records whose partition value is negative - ErrMsg1 := "[types:1690]BIGINT UNSIGNED value is out of range in '(tu.c1 - 10)'" - tk.MustGetErrMsg("insert into tu values (0);", ErrMsg1) - tk.MustGetErrMsg("insert into tu values (cast(1 as unsigned));", ErrMsg1) - tk.MustExec(("insert into tu values (cast(9223372036854775807 as unsigned));")) - // MySQL will not support c1 value bigger than 9223372036854775817 in this case - tk.MustExec(("insert into tu values (cast(18446744073709551615 as unsigned));")) - - // test `create table like` - ErrMsg2 := "[types:1690]BIGINT UNSIGNED value is out of range in '(tu2.c1 - 10)'" - tk.MustExec(`CREATE TABLE tu2 like tu;`) - // currently not support insert records whose partition value is negative - tk.MustGetErrMsg("insert into tu2 values (0);", ErrMsg2) - tk.MustGetErrMsg("insert into tu2 values (cast(1 as unsigned));", ErrMsg2) - tk.MustExec(("insert into tu2 values (cast(9223372036854775807 as unsigned));")) - // MySQL will not support c1 value bigger than 9223372036854775817 in this case - tk.MustExec(("insert into tu2 values (cast(18446744073709551615 as unsigned));")) - - // compatible with MySQL - ErrMsg3 := "[ddl:1493]VALUES LESS THAN value must be strictly increasing for each partition" - tk.MustExec("SET @@sql_mode='';") - tk.MustGetErrMsg(`CREATE TABLE tu3 like tu;`, ErrMsg3) + tk.MustExec(`create table t2 (a bigint unsigned) partition by range (a) ( + partition p1 values less than (0), + partition p2 values less than (1), + partition p3 values less than (18446744073709551614), + partition p4 values less than (18446744073709551615), + partition p5 values less than maxvalue);`) + tk.MustExec("insert into t2 values(10);") + tk.MustGetErrCode(`CREATE TABLE tu (c1 BIGINT UNSIGNED) PARTITION BY RANGE(c1 - 10) ( + PARTITION p0 VALUES LESS THAN (-5), + PARTITION p1 VALUES LESS THAN (0), + PARTITION p2 VALUES LESS THAN (5), + PARTITION p3 VALUES LESS THAN (10), + PARTITION p4 VALUES LESS THAN (MAXVALUE));`, mysql.ErrPartitionConstDomain) } func (ts *testSuite) TestIntUint(c *C) {