-
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
session: add session variable to log query string. #5633
Conversation
Use an atomic global variable to control the switch to log query. And the query is logged before execution.
@shenli @tiancaiamao PTAL |
sessionctx/variable/sysvar.go
Outdated
@@ -620,6 +620,7 @@ var defaultSysVars = []*SysVar{ | |||
{ScopeSession, TiDBDMLBatchSize, strconv.Itoa(DefDMLBatchSize)}, | |||
{ScopeSession, TiDBCurrentTS, strconv.Itoa(DefCurretTS)}, | |||
{ScopeSession, TiDBMaxChunkSize, strconv.Itoa(DefMaxChunkSize)}, | |||
{ScopeSession, TiDBLogQuery, strconv.Itoa(DefLogQuery)}, |
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.
This is a session scope variable. How could the users enable this feature? Most of them do not know it.
I think we could make it a global scope variable or a configuration of the server.
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.
This should only be used temporarily and for a single tidb-server.
Make it a configuration require a restart which is inconvenient.
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 we should add a comment here. For this variable is a 'server scope' variable instead of a 'session scope' variable.
@shenli PTAL |
Could we use the same variable with MySQL general log? https://dev.mysql.com/doc/refman/5.7/en/query-log.html |
@shenli |
session.go
Outdated
} | ||
|
||
func logQuery(query string, vars *variable.SessionVars) { | ||
if atomic.LoadUint32(&variable.ProcessLogQuery) != 0 && !vars.InRestrictedSQL { |
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.
s/0/variable.DefLogQuery
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 default may change to other values, but 0 is always 0.
LGTM |
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
/run-all-tests |
Use an atomic global variable to control the switch to log query.
And the query is logged before execution.