Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pingcap/tidb into binding…
Browse files Browse the repository at this point in the history
…Stats
  • Loading branch information
Reminiscent committed Aug 3, 2021
2 parents cd76bc2 + de3bc62 commit b1fa991
Show file tree
Hide file tree
Showing 56 changed files with 1,327 additions and 718 deletions.
1 change: 0 additions & 1 deletion cmd/explaintest/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ status-host = "127.0.0.1"
stats-lease = "0"

[experimental]
allow-expression-index = true
28 changes: 14 additions & 14 deletions cmd/explaintest/r/explain_complex_stats.result

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,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 creating expression index.
AllowsExpressionIndex bool `toml:"allow-expression-index" json:"allow-expression-index"`
// Whether enable global kill.
EnableGlobalKill bool `toml:"enable-global-kill" json:"-"`
}
Expand Down Expand Up @@ -667,8 +665,7 @@ var defaultConf = Config{
Engines: []string{"tikv", "tiflash", "tidb"},
},
Experimental: Experimental{
AllowsExpressionIndex: false,
EnableGlobalKill: false,
EnableGlobalKill: false,
},
EnableCollectExecutionInfo: true,
EnableTelemetry: true,
Expand Down
2 changes: 0 additions & 2 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,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 creating expression index.
allow-expression-index = false

# server level isolation read by engines and labels
[isolation-read]
Expand Down
2 changes: 0 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ max-sql-length=1024
refresh-interval=100
history-size=100
[experimental]
allow-expression-index = true
[isolation-read]
engines = ["tiflash"]
[labels]
Expand Down Expand Up @@ -272,7 +271,6 @@ deadlock-history-collect-retryable = true
c.Assert(conf.RepairMode, Equals, true)
c.Assert(conf.MaxServerConnections, Equals, uint32(200))
c.Assert(conf.MemQuotaQuery, Equals, int64(10000))
c.Assert(conf.Experimental.AllowsExpressionIndex, IsTrue)
c.Assert(conf.IsolationRead.Engines, DeepEquals, []string{"tiflash"})
c.Assert(conf.MaxIndexLength, Equals, 3080)
c.Assert(conf.IndexLimit, Equals, 70)
Expand Down
19 changes: 0 additions & 19 deletions ddl/db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/executor"
Expand Down Expand Up @@ -96,9 +95,6 @@ func (s *testStateChangeSuiteBase) TearDownSuite(c *C) {

// TestShowCreateTable tests the result of "show create table" when we are running "add index" or "add column".
func (s *serialTestStateChangeSuite) TestShowCreateTable(c *C) {
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table t (id int)")
Expand Down Expand Up @@ -755,12 +751,6 @@ func (s *testStateChangeSuite) TestDeleteOnlyForDropColumnWithIndexes(c *C) {

// TestDeleteOnlyForDropExpressionIndex tests for deleting data when the hidden column is delete-only state.
func (s *serialTestStateChangeSuite) TestDeleteOnlyForDropExpressionIndex(c *C) {
originalVal := config.GetGlobalConfig().Experimental.AllowsExpressionIndex
config.GetGlobalConfig().Experimental.AllowsExpressionIndex = true
defer func() {
config.GetGlobalConfig().Experimental.AllowsExpressionIndex = originalVal
}()

_, err := s.se.Execute(context.Background(), "use test_db_state")
c.Assert(err, IsNil)
_, err = s.se.Execute(context.Background(), `create table tt (a int, b int)`)
Expand Down Expand Up @@ -1161,9 +1151,6 @@ func (s *testStateChangeSuite) TestParallelAlterAddIndex(c *C) {
}

func (s *serialTestStateChangeSuite) TestParallelAlterAddExpressionIndex(c *C) {
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
sql1 := "ALTER TABLE t add index expr_index_b((b+1));"
sql2 := "CREATE INDEX expr_index_b ON t ((c+1));"
f := func(c *C, err1, err2 error) {
Expand Down Expand Up @@ -1799,12 +1786,6 @@ func (s *testStateChangeSuite) TestWriteReorgForColumnTypeChange(c *C) {
}

func (s *serialTestStateChangeSuite) TestCreateExpressionIndex(c *C) {
originalVal := config.GetGlobalConfig().Experimental.AllowsExpressionIndex
config.GetGlobalConfig().Experimental.AllowsExpressionIndex = true
defer func() {
config.GetGlobalConfig().Experimental.AllowsExpressionIndex = originalVal
}()

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test_db_state")
tk.MustExec("drop table if exists t")
Expand Down
34 changes: 9 additions & 25 deletions ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2244,9 +2244,6 @@ func (s *testIntegrationSuite3) TestParserIssue284(c *C) {
}

func (s *testSerialDBSuite1) TestAddExpressionIndex(c *C) {
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
Expand Down Expand Up @@ -2305,27 +2302,17 @@ func (s *testSerialDBSuite1) TestAddExpressionIndex(c *C) {
tk.MustExec("create table t(a int, key((a+1)), key((a+2)), key idx((a+3)), key((a+4)));")
tk.MustExec("drop table if exists t")
tk.MustExec("CREATE TABLE t (A INT, B INT, UNIQUE KEY ((A * 2)));")

// Test experiment switch.
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = false
})
tk.MustGetErrMsg("create index d on t((a+1))", "[ddl:8200]Unsupported creating expression index without allow-expression-index in config")
tk.MustGetErrMsg("create table t(a int, key ((a+1)));", "[ddl:8200]Unsupported creating expression index without allow-expression-index in config")
}

func (s *testSerialDBSuite1) TestCreateExpressionIndexError(c *C) {
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})

tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int, b real);")
tk.MustGetErrCode("alter table t add primary key ((a+b)) nonclustered;", errno.ErrFunctionalIndexPrimaryKey)

tk.MustGetErrCode("create table t(a int, index((cast(a as JSON))))", errno.ErrFunctionalIndexOnJSONOrGeometryFunction)

// Test for error
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t (a int, b real);")
Expand Down Expand Up @@ -2363,9 +2350,6 @@ func (s *testSerialDBSuite1) TestCreateExpressionIndexError(c *C) {
}

func (s *testSerialDBSuite1) TestAddExpressionIndexOnPartition(c *C) {
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
Expand Down Expand Up @@ -2498,9 +2482,6 @@ func (s *testIntegrationSuite3) TestCreateTableWithAutoIdCache(c *C) {
}

func (s *testIntegrationSuite4) TestAlterIndexVisibility(c *C) {
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("create database if not exists alter_index_test")
tk.MustExec("USE alter_index_test;")
Expand Down Expand Up @@ -2597,10 +2578,6 @@ func (s *testIntegrationSuite5) TestDropColumnsWithMultiIndex(c *C) {
}

func (s *testSerialDBSuite) TestDropLastVisibleColumnOrColumns(c *C) {
defer config.RestoreFunc()
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test_db")
tk.MustExec("create table t_drop_last_column(x int, key((1+1)))")
Expand Down Expand Up @@ -3149,4 +3126,11 @@ func (s *testIntegrationSuite3) TestDropTemporaryTable(c *C) {
_ = iter.Next()
}
c.Assert(iter.Valid(), IsFalse)

// Check drop not exists table in transaction.
tk.MustExec("begin")
tk.MustExec("create temporary table a_local_temp_table_8 (id int)")
_, err = tk.Exec("drop table a_local_temp_table_8, a_local_temp_table_9_not_exist")
c.Assert(err.Error(), Equals, "[schema:1051]Unknown table 'test.a_local_temp_table_9_not_exist'")
tk.MustQuery("select * from a_local_temp_table_8").Check(testkit.Rows())
}
3 changes: 0 additions & 3 deletions ddl/db_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2081,9 +2081,6 @@ func (s *testIntegrationSuite4) TestExchangePartitionTableCompatiable(c *C) {
}

func (s *testSerialDBSuite1) TestExchangePartitionExpressIndex(c *C) {
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("set @@tidb_enable_exchange_partition=1")
Expand Down
3 changes: 0 additions & 3 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,6 @@ func (s *testSerialDBSuite) TestWriteReorgForColumnTypeChangeOnAmendTxn(c *C) {
}

func (s *testSerialDBSuite) TestAddExpressionIndexRollback(c *C) {
config.UpdateGlobal(func(conf *config.Config) {
conf.Experimental.AllowsExpressionIndex = true
})
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test_db")
tk.MustExec("drop table if exists t1")
Expand Down
3 changes: 0 additions & 3 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5099,9 +5099,6 @@ func buildHiddenColumnInfo(ctx sessionctx.Context, indexPartSpecifications []*as
idxPart.Expr = nil
hiddenCols = append(hiddenCols, colInfo)
}
if len(hiddenCols) > 0 && !config.GetGlobalConfig().Experimental.AllowsExpressionIndex {
return nil, ErrUnsupportedExpressionIndex
}
return hiddenCols, nil
}

Expand Down
4 changes: 2 additions & 2 deletions ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ var (
ErrColumnTypeUnsupportedNextValue = dbterror.ClassDDL.NewStd(mysql.ErrColumnTypeUnsupportedNextValue)
// ErrAddColumnWithSequenceAsDefault is returned when the new added column with sequence's nextval as it's default value.
ErrAddColumnWithSequenceAsDefault = dbterror.ClassDDL.NewStd(mysql.ErrAddColumnWithSequenceAsDefault)
// ErrUnsupportedExpressionIndex is returned when create an expression index without allow-expression-index.
ErrUnsupportedExpressionIndex = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "creating expression index without allow-expression-index in config"), nil))
// ErrPartitionExchangePartTable is returned when exchange table partition with another table is partitioned.
ErrPartitionExchangePartTable = dbterror.ClassDDL.NewStd(mysql.ErrPartitionExchangePartTable)
// ErrTablesDifferentMetadata is returned when exchanges tables is not compatible.
Expand Down Expand Up @@ -290,4 +288,6 @@ var (

// ErrInvalidAttributesSpec is returned when meeting invalid attributes.
ErrInvalidAttributesSpec = dbterror.ClassDDL.NewStd(mysql.ErrInvalidAttributesSpec)
// ErrFunctionalIndexOnJSONOrGeometryFunction returns when creating expression index and the type of the expression is JSON.
ErrFunctionalIndexOnJSONOrGeometryFunction = dbterror.ClassDDL.NewStd(mysql.ErrFunctionalIndexOnJSONOrGeometryFunction)
)
5 changes: 4 additions & 1 deletion ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ func checkIndexPrefixLength(columns []*model.ColumnInfo, idxColumns []*model.Ind

func checkIndexColumn(col *model.ColumnInfo, indexColumnLen int) error {
if col.Flen == 0 && (types.IsTypeChar(col.FieldType.Tp) || types.IsTypeVarchar(col.FieldType.Tp)) {
if col.GeneratedExprString != "" {
if col.Hidden {
return errors.Trace(errWrongKeyColumnFunctionalIndex.GenWithStackByArgs(col.GeneratedExprString))
}
return errors.Trace(errWrongKeyColumn.GenWithStackByArgs(col.Name))
}

// JSON column cannot index.
if col.FieldType.Tp == mysql.TypeJSON {
if col.Hidden {
return ErrFunctionalIndexOnJSONOrGeometryFunction
}
return errors.Trace(errJSONUsedAsKey.GenWithStackByArgs(col.Name.O))
}

Expand Down
Loading

0 comments on commit b1fa991

Please sign in to comment.