Skip to content

Commit

Permalink
session: support 'GLOBAL SCOPE' for tidb_enable_table_partition (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
bb7133 committed Dec 20, 2019
1 parent 37b1d77 commit b1dc803
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ var (
ErrUnsupportedPartitionByRangeColumns = terror.ClassDDL.New(codeUnsupportedPartitionByRangeColumns,
"unsupported partition by range columns")
errUnsupportedCreatePartition = terror.ClassDDL.New(codeUnsupportedCreatePartition, "unsupported partition type, treat as normal table")
errTablePartitionDisabled = terror.ClassDDL.New(codeUnsupportedCreatePartition, "Partitions are ignored because Table Partition is disabled, please set 'tidb_enable_table_partition' if you need to need to enable it")

// ErrDupKeyName returns for duplicated key name
ErrDupKeyName = terror.ClassDDL.New(codeDupKeyName, "duplicate key name")
Expand Down
2 changes: 1 addition & 1 deletion ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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{
Expand Down
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,7 @@ var builtinGlobalVariable = []string{
variable.TiDBRetryLimit,
variable.TiDBDisableTxnAutoRetry,
variable.TiDBEnableWindowFunction,
variable.TiDBEnableTablePartition,
variable.TiDBEnableFastAnalyze,
variable.TiDBExpensiveQueryTimeThreshold,
variable.TiDBTxnMode,
Expand Down
16 changes: 16 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2420,6 +2420,22 @@ func (s *testSessionSuite) 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 *testSessionSuite) TestTxnRetryErrMsg(c *C) {
tk1 := testkit.NewTestKitWithInit(c, s.store)
tk2 := testkit.NewTestKitWithInit(c, s.store)
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ var defaultSysVars = []*SysVar{
{ScopeSession, TIDBMemQuotaNestedLoopApply, strconv.FormatInt(DefTiDBMemQuotaNestedLoopApply, 10)},
{ScopeSession, TiDBEnableStreaming, "0"},
{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)},
Expand Down

0 comments on commit b1dc803

Please sign in to comment.