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

Fix my sql process list truncated sql #2849

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Changes from 2 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
42 changes: 20 additions & 22 deletions sqle/server/auditplan/task_type_mysql_processlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,6 @@ func (at *MySQLProcessListTaskV2) Audit(sqls []*model.SQLManageRecord) (*AuditRe
return auditSQLs(sqls)
}

func (at *MySQLProcessListTaskV2) processListSQL(ap *AuditPlan) string {
sql := `
SELECT DISTINCT db,time,info
FROM information_schema.processlist
WHERE ID != connection_id() AND info != '' AND db NOT IN ('information_schema','performance_schema','mysql','sys')
%v
`
whereSqlMinSecond := ""
{
sqlMinSecond := ap.Params.GetParam(paramKeySQLMinSecond).Int()
if sqlMinSecond > 0 {
whereSqlMinSecond = fmt.Sprintf("AND TIME > %d", sqlMinSecond)
}
}
sql = fmt.Sprintf(sql, whereSqlMinSecond)
return sql
}

func (at *MySQLProcessListTaskV2) ExtractSQL(logger *logrus.Entry, ap *AuditPlan, persist *model.Storage) ([]*SQLV2, error) {
if ap.InstanceID == "" {
return nil, fmt.Errorf("instance is not configured")
Expand Down Expand Up @@ -99,17 +81,33 @@ func (at *MySQLProcessListTaskV2) ExtractSQL(logger *logrus.Entry, ap *AuditPlan
}
defer db.Db.Close()

res, err := db.Db.Query(at.processListSQL(ap))
// 查询 SHOW FULL PROCESSLIST
res, err := db.Db.Query("SHOW FULL PROCESSLIST")
if err != nil {
return nil, fmt.Errorf("show processlist failed, error: %v", err)
return nil, fmt.Errorf("SHOW FULL PROCESSLIST failed, error: %v", err)
}

if len(res) == 0 {
if len(res) <= 1 { // 仅有自己的连接
return nil, nil
}
cache := NewSQLV2Cache()
sqlMinSecond := ap.Params.GetParam(paramKeySQLMinSecond).Int()
for i := range res {
query := res[i]["info"].String
if sqlMinSecond > 0 {
queryTime, _ := strconv.Atoi(res[i]["Time"].String)
if sqlMinSecond > queryTime {
continue
littleniannian marked this conversation as resolved.
Show resolved Hide resolved
}
}
if res[i]["Info"].String == "" ||
littleniannian marked this conversation as resolved.
Show resolved Hide resolved
res[i]["Id"].String == db.Db.GetConnectionID() ||
res[i]["db"].String == "information_schema" ||
res[i]["db"].String == "performance_schema" ||
res[i]["db"].String == "mysql" ||
res[i]["db"].String == "sys" {
continue
}
query := res[i]["Info"].String
sqlV2 := &SQLV2{
Source: ap.Type,
SourceId: strconv.FormatUint(uint64(ap.InstanceAuditPlanId), 10),
Expand Down
Loading