Skip to content

Commit

Permalink
config: remove allow-auto-random config option (pingcap#16596)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Jul 16, 2020
1 parent 5246521 commit 2bc02be
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 83 deletions.
6 changes: 0 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,6 @@ type IsolationRead struct {
// Experimental controls the features that are still experimental: their semantics, interfaces are subject to change.
// Using these features in the production environment is not recommended.
type Experimental struct {
// Whether enable the syntax like `auto_random(3)` on the primary key column.
AllowAutoRandom bool `toml:"allow-auto-random" json:"allow-auto-random"`
// Whether enable creating expression index.
AllowsExpressionIndex bool `toml:"allow-expression-index" json:"allow-expression-index"`
}
Expand Down Expand Up @@ -681,7 +679,6 @@ var defaultConf = Config{
Engines: []string{"tikv", "tiflash", "tidb"},
},
Experimental: Experimental{
AllowAutoRandom: false,
AllowsExpressionIndex: false,
},
EnableCollectExecutionInfo: true,
Expand Down Expand Up @@ -867,9 +864,6 @@ func (c *Config) Valid() error {
return fmt.Errorf("refresh-interval in [stmt-summary] should be greater than 0")
}

if c.AlterPrimaryKey && c.Experimental.AllowAutoRandom {
return fmt.Errorf("allow-auto-random is unavailable when alter-primary-key is enabled")
}
if c.PreparedPlanCache.Capacity < 1 {
return fmt.Errorf("capacity in [prepared-plan-cache] should be at least 1")
}
Expand Down
2 changes: 0 additions & 2 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ history-size = 24
# experimental section controls the features that are still experimental: their semantics,
# interfaces are subject to change, using these features in the production environment is not recommended.
[experimental]
# enable column attribute `auto_random` to be defined on the primary key column.
allow-auto-random = false
# enable creating expression index.
allow-expression-index = false

Expand Down
15 changes: 0 additions & 15 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ max-sql-length=1024
refresh-interval=100
history-size=100
[experimental]
allow-auto-random = true
allow-expression-index = true
[isolation-read]
engines = ["tiflash"]
Expand Down Expand Up @@ -245,7 +244,6 @@ engines = ["tiflash"]
c.Assert(conf.MaxServerConnections, Equals, uint32(200))
c.Assert(conf.MemQuotaQuery, Equals, int64(10000))
c.Assert(conf.Experimental.AllowsExpressionIndex, IsTrue)
c.Assert(conf.Experimental.AllowAutoRandom, IsTrue)
c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"})
c.Assert(conf.MaxIndexLength, Equals, 3080)
c.Assert(conf.SkipRegisterToDashboard, Equals, true)
Expand Down Expand Up @@ -414,19 +412,6 @@ func (s *testConfigSuite) TestTxnTotalSizeLimitValid(c *C) {
}
}

func (s *testConfigSuite) TestAllowAutoRandomValid(c *C) {
conf := NewConfig()
checkValid := func(allowAlterPK, allowAutoRand, shouldBeValid bool) {
conf.AlterPrimaryKey = allowAlterPK
conf.Experimental.AllowAutoRandom = allowAutoRand
c.Assert(conf.Valid() == nil, Equals, shouldBeValid)
}
checkValid(true, true, false)
checkValid(true, false, true)
checkValid(false, true, true)
checkValid(false, false, true)
}

func (s *testConfigSuite) TestPreparePlanCacheValid(c *C) {
conf := NewConfig()
tests := map[PreparedPlanCache]bool{
Expand Down
7 changes: 0 additions & 7 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1106,13 +1106,9 @@ func checkConstraintNames(constraints []*ast.Constraint) error {
}

func setTableAutoRandomBits(ctx sessionctx.Context, tbInfo *model.TableInfo, colDefs []*ast.ColumnDef) error {
allowAutoRandom := config.GetGlobalConfig().Experimental.AllowAutoRandom
pkColName := tbInfo.GetPkName()
for _, col := range colDefs {
if containsColumnOption(col, ast.ColumnOptionAutoRandom) {
if !allowAutoRandom {
return ErrInvalidAutoRandom.GenWithStackByArgs(autoid.AutoRandomExperimentalDisabledErrMsg)
}
if col.Tp.Tp != mysql.TypeLonglong {
return ErrInvalidAutoRandom.GenWithStackByArgs(
fmt.Sprintf(autoid.AutoRandomOnNonBigIntColumn, types.TypeStr(col.Tp.Tp)))
Expand Down Expand Up @@ -3085,9 +3081,6 @@ func checkColumnWithIndexConstraint(tbInfo *model.TableInfo, originalCol, newCol
}

func checkAutoRandom(tableInfo *model.TableInfo, originCol *table.Column, specNewColumn *ast.ColumnDef) (uint64, error) {
if !config.GetGlobalConfig().Experimental.AllowAutoRandom && containsColumnOption(specNewColumn, ast.ColumnOptionAutoRandom) {
return 0, ErrInvalidAutoRandom.GenWithStackByArgs(autoid.AutoRandomExperimentalDisabledErrMsg)
}
// Disallow add/drop actions on auto_random.
oldRandBits := tableInfo.AutoRandomBits
newRandBits, err := extractAutoRandomBitsFromColDef(specNewColumn)
Expand Down
14 changes: 7 additions & 7 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,6 @@ func (s *testSerialSuite) TestAutoRandom(c *C) {
assertPKIsNotHandle := func(sql, errCol string) {
assertInvalidAutoRandomErr(sql, autoid.AutoRandomPKisNotHandleErrMsg, errCol)
}
assertExperimentDisabled := func(sql string) {
assertInvalidAutoRandomErr(sql, autoid.AutoRandomExperimentalDisabledErrMsg)
}
assertAlterValue := func(sql string) {
assertInvalidAutoRandomErr(sql, autoid.AutoRandomAlterErrMsg)
}
Expand Down Expand Up @@ -898,6 +895,13 @@ func (s *testSerialSuite) TestAutoRandom(c *C) {
assertPKIsNotHandle("create table t (a bigint auto_random(3), b bigint, primary key (a, b))", "a")
assertPKIsNotHandle("create table t (a bigint auto_random(3), b int, c char, primary key (a, c))", "a")

// PKIsNotHandle: table is created when alter-primary-key = true.
config.GetGlobalConfig().AlterPrimaryKey = true
assertPKIsNotHandle("create table t (a bigint auto_random(3) primary key, b int)", "a")
assertPKIsNotHandle("create table t (a bigint auto_random(3) primary key, b int)", "a")
assertPKIsNotHandle("create table t (a int, b bigint auto_random(3) primary key)", "b")
config.GetGlobalConfig().AlterPrimaryKey = false

// Can not set auto_random along with auto_increment.
assertWithAutoInc("create table t (a bigint auto_random(3) primary key auto_increment)")
assertWithAutoInc("create table t (a bigint primary key auto_increment auto_random(3))")
Expand Down Expand Up @@ -1016,10 +1020,6 @@ func (s *testSerialSuite) TestAutoRandom(c *C) {
tk.MustExec("insert into t values(3)")
tk.MustExec("insert into t values()")
})

// Disallow using it when allow-auto-random is not enabled.
config.GetGlobalConfig().Experimental.AllowAutoRandom = false
assertExperimentDisabled("create table auto_random_table (a int primary key auto_random(3))")
}

func (s *testSerialSuite) TestAutoRandomIncBitsIncrementAndOffset(c *C) {
Expand Down
38 changes: 10 additions & 28 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/errno"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testutil"
)

func (s *testSuite8) TestInsertOnDuplicateKey(c *C) {
Expand Down Expand Up @@ -968,13 +970,8 @@ type testSuite9 struct {
}

func (s *testSuite9) TestAutoRandomID(c *C) {
allowAutoRandom := config.GetGlobalConfig().Experimental.AllowAutoRandom
if !allowAutoRandom {
config.GetGlobalConfig().Experimental.AllowAutoRandom = true
defer func() {
config.GetGlobalConfig().Experimental.AllowAutoRandom = false
}()
}
testutil.ConfigTestUtils.SetupAutoRandomTestConfig()
defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig()

tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test`)
Expand Down Expand Up @@ -1017,13 +1014,8 @@ func (s *testSuite9) TestAutoRandomID(c *C) {
}

func (s *testSuite9) TestMultiAutoRandomID(c *C) {
allowAutoRandom := config.GetGlobalConfig().Experimental.AllowAutoRandom
if !allowAutoRandom {
config.GetGlobalConfig().Experimental.AllowAutoRandom = true
defer func() {
config.GetGlobalConfig().Experimental.AllowAutoRandom = false
}()
}
testutil.ConfigTestUtils.SetupAutoRandomTestConfig()
defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig()

tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test`)
Expand Down Expand Up @@ -1066,13 +1058,8 @@ func (s *testSuite9) TestMultiAutoRandomID(c *C) {
}

func (s *testSuite9) TestAutoRandomIDAllowZero(c *C) {
allowAutoRandom := config.GetGlobalConfig().Experimental.AllowAutoRandom
if !allowAutoRandom {
config.GetGlobalConfig().Experimental.AllowAutoRandom = true
defer func() {
config.GetGlobalConfig().Experimental.AllowAutoRandom = false
}()
}
testutil.ConfigTestUtils.SetupAutoRandomTestConfig()
defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig()

tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test`)
Expand Down Expand Up @@ -1104,13 +1091,8 @@ func (s *testSuite9) TestAutoRandomIDAllowZero(c *C) {
}

func (s *testSuite9) TestAutoRandomIDExplicit(c *C) {
allowAutoRandom := config.GetGlobalConfig().Experimental.AllowAutoRandom
if !allowAutoRandom {
config.GetGlobalConfig().Experimental.AllowAutoRandom = true
defer func() {
config.GetGlobalConfig().Experimental.AllowAutoRandom = false
}()
}
testutil.ConfigTestUtils.SetupAutoRandomTestConfig()
defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig()

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("set @@allow_auto_random_explicit_insert = true")
Expand Down
7 changes: 2 additions & 5 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,8 @@ func HelperTestAdminShowNextID(c *C, s *seqTestSuite, str string) {
r.Check(testkit.Rows("test1 tt id 41 AUTO_INCREMENT"))
tk.MustExec("drop table tt")

oldAutoRandom := config.GetGlobalConfig().Experimental.AllowAutoRandom
config.GetGlobalConfig().Experimental.AllowAutoRandom = true
defer func() {
config.GetGlobalConfig().Experimental.AllowAutoRandom = oldAutoRandom
}()
testutil.ConfigTestUtils.SetupAutoRandomTestConfig()
defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig()
tk.MustExec("set @@allow_auto_random_explicit_insert = true")

// Test for a table with auto_random primary key.
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ require (
github.com/ngaut/sync2 v0.0.0-20141008032647-7a24ed77b2ef
github.com/opentracing/basictracer-go v1.0.0
github.com/opentracing/opentracing-go v1.1.0
github.com/pingcap/br v0.0.0-20200623060633-439a1c2b2bfd
github.com/pingcap/br v0.0.0-20200716021245-f1df51c11469
github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712
github.com/pingcap/errors v0.11.5-0.20190809092503-95897b64e011
github.com/pingcap/failpoint v0.0.0-20200603062251-b230c36c413c
github.com/pingcap/fn v0.0.0-20191016082858-07623b84a47d
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20200518112156-d4aeb467de29
github.com/pingcap/kvproto v0.0.0-20200706115936-1e0910aabe6c
github.com/pingcap/log v0.0.0-20200511115504-543df19646ad
github.com/pingcap/parser v0.0.0-20200623164729-3a18f1e5dceb
github.com/pingcap/pd/v4 v4.0.0-rc.2.0.20200520083007-2c251bd8f181
github.com/pingcap/sysutil v0.0.0-20200408114249-ed3bd6f7fdb1
github.com/pingcap/tidb-tools v4.0.0-rc.1.0.20200514040632-f76b3e428e19+incompatible
github.com/pingcap/tidb-tools v4.0.0-rc.2.0.20200521050818-6dd445d83fe0+incompatible
github.com/pingcap/tipb v0.0.0-20200522051215-f31a15d98fce
github.com/prometheus/client_golang v1.5.1
github.com/prometheus/client_model v0.2.0
Expand All @@ -55,10 +55,9 @@ require (
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
golang.org/x/text v0.3.2
golang.org/x/tools v0.0.0-20200325203130-f53864d0dba1
golang.org/x/tools v0.0.0-20200521211927-2b542361a4fc
google.golang.org/grpc v1.26.0
gopkg.in/natefinch/lumberjack.v2 v2.0.0
honnef.co/go/tools v0.0.1-2020.1.4 // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)
Expand Down
Loading

0 comments on commit 2bc02be

Please sign in to comment.