Skip to content

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

fix: fix panic in fingerprint (#12391)

rebelice590c6e8ce2e9
diff --git a/backend/plugin/parser/mysql/fingerprint.go b/backend/plugin/parser/mysql/fingerprint.go
index 1a03d8cc42..26ec31baf6 100644
--- a/backend/plugin/parser/mysql/fingerprint.go
+++ b/backend/plugin/parser/mysql/fingerprint.go
@@ -140,6 +140,10 @@ func collapseUnion(query string) (string, error) {
}
if i == start+1 {
// The i-th part is not equal to the front part.
+ if i == len(parts)-1 {
+ // The i-th part is the sentinel node.
+ break
+ }
if _, err := buf.WriteString(separators[i-1]); err != nil {
return "", err
}
diff --git a/backend/plugin/parser/mysql/fingerprint_test.go b/backend/plugin/parser/mysql/fingerprint_test.go
index 2229dc330f..72efc8e1f3 100644
--- a/backend/plugin/parser/mysql/fingerprint_test.go
+++ b/backend/plugin/parser/mysql/fingerprint_test.go
@@ -11,6 +11,10 @@ func TestGetMySQLFingerprint(t *testing.T) {
stmt string
want string
}{
+ {
+ stmt: "SELECT * FROM `mytable` UNION SELECT a, b FROM `mytable`",
+ want: "select * from `mytable` union select a, b from `mytable`",
+ },
{
stmt: "-- this is comment\nSELECT * FROM `mytable`",
want: "select * from `mytable`",