Skip to content

Commit

Permalink
config: remove allow-auto-random config option (#16596)
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored Jun 10, 2020
1 parent 1cc33b0 commit f12cdc4
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 90 deletions.
6 changes: 0 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,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 @@ -680,7 +678,6 @@ var defaultConf = Config{
Engines: []string{"tikv", "tiflash", "tidb"},
},
Experimental: Experimental{
AllowAutoRandom: false,
AllowsExpressionIndex: false,
},
EnableCollectExecutionInfo: false,
Expand Down Expand Up @@ -863,9 +860,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 @@ -415,8 +415,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 @@ -204,7 +204,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 @@ -244,7 +243,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)

Expand Down Expand Up @@ -388,19 +386,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 @@ -1169,13 +1169,9 @@ func getPrimaryKey(tblInfo *model.TableInfo) *model.IndexInfo {
}

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 @@ -3513,9 +3509,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 @@ -843,9 +843,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 @@ -900,6 +897,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 @@ -1017,10 +1021,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) TestAutoRandomExchangePartition(c *C) {
Expand Down
38 changes: 9 additions & 29 deletions executor/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/errno"
"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 +968,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 @@ -1011,13 +1006,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 @@ -1060,13 +1050,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 @@ -1098,13 +1083,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 @@ -830,12 +830,9 @@ 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
testutil.ConfigTestUtils.SetupAutoRandomTestConfig()
defer testutil.ConfigTestUtils.RestoreAutoRandomTestConfig()
tk.MustExec("set @@allow_auto_random_explicit_insert = true")
defer func() {
config.GetGlobalConfig().Experimental.AllowAutoRandom = oldAutoRandom
}()

// Test for a table with auto_random primary key.
tk.MustExec("create table t3(id bigint primary key auto_random(5), c int)")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/opentracing/basictracer-go v1.0.0
github.com/opentracing/opentracing-go v1.1.0
github.com/pingcap/badger v1.5.1-0.20200604041313-19c397305fcc
github.com/pingcap/br v0.0.0-20200521085655-53201addd4ad
github.com/pingcap/br v0.0.0-20200610051721-b057d65ff579
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
Expand Down Expand Up @@ -56,7 +56,7 @@ 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
sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4
Expand Down
Loading

0 comments on commit f12cdc4

Please sign in to comment.