diff --git a/config/config.go b/config/config.go index 9235f753d5aa0..8aa5add1583a4 100644 --- a/config/config.go +++ b/config/config.go @@ -88,7 +88,8 @@ type Config struct { CheckMb4ValueInUTF8 bool `toml:"check-mb4-value-in-utf8" json:"check-mb4-value-in-utf8"` // TreatOldVersionUTF8AsUTF8MB4 is use to treat old version table/column UTF8 charset as UTF8MB4. This is for compatibility. // Currently not support dynamic modify, because this need to reload all old version schema. - TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"` + TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"` + SplitRegionMaxNum uint64 `toml:"split-region-max-num" json:"split-region-max-num"` } // Log is the log section of config. @@ -321,6 +322,7 @@ var defaultConf = Config{ EnableStreaming: false, CheckMb4ValueInUTF8: true, TreatOldVersionUTF8AsUTF8MB4: true, + SplitRegionMaxNum: 1000, TxnLocalLatches: TxnLocalLatches{ Enabled: true, Capacity: 2048000, diff --git a/config/config.toml.example b/config/config.toml.example index 93a5454196ed7..b2016f95d1e29 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -54,6 +54,9 @@ check-mb4-value-in-utf8 = true # treat-old-version-utf8-as-utf8mb4 use for upgrade compatibility. Set to true will treat old version table/column UTF8 charset as UTF8MB4. treat-old-version-utf8-as-utf8mb4 = true +# Maximum number of the splitting region, which is used by the split region statement. +split-region-max-num = 1000 + [log] # Log level: debug, info, warn, error, fatal. level = "info" diff --git a/config/config_test.go b/config/config_test.go index ddc18e2f6cc04..84d8788d66f9b 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -60,6 +60,7 @@ unrecognized-option-test = true _, err = f.WriteString(` token-limit = 0 +split-region-max-num=10000 [performance] [tikv-client] commit-timeout="41s" @@ -78,6 +79,7 @@ max-batch-size=128 c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s") c.Assert(conf.TiKVClient.MaxBatchSize, Equals, uint(128)) c.Assert(conf.TokenLimit, Equals, uint(1000)) + c.Assert(conf.SplitRegionMaxNum, Equals, uint64(10000)) c.Assert(f.Close(), IsNil) c.Assert(os.Remove(configFile), IsNil) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index a2a717d694636..86a6ffe381d71 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -27,6 +27,7 @@ import ( "github.com/pingcap/parser/model" "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/opcode" + "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -1774,8 +1775,6 @@ func (b *PlanBuilder) buildLoadStats(ld *ast.LoadStatsStmt) Plan { return p } -const maxSplitRegionNum = 1000 - func (b *PlanBuilder) buildSplitRegion(node *ast.SplitRegionStmt) (Plan, error) { if len(node.IndexName.L) != 0 { return b.buildSplitIndexRegion(node) @@ -1836,6 +1835,7 @@ func (b *PlanBuilder) buildSplitIndexRegion(node *ast.SplitRegionStmt) (Plan, er p.Lower = lowerValues p.Upper = upperValues + maxSplitRegionNum := int64(config.GetGlobalConfig().SplitRegionMaxNum) if node.SplitOpt.Num > maxSplitRegionNum { return nil, errors.Errorf("Split index region num exceeded the limit %v", maxSplitRegionNum) } else if node.SplitOpt.Num < 1 { @@ -1946,6 +1946,7 @@ func (b *PlanBuilder) buildSplitTableRegion(node *ast.SplitRegionStmt) (Plan, er p.Lower = []types.Datum{lowerValues} p.Upper = []types.Datum{upperValue} + maxSplitRegionNum := int64(config.GetGlobalConfig().SplitRegionMaxNum) if node.SplitOpt.Num > maxSplitRegionNum { return nil, errors.Errorf("Split table region num exceeded the limit %v", maxSplitRegionNum) } else if node.SplitOpt.Num < 1 {