diff --git a/privilege/privileges/cache.go b/privilege/privileges/cache.go index 3ff9e6b0c28bb..d00dc99bb076c 100644 --- a/privilege/privileges/cache.go +++ b/privilege/privileges/cache.go @@ -156,7 +156,7 @@ func noSuchTable(err error) bool { // LoadUserTable loads the mysql.user table from database. func (p *MySQLPrivilege) LoadUserTable(ctx sessionctx.Context) error { - err := p.loadTable(ctx, "select Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Process_priv,Grant_priv,References_priv,Alter_priv,Show_db_priv,Super_priv,Execute_priv,Index_priv,Create_user_priv,Trigger_priv from mysql.user;", p.decodeUserTableRow) + err := p.loadTable(ctx, "select HIGH_PRIORITY Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Process_priv,Grant_priv,References_priv,Alter_priv,Show_db_priv,Super_priv,Execute_priv,Index_priv,Create_user_priv,Trigger_priv from mysql.user;", p.decodeUserTableRow) if err != nil { return errors.Trace(err) } @@ -253,17 +253,17 @@ func (p MySQLPrivilege) SortUserTable() { // LoadDBTable loads the mysql.db table from database. func (p *MySQLPrivilege) LoadDBTable(ctx sessionctx.Context) error { - return p.loadTable(ctx, "select Host,DB,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,Index_priv,Alter_priv,Execute_priv from mysql.db order by host, db, user;", p.decodeDBTableRow) + return p.loadTable(ctx, "select HIGH_PRIORITY Host,DB,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,Index_priv,Alter_priv,Execute_priv from mysql.db order by host, db, user;", p.decodeDBTableRow) } // LoadTablesPrivTable loads the mysql.tables_priv table from database. func (p *MySQLPrivilege) LoadTablesPrivTable(ctx sessionctx.Context) error { - return p.loadTable(ctx, "select Host,DB,User,Table_name,Grantor,Timestamp,Table_priv,Column_priv from mysql.tables_priv", p.decodeTablesPrivTableRow) + return p.loadTable(ctx, "select HIGH_PRIORITY Host,DB,User,Table_name,Grantor,Timestamp,Table_priv,Column_priv from mysql.tables_priv", p.decodeTablesPrivTableRow) } // LoadColumnsPrivTable loads the mysql.columns_priv table from database. func (p *MySQLPrivilege) LoadColumnsPrivTable(ctx sessionctx.Context) error { - return p.loadTable(ctx, "select Host,DB,User,Table_name,Column_name,Timestamp,Column_priv from mysql.columns_priv", p.decodeColumnsPrivTableRow) + return p.loadTable(ctx, "select HIGH_PRIORITY Host,DB,User,Table_name,Column_name,Timestamp,Column_priv from mysql.columns_priv", p.decodeColumnsPrivTableRow) } func (p *MySQLPrivilege) loadTable(sctx sessionctx.Context, sql string, diff --git a/server/server.go b/server/server.go index 942c39df4dc81..4512a60bc20be 100644 --- a/server/server.go +++ b/server/server.go @@ -36,11 +36,11 @@ import ( "math/rand" "net" "net/http" + // For pprof + _ "net/http/pprof" "sync" "sync/atomic" "time" - // For pprof - _ "net/http/pprof" "github.com/blacktear23/go-proxyprotocol" "github.com/juju/errors" diff --git a/session/bootstrap.go b/session/bootstrap.go index 724600f4de74d..c4298907d66b3 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -286,7 +286,7 @@ func checkBootstrapped(s Session) (bool, error) { // getTiDBVar gets variable value from mysql.tidb table. // Those variables are used by TiDB server. func getTiDBVar(s Session, name string) (sVal string, isNull bool, e error) { - sql := fmt.Sprintf(`SELECT VARIABLE_VALUE FROM %s.%s WHERE VARIABLE_NAME="%s"`, + sql := fmt.Sprintf(`SELECT HIGH_PRIORITY VARIABLE_VALUE FROM %s.%s WHERE VARIABLE_NAME="%s"`, mysql.SystemDB, mysql.TiDBTable, name) ctx := context.Background() rs, err := s.Execute(ctx, sql) @@ -436,7 +436,7 @@ func upgradeToVer2(s Session) { value := fmt.Sprintf(`("%s", "%s")`, v, variable.SysVars[v].Value) values = append(values, value) } - sql := fmt.Sprintf("INSERT IGNORE INTO %s.%s VALUES %s;", mysql.SystemDB, mysql.GlobalVariablesTable, + sql := fmt.Sprintf("INSERT HIGH_PRIORITY IGNORE INTO %s.%s VALUES %s;", mysql.SystemDB, mysql.GlobalVariablesTable, strings.Join(values, ", ")) mustExecute(s, sql) } @@ -444,7 +444,7 @@ func upgradeToVer2(s Session) { // upgradeToVer3 updates to version 3. func upgradeToVer3(s Session) { // Version 3 fix tx_read_only variable value. - sql := fmt.Sprintf("UPDATE %s.%s set variable_value = '0' where variable_name = 'tx_read_only';", + sql := fmt.Sprintf("UPDATE HIGH_PRIORITY %s.%s set variable_value = '0' where variable_name = 'tx_read_only';", mysql.SystemDB, mysql.GlobalVariablesTable) mustExecute(s, sql) } @@ -463,18 +463,18 @@ func upgradeToVer5(s Session) { func upgradeToVer6(s Session) { doReentrantDDL(s, "ALTER TABLE mysql.user ADD COLUMN `Super_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N' AFTER `Show_db_priv`", infoschema.ErrColumnExists) // For reasons of compatibility, set the non-exists privilege column value to 'Y', as TiDB doesn't check them in older versions. - mustExecute(s, "UPDATE mysql.user SET Super_priv='Y'") + mustExecute(s, "UPDATE HIGH_PRIORITY mysql.user SET Super_priv='Y'") } func upgradeToVer7(s Session) { doReentrantDDL(s, "ALTER TABLE mysql.user ADD COLUMN `Process_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N' AFTER `Drop_priv`", infoschema.ErrColumnExists) // For reasons of compatibility, set the non-exists privilege column value to 'Y', as TiDB doesn't check them in older versions. - mustExecute(s, "UPDATE mysql.user SET Process_priv='Y'") + mustExecute(s, "UPDATE HIGH_PRIORITY mysql.user SET Process_priv='Y'") } func upgradeToVer8(s Session) { // This is a dummy upgrade, it checks whether upgradeToVer7 success, if not, do it again. - if _, err := s.Execute(context.Background(), "SELECT `Process_priv` from mysql.user limit 0"); err == nil { + if _, err := s.Execute(context.Background(), "SELECT HIGH_PRIORITY `Process_priv` from mysql.user limit 0"); err == nil { return } upgradeToVer7(s) @@ -483,7 +483,7 @@ func upgradeToVer8(s Session) { func upgradeToVer9(s Session) { doReentrantDDL(s, "ALTER TABLE mysql.user ADD COLUMN `Trigger_priv` enum('N','Y') CHARACTER SET utf8 NOT NULL DEFAULT 'N' AFTER `Create_user_priv`", infoschema.ErrColumnExists) // For reasons of compatibility, set the non-exists privilege column value to 'Y', as TiDB doesn't check them in older versions. - mustExecute(s, "UPDATE mysql.user SET Trigger_priv='Y'") + mustExecute(s, "UPDATE HIGH_PRIORITY mysql.user SET Trigger_priv='Y'") } func doReentrantDDL(s Session, sql string, ignorableErrs ...error) { @@ -514,14 +514,14 @@ func upgradeToVer11(s Session) { } log.Fatal(err) } - mustExecute(s, "UPDATE mysql.user SET References_priv='Y'") + mustExecute(s, "UPDATE HIGH_PRIORITY mysql.user SET References_priv='Y'") } func upgradeToVer12(s Session) { ctx := context.Background() _, err := s.Execute(ctx, "BEGIN") terror.MustNil(err) - sql := "SELECT user, host, password FROM mysql.user WHERE password != ''" + sql := "SELECT HIGH_PRIORITY user, host, password FROM mysql.user WHERE password != ''" rs, err := s.Execute(ctx, sql) terror.MustNil(err) r := rs[0] @@ -538,7 +538,7 @@ func upgradeToVer12(s Session) { var newPass string newPass, err = oldPasswordUpgrade(pass) terror.MustNil(err) - updateSQL := fmt.Sprintf(`UPDATE mysql.user set password = "%s" where user="%s" and host="%s"`, newPass, user, host) + updateSQL := fmt.Sprintf(`UPDATE HIGH_PRIORITY mysql.user set password = "%s" where user="%s" and host="%s"`, newPass, user, host) sqls = append(sqls, updateSQL) } err = r.Next(ctx, chk) @@ -549,7 +549,7 @@ func upgradeToVer12(s Session) { mustExecute(s, sql) } - sql = fmt.Sprintf(`INSERT INTO %s.%s VALUES ("%s", "%d", "TiDB bootstrap version.") ON DUPLICATE KEY UPDATE VARIABLE_VALUE="%d"`, + sql = fmt.Sprintf(`INSERT HIGH_PRIORITY INTO %s.%s VALUES ("%s", "%d", "TiDB bootstrap version.") ON DUPLICATE KEY UPDATE VARIABLE_VALUE="%d"`, mysql.SystemDB, mysql.TiDBTable, tidbServerVersionVar, version12, version12) mustExecute(s, sql) @@ -576,7 +576,7 @@ func upgradeToVer13(s Session) { log.Fatal(err) } } - mustExecute(s, "UPDATE mysql.user SET Create_tmp_table_priv='Y',Lock_tables_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',Event_priv='Y'") + mustExecute(s, "UPDATE HIGH_PRIORITY mysql.user SET Create_tmp_table_priv='Y',Lock_tables_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',Event_priv='Y'") } func upgradeToVer14(s Session) { @@ -652,7 +652,7 @@ func upgradeToVer23(s Session) { // updateBootstrapVer updates bootstrap version variable in mysql.TiDB table. func updateBootstrapVer(s Session) { // Update bootstrap version. - sql := fmt.Sprintf(`INSERT INTO %s.%s VALUES ("%s", "%d", "TiDB bootstrap version.") ON DUPLICATE KEY UPDATE VARIABLE_VALUE="%d"`, + sql := fmt.Sprintf(`INSERT HIGH_PRIORITY INTO %s.%s VALUES ("%s", "%d", "TiDB bootstrap version.") ON DUPLICATE KEY UPDATE VARIABLE_VALUE="%d"`, mysql.SystemDB, mysql.TiDBTable, tidbServerVersionVar, currentBootstrapVersion, currentBootstrapVersion) mustExecute(s, sql) } @@ -707,7 +707,7 @@ func doDMLWorks(s Session) { mustExecute(s, "BEGIN") // Insert a default user with empty password. - mustExecute(s, `INSERT INTO mysql.user VALUES + mustExecute(s, `INSERT HIGH_PRIORITY INTO mysql.user VALUES ("%", "root", "", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y")`) // Init global system variables table. @@ -719,16 +719,16 @@ func doDMLWorks(s Session) { values = append(values, value) } } - sql := fmt.Sprintf("INSERT INTO %s.%s VALUES %s;", mysql.SystemDB, mysql.GlobalVariablesTable, + sql := fmt.Sprintf("INSERT HIGH_PRIORITY INTO %s.%s VALUES %s;", mysql.SystemDB, mysql.GlobalVariablesTable, strings.Join(values, ", ")) mustExecute(s, sql) - sql = fmt.Sprintf(`INSERT INTO %s.%s VALUES("%s", "%s", "Bootstrap flag. Do not delete.") + sql = fmt.Sprintf(`INSERT HIGH_PRIORITY INTO %s.%s VALUES("%s", "%s", "Bootstrap flag. Do not delete.") ON DUPLICATE KEY UPDATE VARIABLE_VALUE="%s"`, mysql.SystemDB, mysql.TiDBTable, bootstrappedVar, bootstrappedVarTrue, bootstrappedVarTrue) mustExecute(s, sql) - sql = fmt.Sprintf(`INSERT INTO %s.%s VALUES("%s", "%d", "Bootstrap version. Do not delete.")`, + sql = fmt.Sprintf(`INSERT HIGH_PRIORITY INTO %s.%s VALUES("%s", "%d", "Bootstrap version. Do not delete.")`, mysql.SystemDB, mysql.TiDBTable, tidbServerVersionVar, currentBootstrapVersion) mustExecute(s, sql) diff --git a/statistics/boostrap.go b/statistics/bootstrap.go similarity index 94% rename from statistics/boostrap.go rename to statistics/bootstrap.go index 938ccf0f31296..726c44bf2fe4d 100644 --- a/statistics/boostrap.go +++ b/statistics/bootstrap.go @@ -58,7 +58,7 @@ func (h *Handle) initStatsMeta4Chunk(is infoschema.InfoSchema, tables statsCache func (h *Handle) initStatsMeta(is infoschema.InfoSchema) (statsCache, error) { h.mu.Lock() defer h.mu.Unlock() - sql := "select version, table_id, modify_count, count from mysql.stats_meta" + sql := "select HIGH_PRIORITY version, table_id, modify_count, count from mysql.stats_meta" rc, err := h.mu.ctx.(sqlexec.SQLExecutor).Execute(context.TODO(), sql) if len(rc) > 0 { defer terror.Call(rc[0].Close) @@ -128,7 +128,7 @@ func (h *Handle) initStatsHistograms4Chunk(is infoschema.InfoSchema, tables stat func (h *Handle) initStatsHistograms(is infoschema.InfoSchema, tables statsCache) error { h.mu.Lock() defer h.mu.Unlock() - sql := "select table_id, is_index, hist_id, distinct_count, version, null_count, cm_sketch, tot_col_size, stats_ver from mysql.stats_histograms" + sql := "select HIGH_PRIORITY table_id, is_index, hist_id, distinct_count, version, null_count, cm_sketch, tot_col_size, stats_ver from mysql.stats_histograms" rc, err := h.mu.ctx.(sqlexec.SQLExecutor).Execute(context.TODO(), sql) if len(rc) > 0 { defer terror.Call(rc[0].Close) @@ -200,7 +200,7 @@ func initStatsBuckets4Chunk(ctx sessionctx.Context, tables statsCache, iter *chu func (h *Handle) initStatsBuckets(tables statsCache) error { h.mu.Lock() defer h.mu.Unlock() - sql := "select table_id, is_index, hist_id, count, repeats, lower_bound, upper_bound from mysql.stats_buckets order by table_id, is_index, hist_id, bucket_id" + sql := "select HIGH_PRIORITY table_id, is_index, hist_id, count, repeats, lower_bound, upper_bound from mysql.stats_buckets order by table_id, is_index, hist_id, bucket_id" rc, err := h.mu.ctx.(sqlexec.SQLExecutor).Execute(context.TODO(), sql) if len(rc) > 0 { defer terror.Call(rc[0].Close) diff --git a/store/tikv/gcworker/gc_worker.go b/store/tikv/gcworker/gc_worker.go index 9f4885321540f..cfe0a9fbdb9e7 100644 --- a/store/tikv/gcworker/gc_worker.go +++ b/store/tikv/gcworker/gc_worker.go @@ -872,7 +872,7 @@ func (w *GCWorker) loadValueFromSysTable(key string) (string, error) { } func (w *GCWorker) saveValueToSysTable(key, value string) error { - stmt := fmt.Sprintf(`INSERT INTO mysql.tidb VALUES ('%[1]s', '%[2]s', '%[3]s') + stmt := fmt.Sprintf(`INSERT HIGH_PRIORITY INTO mysql.tidb VALUES ('%[1]s', '%[2]s', '%[3]s') ON DUPLICATE KEY UPDATE variable_value = '%[2]s', comment = '%[3]s'`, key, value, gcVariableComments[key])