Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: truncate string for UTF-8 (#9588)

rebelice2ec2f483e385
diff --git a/backend/plugin/db/mysql/sync.go b/backend/plugin/db/mysql/sync.go
index a27af3b4f0..29a070cec8 100644
--- a/backend/plugin/db/mysql/sync.go
+++ b/backend/plugin/db/mysql/sync.go
@@ -640,10 +640,10 @@ func analyzeSlowLog(engine storepb.Engine, logs []*slowLog) (map[string]*storepb
return nil, errors.Wrapf(err, "get sql fingerprint failed, sql: %s", log.details.SqlText)
}
if len(fingerprint) > db.SlowQueryMaxLen {
- fingerprint = fingerprint[:db.SlowQueryMaxLen]
+ fingerprint, _ = common.TruncateString(fingerprint, db.SlowQueryMaxLen)
}
if len(log.details.SqlText) > db.SlowQueryMaxLen {
- log.details.SqlText = log.details.SqlText[:db.SlowQueryMaxLen]
+ log.details.SqlText, _ = common.TruncateString(log.details.SqlText, db.SlowQueryMaxLen)
}
for _, db := range databaseList {
diff --git a/backend/plugin/db/pg/sync.go b/backend/plugin/db/pg/sync.go
index 67e35d1030..83573c079a 100644
--- a/backend/plugin/db/pg/sync.go
+++ b/backend/plugin/db/pg/sync.go
@@ -836,7 +836,7 @@ func (driver *Driver) SyncSlowQuery(ctx context.Context, _ time.Time) (map[strin
return nil, err
}
if len(fingerprint) > db.SlowQueryMaxLen {
- fingerprint = fingerprint[:db.SlowQueryMaxLen]
+ fingerprint, _ = common.TruncateString(fingerprint, db.SlowQueryMaxLen)
}
item := storepb.SlowQueryStatisticsItem{
SqlFingerprint: fingerprint,