Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: Add index limit configuration #21192

Merged
merged 8 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const (
DefMaxIndexLength = 3072
// DefMaxOfMaxIndexLength is the maximum index length(in bytes) for TiDB v3.0.7 and previous version.
DefMaxOfMaxIndexLength = 3072 * 4
// DefIndexLimit is the limitation of index on a single table. This value is consistent with MySQL.
DefIndexLimit = 64
// DefMaxOfIndexLimit is the maximum limitation of index on a single table for TiDB.
DefMaxOfIndexLimit = 64 * 8
// DefMinQuotaStatistics is the minimum statistic memory quota(in bytes).
DefMinQuotaStatistics = 32 << 30
// DefPort is the default port of TiDB
Expand Down Expand Up @@ -125,6 +129,7 @@ type Config struct {
PessimisticTxn PessimisticTxn `toml:"pessimistic-txn" json:"pessimistic-txn"`
CheckMb4ValueInUTF8 bool `toml:"check-mb4-value-in-utf8" json:"check-mb4-value-in-utf8"`
MaxIndexLength int `toml:"max-index-length" json:"max-index-length"`
IndexLimit int `toml:"index-limit" json:"index-limit"`
GracefulWaitBeforeShutdown int `toml:"graceful-wait-before-shutdown" json:"graceful-wait-before-shutdown"`
// AlterPrimaryKey is used to control alter primary key feature.
AlterPrimaryKey bool `toml:"alter-primary-key" json:"alter-primary-key"`
Expand Down Expand Up @@ -644,6 +649,7 @@ var defaultConf = Config{
EnableBatchDML: false,
CheckMb4ValueInUTF8: true,
MaxIndexLength: 3072,
IndexLimit: 64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use DefIndexLimit here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use DefIndexLimit as a constant. I think it is ok to use IndexLimit here, as other configuration items do not start with Def @AilinKid

AlterPrimaryKey: false,
TreatOldVersionUTF8AsUTF8MB4: true,
EnableTableLock: false,
Expand Down Expand Up @@ -937,6 +943,9 @@ func (c *Config) Valid() error {
if c.MaxIndexLength < DefMaxIndexLength || c.MaxIndexLength > DefMaxOfMaxIndexLength {
return fmt.Errorf("max-index-length should be [%d, %d]", DefMaxIndexLength, DefMaxOfMaxIndexLength)
}
if c.IndexLimit < DefIndexLimit || c.IndexLimit > DefMaxOfIndexLimit {
return fmt.Errorf("index-limit should be [%d, %d]", DefIndexLimit, DefMaxOfIndexLimit)
}
if c.Log.File.MaxSize > MaxLogFileSize {
return fmt.Errorf("invalid max log file size=%v which is larger than max=%v", c.Log.File.MaxSize, MaxLogFileSize)
}
Expand Down
3 changes: 3 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ treat-old-version-utf8-as-utf8mb4 = true
# max-index-length is used to deal with compatibility issues from v3.0.7 and previous version upgrades. It can only be in [3072, 3072*4].
max-index-length = 3072

# index-limit is used to deal with compatibility issues. It can only be in [64, 64*4].
index-limit = 64

# enable-table-lock is used to control table lock feature. Default is false, indicate the table lock feature is disabled.
enable-table-lock = false

Expand Down
14 changes: 14 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ mem-quota-query = 10000
mem-quota-statistics = 10000
nested-loop-join-cache-capacity = 100
max-index-length = 3080
index-limit = 70
skip-register-to-dashboard = true
deprecate-integer-display-length = true
txn-scope = "dc-1"
Expand Down Expand Up @@ -269,6 +270,7 @@ spilled-file-encryption-method = "plaintext"
c.Assert(conf.NestedLoopJoinCacheCapacity, Equals, int64(100))
c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"})
c.Assert(conf.MaxIndexLength, Equals, 3080)
c.Assert(conf.IndexLimit, Equals, 70)
c.Assert(conf.SkipRegisterToDashboard, Equals, true)
c.Assert(len(conf.Labels), Equals, 2)
c.Assert(conf.Labels["foo"], Equals, "bar")
Expand Down Expand Up @@ -478,6 +480,18 @@ func (s *testConfigSuite) TestMaxIndexLength(c *C) {
checkValid(DefMaxOfMaxIndexLength+1, false)
}

func (s *testConfigSuite) TestIndexLimit(c *C) {
conf := NewConfig()
checkValid := func(indexLimit int, shouldBeValid bool) {
conf.IndexLimit = indexLimit
c.Assert(conf.Valid() == nil, Equals, shouldBeValid)
}
checkValid(DefIndexLimit, true)
checkValid(DefIndexLimit-1, false)
checkValid(DefMaxOfIndexLimit, true)
checkValid(DefMaxOfIndexLimit+1, false)
}

func (s *testConfigSuite) TestParsePath(c *C) {
etcdAddrs, disableGC, err := ParsePath("tikv://node1:2379,node2:2379")
c.Assert(err, IsNil)
Expand Down
4 changes: 2 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,8 @@ func checkTooManyColumns(colDefs []*model.ColumnInfo) error {
}

func checkTooManyIndexes(idxDefs []*model.IndexInfo) error {
if uint32(len(idxDefs)) > atomic.LoadUint32(&TableIndexCountLimit) {
return errTooManyKeys.GenWithStackByArgs(TableIndexCountLimit)
if len(idxDefs) > config.GetGlobalConfig().IndexLimit {
return errTooManyKeys.GenWithStackByArgs(config.GetGlobalConfig().IndexLimit)
}
return nil
}
Expand Down