Skip to content

Commit

Permalink
config, ddl: make TableColumnCountLimit configurable or be compatib…
Browse files Browse the repository at this point in the history
…le with MySQL (pingcap#21612)
  • Loading branch information
TszKitLo40 authored Dec 17, 2020
1 parent b25f62d commit ce704c8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
9 changes: 9 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ const (
DefStatusHost = "0.0.0.0"
// DefStoreLivenessTimeout is the default value for store liveness timeout.
DefStoreLivenessTimeout = "5s"
// Def TableColumnCountLimit is limit of the number of columns in a table
DefTableColumnCountLimit = 1017
// Def TableColumnCountLimit is maximum limitation of the number of columns in a table
DefMaxOfTableColumnCountLimit = 4096
// DefTxnScope is the default value for TxnScope
DefTxnScope = "global"
// DefStoresRefreshInterval is the default value of StoresRefreshInterval
Expand Down Expand Up @@ -127,6 +131,7 @@ type Config struct {
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"`
TableColumnCountLimit uint32 `toml:"table-column-count-limit" json:"table-column-count-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 @@ -647,6 +652,7 @@ var defaultConf = Config{
CheckMb4ValueInUTF8: true,
MaxIndexLength: 3072,
IndexLimit: 64,
TableColumnCountLimit: 1017,
AlterPrimaryKey: false,
TreatOldVersionUTF8AsUTF8MB4: true,
EnableTableLock: false,
Expand Down Expand Up @@ -958,6 +964,9 @@ func (c *Config) Valid() error {
if c.OOMAction != OOMActionLog && c.OOMAction != OOMActionCancel {
return fmt.Errorf("unsupported OOMAction %v, TiDB only supports [%v, %v]", c.OOMAction, OOMActionLog, OOMActionCancel)
}
if c.TableColumnCountLimit < DefTableColumnCountLimit || c.TableColumnCountLimit > DefMaxOfTableColumnCountLimit {
return fmt.Errorf("table-column-limit should be [%d, %d]", DefIndexLimit, DefMaxOfTableColumnCountLimit)
}

// lower_case_table_names is allowed to be 0, 1, 2
if c.LowerCaseTableNames < 0 || c.LowerCaseTableNames > 2 {
Expand Down
14 changes: 14 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ max-server-connections = 200
mem-quota-query = 10000
max-index-length = 3080
index-limit = 70
table-column-count-limit = 4000
skip-register-to-dashboard = true
deprecate-integer-display-length = true
txn-scope = "dc-1"
Expand Down Expand Up @@ -264,6 +265,7 @@ spilled-file-encryption-method = "plaintext"
c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"})
c.Assert(conf.MaxIndexLength, Equals, 3080)
c.Assert(conf.IndexLimit, Equals, 70)
c.Assert(conf.TableColumnCountLimit, Equals, uint32(4000))
c.Assert(conf.SkipRegisterToDashboard, Equals, true)
c.Assert(len(conf.Labels), Equals, 2)
c.Assert(conf.Labels["foo"], Equals, "bar")
Expand Down Expand Up @@ -486,6 +488,18 @@ func (s *testConfigSuite) TestIndexLimit(c *C) {
checkValid(DefMaxOfIndexLimit+1, false)
}

func (s *testConfigSuite) TestTableColumnCountLimit(c *C) {
conf := NewConfig()
checkValid := func(tableColumnLimit int, shouldBeValid bool) {
conf.TableColumnCountLimit = uint32(tableColumnLimit)
c.Assert(conf.Valid() == nil, Equals, shouldBeValid)
}
checkValid(DefTableColumnCountLimit, true)
checkValid(DefTableColumnCountLimit-1, false)
checkValid(DefMaxOfTableColumnCountLimit, true)
checkValid(DefMaxOfTableColumnCountLimit+1, false)
}

func (s *testConfigSuite) TestParsePath(c *C) {
etcdAddrs, disableGC, err := ParsePath("tikv://node1:2379,node2:2379")
c.Assert(err, IsNil)
Expand Down
3 changes: 2 additions & 1 deletion ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
ddlutil "github.com/pingcap/tidb/ddl/util"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -1607,7 +1608,7 @@ func allocateColumnID(tblInfo *model.TableInfo) int64 {
}

func checkAddColumnTooManyColumns(colNum int) error {
if uint32(colNum) > atomic.LoadUint32(&TableColumnCountLimit) {
if uint32(colNum) > atomic.LoadUint32(&config.GetGlobalConfig().TableColumnCountLimit) {
return errTooManyFields
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1348,11 +1348,11 @@ func (s *testIntegrationSuite6) TestCreateTableTooLarge(c *C) {
sql += ");"
tk.MustGetErrCode(sql, errno.ErrTooManyFields)

originLimit := atomic.LoadUint32(&ddl.TableColumnCountLimit)
atomic.StoreUint32(&ddl.TableColumnCountLimit, uint32(cnt*4))
originLimit := config.GetGlobalConfig().TableColumnCountLimit
atomic.StoreUint32(&config.GetGlobalConfig().TableColumnCountLimit, uint32(cnt*4))
_, err := tk.Exec(sql)
c.Assert(kv.ErrEntryTooLarge.Equal(err), IsTrue, Commentf("err:%v", err))
atomic.StoreUint32(&ddl.TableColumnCountLimit, originLimit)
atomic.StoreUint32(&config.GetGlobalConfig().TableColumnCountLimit, originLimit)
}

func (s *testIntegrationSuite8) TestCreateTableTooManyIndexes(c *C) {
Expand Down Expand Up @@ -1472,7 +1472,7 @@ func (s *testIntegrationSuite3) TestResolveCharset(c *C) {
func (s *testIntegrationSuite6) TestAddColumnTooMany(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
count := int(atomic.LoadUint32(&ddl.TableColumnCountLimit) - 1)
count := int(atomic.LoadUint32(&config.GetGlobalConfig().TableColumnCountLimit) - 1)
var cols []string
for i := 0; i < count; i++ {
cols = append(cols, fmt.Sprintf("a%d int", i))
Expand Down
3 changes: 0 additions & 3 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ const (
)

var (
// TableColumnCountLimit is limit of the number of columns in a table.
// It's exported for testing.
TableColumnCountLimit = uint32(512)
// TableIndexCountLimit is limit of the number of indexes in a table.
TableIndexCountLimit = uint32(64)
// EnableSplitTableRegion is a flag to decide whether to split a new region for
Expand Down
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ func checkTooLongColumn(cols []*model.ColumnInfo) error {
}

func checkTooManyColumns(colDefs []*model.ColumnInfo) error {
if uint32(len(colDefs)) > atomic.LoadUint32(&TableColumnCountLimit) {
if uint32(len(colDefs)) > atomic.LoadUint32(&config.GetGlobalConfig().TableColumnCountLimit) {
return errTooManyFields
}
return nil
Expand Down

0 comments on commit ce704c8

Please sign in to comment.