From 99cb7c3d6c89a1c70c9fdeebcfc7677b1a456eb8 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Fri, 24 Nov 2023 17:23:45 +0800 Subject: [PATCH] session: set request source to type of the prepared stmt for execute stmt (#46348) (#46353) close pingcap/tidb#46349 --- session/session.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/session/session.go b/session/session.go index f8086e51178ab..19956baeed535 100644 --- a/session/session.go +++ b/session/session.go @@ -2197,7 +2197,16 @@ func (s *session) ExecuteStmt(ctx context.Context, stmtNode ast.StmtNode) (sqlex } }) - stmtLabel := ast.GetStmtLabel(stmtNode) + var stmtLabel string + if execStmt, ok := stmtNode.(*ast.ExecuteStmt); ok { + prepareStmt, err := plannercore.GetPreparedStmt(execStmt, s.sessionVars) + if err == nil && prepareStmt.PreparedAst != nil { + stmtLabel = ast.GetStmtLabel(prepareStmt.PreparedAst.Stmt) + } + } + if stmtLabel == "" { + stmtLabel = ast.GetStmtLabel(stmtNode) + } s.setRequestSource(ctx, stmtLabel, stmtNode) // Transform abstract syntax tree to a physical plan(stored in executor.ExecStmt).