diff --git a/mysql/mysql_gtid.go b/mysql/mysql_gtid.go index 151581f85..80287baf5 100644 --- a/mysql/mysql_gtid.go +++ b/mysql/mysql_gtid.go @@ -418,11 +418,25 @@ func (s *MysqlGTIDSet) Equal(o GTIDSet) bool { } func (s *MysqlGTIDSet) String() string { + // there is only one element in gtid set + if len(s.Sets) == 1 { + for _, set := range s.Sets { + return set.String() + } + } + + // sort multi set var buf bytes.Buffer - sep := "" + sets := make([]string, 0, len(s.Sets)) for _, set := range s.Sets { + sets = append(sets, set.String()) + } + sort.Strings(sets) + + sep := "" + for _, set := range sets { buf.WriteString(sep) - buf.WriteString(set.String()) + buf.WriteString(set) sep = "," }