diff --git a/ddl/ddl.go b/ddl/ddl.go index f791c02d1b737..ca13d058e8db8 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -137,6 +137,7 @@ var ( // ErrUnsupportedPartitionByRangeColumns returns for does unsupported partition by range columns. ErrUnsupportedPartitionByRangeColumns = terror.ClassDDL.New(mysql.ErrUnsupportedDDLOperation, fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation], "partition by range columns")) errUnsupportedCreatePartition = terror.ClassDDL.New(mysql.ErrUnsupportedDDLOperation, fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation], "partition type, treat as normal table")) + errTablePartitionDisabled = terror.ClassDDL.New(mysql.ErrUnsupportedDDLOperation, "Partitions are ignored because Table Partition is disabled, please set 'tidb_enable_table_partition' if you need to need to enable it") errUnsupportedIndexType = terror.ClassDDL.New(mysql.ErrUnsupportedDDLOperation, fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation], "index type")) // ErrDupKeyName returns for duplicated key name diff --git a/ddl/partition.go b/ddl/partition.go index 8249281836980..bc612fb650d27 100644 --- a/ddl/partition.go +++ b/ddl/partition.go @@ -79,7 +79,7 @@ func buildTablePartitionInfo(ctx sessionctx.Context, d *ddl, s *ast.CreateTableS } } if !enable { - ctx.GetSessionVars().StmtCtx.AppendWarning(errUnsupportedCreatePartition) + ctx.GetSessionVars().StmtCtx.AppendWarning(errTablePartitionDisabled) } pi := &model.PartitionInfo{ diff --git a/session/session.go b/session/session.go index 4b719242e0a13..44e12de2a0736 100644 --- a/session/session.go +++ b/session/session.go @@ -1853,6 +1853,7 @@ var builtinGlobalVariable = []string{ variable.TiDBRetryLimit, variable.TiDBDisableTxnAutoRetry, variable.TiDBEnableWindowFunction, + variable.TiDBEnableTablePartition, variable.TiDBEnableVectorizedExpression, variable.TiDBEnableFastAnalyze, variable.TiDBExpensiveQueryTimeThreshold, diff --git a/session/session_test.go b/session/session_test.go index 8839fb6b44236..19446b5f5ecd4 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -2493,6 +2493,22 @@ func (s *testSessionSuite2) TestCommitRetryCount(c *C) { c.Assert(err, NotNil) } +func (s *testSessionSuite2) TestEnablePartition(c *C) { + tk := testkit.NewTestKitWithInit(c, s.store) + tk.MustExec("set tidb_enable_table_partition=off") + tk.MustQuery("show variables like 'tidb_enable_table_partition'").Check(testkit.Rows("tidb_enable_table_partition off")) + + tk.MustExec("set global tidb_enable_table_partition = on") + + tk.MustQuery("show variables like 'tidb_enable_table_partition'").Check(testkit.Rows("tidb_enable_table_partition off")) + tk.MustQuery("show global variables like 'tidb_enable_table_partition'").Check(testkit.Rows("tidb_enable_table_partition on")) + + // Disable global variable cache, so load global session variable take effect immediate. + s.dom.GetGlobalVarsCache().Disable() + tk1 := testkit.NewTestKitWithInit(c, s.store) + tk1.MustQuery("show variables like 'tidb_enable_table_partition'").Check(testkit.Rows("tidb_enable_table_partition on")) +} + func (s *testSessionSuite2) TestTxnRetryErrMsg(c *C) { tk1 := testkit.NewTestKitWithInit(c, s.store) tk2 := testkit.NewTestKitWithInit(c, s.store) diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 03ffe4821b504..a1853d0c450c2 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -686,7 +686,7 @@ var defaultSysVars = []*SysVar{ {ScopeSession, TiDBEnableStreaming, "0"}, {ScopeSession, TiDBEnableChunkRPC, "1"}, {ScopeSession, TxnIsolationOneShot, ""}, - {ScopeSession, TiDBEnableTablePartition, "auto"}, + {ScopeGlobal | ScopeSession, TiDBEnableTablePartition, "auto"}, {ScopeGlobal | ScopeSession, TiDBHashJoinConcurrency, strconv.Itoa(DefTiDBHashJoinConcurrency)}, {ScopeGlobal | ScopeSession, TiDBProjectionConcurrency, strconv.Itoa(DefTiDBProjectionConcurrency)}, {ScopeGlobal | ScopeSession, TiDBHashAggPartialConcurrency, strconv.Itoa(DefTiDBHashAggPartialConcurrency)},