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

executor: support plan replayer capture <sql> <*> #39754

Merged
merged 8 commits into from
Dec 8, 2022
7 changes: 7 additions & 0 deletions domain/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ func (r *planReplayerDumpTaskStatus) GetRunningTaskStatusLen() int {
return len(r.runningTaskMu.runningTasks)
}

// CleanFinishedTaskStatus clean then finished tasks, only used for unit test
func (r *planReplayerDumpTaskStatus) CleanFinishedTaskStatus() {
r.finishedTaskMu.Lock()
defer r.finishedTaskMu.Unlock()
r.finishedTaskMu.finishedTask = map[PlanReplayerTaskKey]struct{}{}
}

// GetFinishedTaskStatusLen used for unit test
func (r *planReplayerDumpTaskStatus) GetFinishedTaskStatusLen() int {
r.finishedTaskMu.RLock()
Expand Down
19 changes: 19 additions & 0 deletions domain/plan_replayer_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ func TestPlanReplayerHandleDumpTask(t *testing.T) {
err = prHandle.CollectPlanReplayerTask()
require.NoError(t, err)
require.Len(t, prHandle.GetTasks(), 0)

// clean the task and register task
prHandle.GetTaskStatus().CleanFinishedTaskStatus()
tk.MustExec("delete from mysql.plan_replayer_task")
tk.MustExec("delete from mysql.plan_replayer_status")
tk.MustExec(fmt.Sprintf("insert into mysql.plan_replayer_task (sql_digest, plan_digest) values ('%v','%v');", sqlDigest, "*"))
err = prHandle.CollectPlanReplayerTask()
require.NoError(t, err)
require.Len(t, prHandle.GetTasks(), 1)
tk.MustQuery("select * from t;")
task = prHandle.DrainTask()
require.NotNil(t, task)
worker = prHandle.GetWorker()
success = worker.HandleTask(task)
require.True(t, success)
require.Equal(t, prHandle.GetTaskStatus().GetRunningTaskStatusLen(), 0)
require.Equal(t, prHandle.GetTaskStatus().GetFinishedTaskStatusLen(), 1)
// assert capture * task still remained
require.Len(t, prHandle.GetTasks(), 1)
}
8 changes: 5 additions & 3 deletions executor/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ func checkPlanReplayerCaptureTask(sctx sessionctx.Context, stmtNode ast.StmtNode
_, sqlDigest := sctx.GetSessionVars().StmtCtx.SQLDigest()
_, planDigest := getPlanDigest(sctx.GetSessionVars().StmtCtx)
for _, task := range tasks {
if task.SQLDigest == sqlDigest.String() && task.PlanDigest == planDigest.String() {
sendPlanReplayerDumpTask(sqlDigest.String(), planDigest.String(), sctx, stmtNode)
return
if task.SQLDigest == sqlDigest.String() {
if task.PlanDigest == "*" || task.PlanDigest == planDigest.String() {
sendPlanReplayerDumpTask(sqlDigest.String(), planDigest.String(), sctx, stmtNode)
return
}
}
}
}
Expand Down