Skip to content

Commit

Permalink
executor, session: fix ExecStmt.OriginText to use the actual original…
Browse files Browse the repository at this point in the history
… text
  • Loading branch information
b6g committed Nov 15, 2024
1 parent 91436e3 commit 1f63e26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (a *ExecStmt) PointGet(ctx context.Context) (*recordSet, error) {

// OriginText returns original statement as a string.
func (a *ExecStmt) OriginText() string {
return a.Text
return a.StmtNode.OriginalText()
}

// IsPrepared returns true if stmt is a prepare statement.
Expand Down Expand Up @@ -2067,7 +2067,7 @@ func (a *ExecStmt) GetTextToLog(keepHint bool) string {
} else if sensitiveStmt, ok := a.StmtNode.(ast.SensitiveStmtNode); ok {
sql = sensitiveStmt.SecureText()
} else {
sql = redact.String(rmode, sessVars.StmtCtx.OriginalSQL+sessVars.PlanCacheParams.String())
sql = redact.String(rmode, a.OriginText()+sessVars.PlanCacheParams.String())
}
return sql
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import (
"github.com/tikv/client-go/v2/oracle"
tikvutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func init() {
Expand Down Expand Up @@ -4139,7 +4140,8 @@ func logGeneralQuery(execStmt *executor.ExecStmt, s *session, isPrepared bool) {
if vars.EnableRedactLog != errors.RedactLogEnable {
query += redact.String(vars.EnableRedactLog, vars.PlanCacheParams.String())
}
logutil.GeneralLogger.Info("GENERAL_LOG",

fields := []zapcore.Field{
zap.Uint64("conn", vars.ConnectionID),
zap.String("session_alias", vars.SessionAlias),
zap.String("user", vars.User.LoginString()),
Expand All @@ -4150,7 +4152,12 @@ func logGeneralQuery(execStmt *executor.ExecStmt, s *session, isPrepared bool) {
zap.String("currentDB", vars.CurrentDB),
zap.Bool("isPessimistic", vars.TxnCtx.IsPessimistic),
zap.String("sessionTxnMode", vars.GetReadableTxnMode()),
zap.String("sql", query))
zap.String("sql", query),
}
if execStmt.OriginText() != execStmt.Text {
fields = append(fields, zap.String("sqlQuoted", strconv.Quote(query)))
}
logutil.GeneralLogger.Info("GENERAL_LOG", fields...)
}
}

Expand Down

0 comments on commit 1f63e26

Please sign in to comment.