Skip to content

Commit

Permalink
support
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisaer committed Feb 10, 2023
1 parent 7bc6722 commit 6c426ed
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 25 deletions.
10 changes: 5 additions & 5 deletions domain/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ func insertPlanReplayerStatus(ctx context.Context, sctx sessionctx.Context, reco
}

func insertPlanReplayerErrorStatusRecord(ctx context.Context, sctx sessionctx.Context, instance string, record PlanReplayerStatusRecord) {
exec := sctx.(sqlexec.SQLExecutor)
_, err := exec.ExecuteInternal(ctx, fmt.Sprintf(
exec := sctx.(sqlexec.RestrictedSQLExecutor)
_, _, err := exec.ExecRestrictedSQL(ctx, nil, fmt.Sprintf(
"insert into mysql.plan_replayer_status (sql_digest, plan_digest, origin_sql, fail_reason, instance) values ('%s','%s','%s','%s','%s')",
record.SQLDigest, record.PlanDigest, record.OriginSQL, record.FailedReason, instance))
if err != nil {
Expand All @@ -158,16 +158,16 @@ func insertPlanReplayerErrorStatusRecord(ctx context.Context, sctx sessionctx.Co
}

func insertPlanReplayerSuccessStatusRecord(ctx context.Context, sctx sessionctx.Context, instance string, record PlanReplayerStatusRecord) {
exec := sctx.(sqlexec.SQLExecutor)
_, err := exec.ExecuteInternal(ctx, fmt.Sprintf(
exec := sctx.(sqlexec.RestrictedSQLExecutor)
_, _, err := exec.ExecRestrictedSQL(ctx, nil, fmt.Sprintf(
"insert into mysql.plan_replayer_status (sql_digest, plan_digest, origin_sql, token, instance) values ('%s','%s','%s','%s','%s')",
record.SQLDigest, record.PlanDigest, record.OriginSQL, record.Token, instance))
if err != nil {
logutil.BgLogger().Warn("insert mysql.plan_replayer_status record failed",
zap.String("sql", record.OriginSQL),
zap.Error(err))
// try insert record without original sql
_, err = exec.ExecuteInternal(ctx, fmt.Sprintf(
_, _, err = exec.ExecRestrictedSQL(ctx, nil, fmt.Sprintf(
"insert into mysql.plan_replayer_status (sql_digest, plan_digest, token, instance) values ('%s','%s','%s','%s')",
record.SQLDigest, record.PlanDigest, record.Token, instance))
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions executor/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func (e *PlanReplayerExec) Next(ctx context.Context, req *chunk.Chunk) error {

func (e *PlanReplayerExec) removeCaptureTask(ctx context.Context) error {
ctx1 := kv.WithInternalSourceType(ctx, kv.InternalTxnStats)
exec := e.ctx.(sqlexec.SQLExecutor)
_, err := exec.ExecuteInternal(ctx1, fmt.Sprintf("delete from mysql.plan_replayer_task where sql_digest = '%s' and plan_digest = '%s'",
exec := e.ctx.(sqlexec.RestrictedSQLExecutor)
_, _, err := exec.ExecRestrictedSQL(ctx1, nil, fmt.Sprintf("delete from mysql.plan_replayer_task where sql_digest = '%s' and plan_digest = '%s'",
e.CaptureInfo.SQLDigest, e.CaptureInfo.PlanDigest))
if err != nil {
logutil.BgLogger().Warn("remove mysql.plan_replayer_status record failed",
Expand All @@ -134,8 +134,8 @@ func (e *PlanReplayerExec) registerCaptureTask(ctx context.Context) error {
if exists {
return errors.New("plan replayer capture task already exists")
}
exec := e.ctx.(sqlexec.SQLExecutor)
_, err = exec.ExecuteInternal(ctx1, fmt.Sprintf("insert into mysql.plan_replayer_task (sql_digest, plan_digest) values ('%s','%s')",
exec := e.ctx.(sqlexec.RestrictedSQLExecutor)
_, _, err = exec.ExecRestrictedSQL(ctx1, nil, fmt.Sprintf("insert into mysql.plan_replayer_task (sql_digest, plan_digest) values ('%s','%s')",
e.CaptureInfo.SQLDigest, e.CaptureInfo.PlanDigest))
if err != nil {
logutil.BgLogger().Warn("insert mysql.plan_replayer_status record failed",
Expand Down
7 changes: 0 additions & 7 deletions privilege/privileges/privileges.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,6 @@ func (p *UserPrivileges) RequestVerification(activeRoles []*auth.RoleIdentity, d
dbLowerName := strings.ToLower(db)
tblLowerName := strings.ToLower(table)

/// Skip check for plan replayer related table
if util.IsSysDB(dbLowerName) {
if util.IsPlanReplayerTable(tblLowerName) {
return true
}
}

// If SEM is enabled and the user does not have the RESTRICTED_TABLES_ADMIN privilege
// There are some hard rules which overwrite system tables and schemas as read-only at most.
semEnabled := sem.IsEnabled()
Expand Down
9 changes: 0 additions & 9 deletions util/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,6 @@ func IsSysDB(dbLowerName string) bool {
return dbLowerName == mysql.SystemDB
}

// IsPlanReplayerTable checks whether is plan replayer related table
func IsPlanReplayerTable(tblLowerName string) bool {
switch tblLowerName {
case "plan_replayer_status", "plan_replayer_task":
return true
}
return false
}

// IsSystemView is similar to IsMemOrSyDB, but does not include the mysql schema
func IsSystemView(dbLowerName string) bool {
switch dbLowerName {
Expand Down

0 comments on commit 6c426ed

Please sign in to comment.