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

chore: record exec plan and cu stats while query failed in mo 1.1 #15361

Merged
merged 4 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/frontend/cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ func Execute(ctx context.Context, ses *Session, proc *process.Process, stmtExec
logInfo(ses, ses.GetDebugString(), fmt.Sprintf("time of Exec.Run : %s", time.Since(runBegin).String()))
}

handleRet:
_ = stmtExec.RecordExecPlan(ctx)

handleRet:
stmtExec.SetStatus(err)
err2 = stmtExec.CommitOrRollbackTxn(ctx, ses)
if err2 != nil {
Expand Down
75 changes: 28 additions & 47 deletions pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3600,6 +3600,13 @@ func (mce *MysqlCmdExecutor) executeStmt(requestCtx context.Context,
return
}

defer func() {
// Serialize the execution plan as json
if cwft, ok := cw.(*TxnComputationWrapper); ok {
_ = cwft.RecordExecPlan(requestCtx)
}
}()

cmpBegin = time.Now()

if ret, err = cw.Compile(requestCtx, ses, ses.GetOutputCallback()); err != nil {
Expand Down Expand Up @@ -3691,13 +3698,6 @@ func (mce *MysqlCmdExecutor) executeStmt(requestCtx context.Context,
return
}

/*
Serialize the execution plan by json
*/
if cwft, ok := cw.(*TxnComputationWrapper); ok {
_ = cwft.RecordExecPlan(requestCtx)
}

} else {
columns, err = cw.GetColumns()
if err != nil {
Expand Down Expand Up @@ -3767,13 +3767,6 @@ func (mce *MysqlCmdExecutor) executeStmt(requestCtx context.Context,
if err != nil {
return
}

/*
Step 4: Serialize the execution plan by json
*/
if cwft, ok := cw.(*TxnComputationWrapper); ok {
_ = cwft.RecordExecPlan(requestCtx)
}
}

case *tree.ShowCreateTable, *tree.ShowCreateDatabase, *tree.ShowTables, *tree.ShowSequences, *tree.ShowDatabases, *tree.ShowColumns,
Expand Down Expand Up @@ -3857,12 +3850,6 @@ func (mce *MysqlCmdExecutor) executeStmt(requestCtx context.Context,
return
}

/*
Step 4: Serialize the execution plan by json
*/
if cwft, ok := cw.(*TxnComputationWrapper); ok {
_ = cwft.RecordExecPlan(requestCtx)
}
//just status, no result set
case *tree.CreateTable, *tree.DropTable, *tree.CreateDatabase, *tree.DropDatabase,
*tree.CreateIndex, *tree.DropIndex,
Expand Down Expand Up @@ -3933,12 +3920,6 @@ func (mce *MysqlCmdExecutor) executeStmt(requestCtx context.Context,

logDebug(ses, ses.GetDebugString(), fmt.Sprintf("time of SendResponse %s", time.Since(echoTime).String()))

/*
Step 4: Serialize the execution plan by json
*/
if cwft, ok := cw.(*TxnComputationWrapper); ok {
_ = cwft.RecordExecPlan(requestCtx)
}
case *tree.ExplainAnalyze:
explainColName := "QUERY PLAN"
columns, err = GetExplainColumns(requestCtx, explainColName)
Expand Down Expand Up @@ -4821,30 +4802,30 @@ func (h *marshalPlanHandler) Stats(ctx context.Context) (statsByte statistic.Sta
stats.BytesScan += bytes
}
}

statsInfo := statistic.StatsInfoFromContext(ctx)
if statsInfo != nil {
val := int64(statsByte.GetTimeConsumed()) +
int64(statsInfo.ParseDuration+
statsInfo.CompileDuration+
statsInfo.PlanDuration) - (statsInfo.IOAccessTimeConsumption + statsInfo.LockTimeConsumption)
if val < 0 {
logutil.Warnf(" negative cpu (%s) + statsInfo(%d + %d + %d - %d - %d) = %d",
uuid.UUID(h.stmt.StatementID).String(),
statsInfo.ParseDuration,
statsInfo.CompileDuration,
statsInfo.PlanDuration,
statsInfo.IOAccessTimeConsumption,
statsInfo.LockTimeConsumption,
val)
v2.GetTraceNegativeCUCounter("cpu").Inc()
} else {
statsByte.WithTimeConsumed(float64(val))
}
}
} else {
statsByte = statistic.DefaultStatsArray
}
statsInfo := statistic.StatsInfoFromContext(ctx)
if statsInfo != nil {
val := int64(statsByte.GetTimeConsumed()) +
int64(statsInfo.ParseDuration+
statsInfo.CompileDuration+
statsInfo.PlanDuration) - (statsInfo.IOAccessTimeConsumption + statsInfo.LockTimeConsumption)
if val < 0 {
logutil.Warnf(" negative cpu (%s) + statsInfo(%d + %d + %d - %d - %d) = %d",
uuid.UUID(h.stmt.StatementID).String(),
statsInfo.ParseDuration,
statsInfo.CompileDuration,
statsInfo.PlanDuration,
statsInfo.IOAccessTimeConsumption,
statsInfo.LockTimeConsumption,
val)
v2.GetTraceNegativeCUCounter("cpu").Inc()
} else {
statsByte.WithTimeConsumed(float64(val))
}
}

return
}

Expand Down
Loading