Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session: fix tables_priv table schema (#33599) #33604

Merged
merged 11 commits into from
Jun 17, 2022
Prev Previous commit
Next Next commit
session: update
  • Loading branch information
zimulala committed Jun 14, 2022
commit ee02aee753a3b5361a12fd967796da5be83f31cf
122 changes: 11 additions & 111 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ const (
last_analyzed_at TIMESTAMP,
PRIMARY KEY (table_id, column_id) CLUSTERED
);`
// CreateTableCacheMetaTable stores the cached table meta lock information.
CreateTableCacheMetaTable = `CREATE TABLE IF NOT EXISTS mysql.table_cache_meta (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove CreateTableCacheMetaTable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may affect the next cherry-pick classmates.

tid bigint(11) NOT NULL DEFAULT 0,
lock_type enum('NONE','READ', 'INTEND', 'WRITE') NOT NULL DEFAULT 'NONE',
lease bigint(20) NOT NULL DEFAULT 0,
oldReadLease bigint(20) NOT NULL DEFAULT 0,
PRIMARY KEY (tid)
);`
)

// bootstrap initiates system DB for a store.
Expand Down Expand Up @@ -528,32 +536,15 @@ const (
version77 = 77
// version78 updates mysql.stats_buckets.lower_bound, mysql.stats_buckets.upper_bound and mysql.stats_histograms.last_analyze_pos from BLOB to LONGBLOB.
version78 = 78
<<<<<<< HEAD
=======
// version79 adds the mysql.table_cache_meta table
// And update mysql.tables_priv from SET('Select','Insert','Update') to SET('Select','Insert','Update','References').
version79 = 79
// version80 fixes the issue https://github.com/pingcap/tidb/issues/25422.
// If the TiDB upgrading from the 4.x to a newer version, we keep the tidb_analyze_version to 1.
version80 = 80
// version81 insert "tidb_enable_index_merge|off" to mysql.GLOBAL_VARIABLES if there is no tidb_enable_index_merge.
// This will only happens when we upgrade a cluster before 4.0.0 to 4.0.0+.
version81 = 81
// version82 adds the mysql.analyze_options table
version82 = 82
// version83 adds the tables mysql.stats_history
version83 = 83
// version84 adds the tables mysql.stats_meta_history
version84 = 84
// version85 updates bindings with status 'using' in mysql.bind_info table to 'enabled' status
version85 = 85
// version86 update mysql.tables_priv from SET('Select','Insert','Update') to SET('Select','Insert','Update','References').
version86 = 86
>>>>>>> e15e6d035... session: fix tables_priv table schema (#33599)
// Note: the version86 of master is merge into version79.
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
// please make sure this is the largest version
var currentBootstrapVersion int64 = version78
var currentBootstrapVersion int64 = version79

var (
bootstrapVersion = []func(Session, int64){
Expand Down Expand Up @@ -635,17 +626,7 @@ var (
upgradeToVer76,
upgradeToVer77,
upgradeToVer78,
<<<<<<< HEAD
=======
upgradeToVer79,
upgradeToVer80,
upgradeToVer81,
upgradeToVer82,
upgradeToVer83,
upgradeToVer84,
upgradeToVer85,
upgradeToVer86,
>>>>>>> e15e6d035... session: fix tables_priv table schema (#33599)
}
)

Expand Down Expand Up @@ -1644,95 +1625,14 @@ func upgradeToVer78(s Session, ver int64) {
doReentrantDDL(s, "ALTER TABLE mysql.stats_histograms MODIFY last_analyze_pos LONGBLOB DEFAULT NULL")
}

<<<<<<< HEAD
=======
func upgradeToVer79(s Session, ver int64) {
if ver >= version79 {
return
}
doReentrantDDL(s, CreateTableCacheMetaTable)
}

func upgradeToVer80(s Session, ver int64) {
if ver >= version80 {
return
}
// Check if tidb_analyze_version exists in mysql.GLOBAL_VARIABLES.
// If not, insert "tidb_analyze_version | 1" since this is the old behavior before we introduce this variable.
ctx := context.Background()
rs, err := s.ExecuteInternal(ctx, "SELECT VARIABLE_VALUE FROM %n.%n WHERE VARIABLE_NAME=%?;",
mysql.SystemDB, mysql.GlobalVariablesTable, variable.TiDBAnalyzeVersion)
terror.MustNil(err)
req := rs.NewChunk(nil)
err = rs.Next(ctx, req)
terror.MustNil(err)
if req.NumRows() != 0 {
return
}

mustExecute(s, "INSERT HIGH_PRIORITY IGNORE INTO %n.%n VALUES (%?, %?);",
mysql.SystemDB, mysql.GlobalVariablesTable, variable.TiDBAnalyzeVersion, 1)
}

// For users that upgrade TiDB from a pre-4.0 version, we want to disable index merge by default.
// This helps minimize query plan regressions.
func upgradeToVer81(s Session, ver int64) {
if ver >= version81 {
return
}
// Check if tidb_enable_index_merge exists in mysql.GLOBAL_VARIABLES.
// If not, insert "tidb_enable_index_merge | off".
ctx := context.Background()
rs, err := s.ExecuteInternal(ctx, "SELECT VARIABLE_VALUE FROM %n.%n WHERE VARIABLE_NAME=%?;",
mysql.SystemDB, mysql.GlobalVariablesTable, variable.TiDBEnableIndexMerge)
terror.MustNil(err)
req := rs.NewChunk(nil)
err = rs.Next(ctx, req)
terror.MustNil(err)
if req.NumRows() != 0 {
return
}

mustExecute(s, "INSERT HIGH_PRIORITY IGNORE INTO %n.%n VALUES (%?, %?);",
mysql.SystemDB, mysql.GlobalVariablesTable, variable.TiDBEnableIndexMerge, variable.Off)
}

func upgradeToVer82(s Session, ver int64) {
if ver >= version82 {
return
}
doReentrantDDL(s, CreateAnalyzeOptionsTable)
}

func upgradeToVer83(s Session, ver int64) {
if ver >= version83 {
return
}
doReentrantDDL(s, CreateStatsHistory)
}

func upgradeToVer84(s Session, ver int64) {
if ver >= version84 {
return
}
doReentrantDDL(s, CreateStatsMetaHistory)
}

func upgradeToVer85(s Session, ver int64) {
if ver >= version85 {
return
}
mustExecute(s, fmt.Sprintf("UPDATE HIGH_PRIORITY mysql.bind_info SET status= '%s' WHERE status = '%s'", bindinfo.Enabled, bindinfo.Using))
}

func upgradeToVer86(s Session, ver int64) {
if ver >= version86 {
return
}
doReentrantDDL(s, "ALTER TABLE mysql.tables_priv MODIFY COLUMN Column_priv SET('Select','Insert','Update','References')")
}

>>>>>>> e15e6d035... session: fix tables_priv table schema (#33599)
func writeOOMAction(s Session) {
comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+"
mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`,
Expand Down