Skip to content

Commit

Permalink
*: add tidb_enable_global_index session variables (#48834)
Browse files Browse the repository at this point in the history
close #48825
  • Loading branch information
Defined2014 authored Nov 30, 2023
1 parent 86a7ab3 commit 94a7844
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 181 deletions.
5 changes: 4 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ type Config struct {
// 2. 'zone' is a special key that indicates the DC location of this tidb-server. If it is set, the value for this
// key will be the default value of the session variable `txn_scope` for this tidb-server.
Labels map[string]string `toml:"labels" json:"labels"`
// EnableGlobalIndex enables creating global index.

// EnableGlobalIndex is deprecated.
EnableGlobalIndex bool `toml:"enable-global-index" json:"enable-global-index"`

// DeprecateIntegerDisplayWidth indicates whether deprecating the max display length for integer.
DeprecateIntegerDisplayWidth bool `toml:"deprecate-integer-display-length" json:"deprecate-integer-display-length"`
// EnableEnumLengthLimit indicates whether the enum/set element length is limited.
Expand Down Expand Up @@ -1159,6 +1161,7 @@ var removedConfig = map[string]struct{}{
"max-server-connections": {}, // use sysvar max_connections
"run-ddl": {}, // use sysvar tidb_enable_ddl
"instance.tidb_memory_usage_alarm_ratio": {}, // use sysvar tidb_memory_usage_alarm_ratio
"enable-global-index": {}, // use sysvar tidb_enable_global_index
}

// isAllRemovedConfigItems returns true if all the items that couldn't validate
Expand Down
7 changes: 2 additions & 5 deletions pkg/ddl/db_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2314,10 +2314,7 @@ func TestDuplicateErrorMessage(t *testing.T) {
for _, newCollate := range []bool{false, true} {
collate.SetNewCollationEnabledForTest(newCollate)
for _, globalIndex := range []bool{false, true} {
restoreConfig := config.RestoreFunc()
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableGlobalIndex = globalIndex
})
tk.MustExec(fmt.Sprintf("set tidb_enable_global_index=%t", globalIndex))
for _, clusteredIndex := range []variable.ClusteredIndexDefMode{variable.ClusteredIndexDefModeOn, variable.ClusteredIndexDefModeOff, variable.ClusteredIndexDefModeIntOnly} {
tk.Session().GetSessionVars().EnableClusteredIndex = clusteredIndex
for _, t := range tests {
Expand All @@ -2344,7 +2341,7 @@ func TestDuplicateErrorMessage(t *testing.T) {
fmt.Sprintf("[kv:1062]Duplicate entry '1-%s' for key 't.t_idx'", strings.Join(fields, "-")))
}
}
restoreConfig()
tk.MustExec("set tidb_enable_global_index=default")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7064,7 +7064,7 @@ func (d *ddl) CreatePrimaryKey(ctx sessionctx.Context, ti ast.Ident, indexName m
return err
}
if !ck {
if !config.GetGlobalConfig().EnableGlobalIndex {
if !ctx.GetSessionVars().EnableGlobalIndex {
return dbterror.ErrUniqueKeyNeedAllFieldsInPf.GenWithStackByArgs("PRIMARY")
}
// index columns does not contain all partition columns, must set global
Expand Down Expand Up @@ -7312,7 +7312,7 @@ func (d *ddl) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast.Inde
return err
}
if !ck {
if !config.GetGlobalConfig().EnableGlobalIndex {
if !ctx.GetSessionVars().EnableGlobalIndex {
return dbterror.ErrUniqueKeyNeedAllFieldsInPf.GenWithStackByArgs("UNIQUE INDEX")
}
// index columns does not contain all partition columns, must set global
Expand Down
9 changes: 4 additions & 5 deletions pkg/ddl/index_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/ddl"
testddlutil "github.com/pingcap/tidb/pkg/ddl/testutil"
"github.com/pingcap/tidb/pkg/errno"
Expand Down Expand Up @@ -679,13 +678,13 @@ func TestAddIndexWithPK(t *testing.T) {
}

func TestAddGlobalIndex(t *testing.T) {
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
conf.EnableGlobalIndex = true
})
store := testkit.CreateMockStoreWithSchemaLease(t, indexModifyLease)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("set tidb_enable_global_index=true")
defer func() {
tk.MustExec("set tidb_enable_global_index=default")
}()
tk.MustExec("create table test_t1 (a int, b int) partition by range (b)" +
" (partition p0 values less than (10), " +
" partition p1 values less than (maxvalue));")
Expand Down
7 changes: 3 additions & 4 deletions pkg/ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/tidb/pkg/config"
sess "github.com/pingcap/tidb/pkg/ddl/internal/session"
"github.com/pingcap/tidb/pkg/ddl/label"
"github.com/pingcap/tidb/pkg/ddl/placement"
Expand Down Expand Up @@ -611,7 +610,7 @@ func buildTablePartitionInfo(ctx sessionctx.Context, s *ast.PartitionOptions, tb

for _, index := range tbInfo.Indices {
if index.Unique && !checkUniqueKeyIncludePartKey(partCols, index.Columns) {
index.Global = config.GetGlobalConfig().EnableGlobalIndex
index.Global = ctx.GetSessionVars().EnableGlobalIndex
}
}
return nil
Expand Down Expand Up @@ -3808,11 +3807,11 @@ func checkPartitioningKeysConstraints(sctx sessionctx.Context, s *ast.CreateTabl
if tblInfo.IsCommonHandle {
return dbterror.ErrUniqueKeyNeedAllFieldsInPf.GenWithStackByArgs("CLUSTERED INDEX")
}
if !config.GetGlobalConfig().EnableGlobalIndex {
if !sctx.GetSessionVars().EnableGlobalIndex {
return dbterror.ErrUniqueKeyNeedAllFieldsInPf.GenWithStackByArgs("PRIMARY KEY")
}
}
if !config.GetGlobalConfig().EnableGlobalIndex {
if !sctx.GetSessionVars().EnableGlobalIndex {
return dbterror.ErrUniqueKeyNeedAllFieldsInPf.GenWithStackByArgs("UNIQUE INDEX")
}
}
Expand Down
Loading

0 comments on commit 94a7844

Please sign in to comment.