-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: print arguments in execute statement in log files #7684
Conversation
/run-all-tests |
executor/prepared.go
Outdated
execStmt.UsingVars[i] = ast.NewValueExpr(val) | ||
expr := ast.NewValueExpr(val) | ||
execStmt.UsingVars[i] = expr | ||
str, err := expr.ToString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI failed because expr
is nil
/run-all-tests |
types/datum.go
Outdated
@@ -1501,6 +1501,8 @@ func (d *Datum) ToFloat64(sc *stmtctx.StatementContext) (float64, error) { | |||
// ToString gets the string representation of the datum. | |||
func (d *Datum) ToString() (string, error) { | |||
switch d.Kind() { | |||
case KindNull: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
types/datum.go
Outdated
case KindMysqlDecimal: | ||
return d.GetMysqlDecimal().String(), nil | ||
case KindMysqlDuration: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reordered this part to make it easier to find which kind has not been converted.
/run-all-tests |
/run-all-tests |
@jackysp |
@coocood , it is easy to compose the arguments string only for the general log and the debug log, but it is not esay for the slow log. |
/run-all-tests |
PTAL @coocood |
@@ -1060,3 +1063,104 @@ func (e *UnionExec) Close() error { | |||
e.resourcePools = nil | |||
return errors.Trace(e.baseExecutor.Close()) | |||
} | |||
|
|||
// ResetContextOfStmt resets the StmtContext and session variables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's moved or changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change at Line 1149.
IMHO, move a function and change it is a bad habit. That will makes a PR harder to read. |
LGTM |
session/session.go
Outdated
@@ -1418,7 +1418,7 @@ func logStmt(node ast.StmtNode, vars *variable.SessionVars) { | |||
|
|||
func logQuery(query string, vars *variable.SessionVars) { | |||
if atomic.LoadUint32(&variable.ProcessGeneralLog) != 0 && !vars.InRestrictedSQL { | |||
query = executor.QueryReplacer.Replace(query) | |||
query = executor.QueryReplacer.Replace(query) + vars.GetExecuteArgumentsInfo() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think put vars.GetExecuteArgumentsInfo()
to line 1422 is better. Reduce the processing of strings.
} else { | ||
str, err := v.ToString() | ||
if err != nil { | ||
terror.Log(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some details to this error log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has some details about it. Actually, it should not meet the error, just make the errcheck happy.
@@ -244,6 +238,9 @@ func (e *DeallocateExec) Next(ctx context.Context, chk *chunk.Chunk) error { | |||
// CompileExecutePreparedStmt compiles a session Execute command to a stmt.Statement. | |||
func CompileExecutePreparedStmt(ctx sessionctx.Context, ID uint32, args ...interface{}) (ast.Statement, error) { | |||
execStmt := &ast.ExecuteStmt{ExecID: ID} | |||
if err := ResetContextOfStmt(ctx, execStmt); err != nil { | |||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add the error trace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think no need now.
PTAL @zimulala |
1 similar comment
PTAL @zimulala |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…he prepared plan cache (pingcap#7956)
What problem does this PR solve?
The log of the
execute statement
looks likeWe don't know what the exact argument value is.
What is changed and how it works?
Append arguments info into log files.
Check List
Tests
For slow query log, general log and debug log:
Code changes
Side effects
Related changes
PTAL @coocood @shenli