Skip to content

Commit 49a4288

Browse files
authored
Merge branch 'master' into execMultiple
2 parents 3e95519 + 3566d1e commit 49a4288

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

mysql/const.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,8 @@ const (
167167
MySQLFlavor = "mysql"
168168
MariaDBFlavor = "mariadb"
169169
)
170+
171+
const (
172+
MYSQL_OPTION_MULTI_STATEMENTS_ON = iota
173+
MYSQL_OPTION_MULTI_STATEMENTS_OFF
174+
)

mysql/mysql_gtid.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/binary"
66
"fmt"
77
"io"
8+
"math"
89
"sort"
910
"strconv"
1011
"strings"
@@ -234,11 +235,15 @@ func (s *UUIDSet) MinusInterval(in IntervalSlice) {
234235
i, j := 0, 0
235236
var minuend Interval
236237
var subtrahend Interval
237-
for j < len(in) && i < len(s.Intervals) {
238+
for i < len(s.Intervals) {
238239
if minuend.Stop != s.Intervals[i].Stop { // `i` changed?
239240
minuend = s.Intervals[i]
240241
}
241-
subtrahend = in[j]
242+
if j < len(in) {
243+
subtrahend = in[j]
244+
} else {
245+
subtrahend = Interval{math.MaxInt64, math.MaxInt64}
246+
}
242247

243248
if minuend.Stop <= subtrahend.Start {
244249
// no overlapping
@@ -248,33 +253,25 @@ func (s *UUIDSet) MinusInterval(in IntervalSlice) {
248253
// no overlapping
249254
j++
250255
} else {
251-
if minuend.Start < subtrahend.Start && minuend.Stop < subtrahend.Stop {
256+
if minuend.Start < subtrahend.Start && minuend.Stop <= subtrahend.Stop {
252257
n = append(n, Interval{minuend.Start, subtrahend.Start})
253258
i++
254-
} else if minuend.Start > subtrahend.Start && minuend.Stop > subtrahend.Stop {
259+
} else if minuend.Start >= subtrahend.Start && minuend.Stop > subtrahend.Stop {
255260
minuend = Interval{subtrahend.Stop, minuend.Stop}
256261
j++
257262
} else if minuend.Start >= subtrahend.Start && minuend.Stop <= subtrahend.Stop {
258263
// minuend is completely removed
259264
i++
260-
} else {
265+
} else if minuend.Start < subtrahend.Start && minuend.Stop > subtrahend.Stop {
261266
n = append(n, Interval{minuend.Start, subtrahend.Start})
262267
minuend = Interval{subtrahend.Stop, minuend.Stop}
263268
j++
269+
} else {
270+
panic("should never be here")
264271
}
265272
}
266273
}
267274

268-
lastSub := in[len(in)-1]
269-
for ; i < len(s.Intervals); i++ {
270-
minuend = s.Intervals[i]
271-
if minuend.Start < lastSub.Stop {
272-
n = append(n, Interval{lastSub.Stop, minuend.Stop})
273-
} else {
274-
n = append(n, s.Intervals[i])
275-
}
276-
}
277-
278275
s.Intervals = n.Normalize()
279276
}
280277

mysql/mysql_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func (t *mysqlTestSuite) TestMysqlGTIDMinus(c *check.C) {
177177
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-57:60-90", "3E11FA47-71CA-11E1-9E33-C80AA9429562:23", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20-22:24-57:60-90"},
178178
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-57:60-90", "3E11FA47-71CA-11E1-9E33-C80AA9429562:22-70", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20-21:71-90"},
179179
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:28-57", "3E11FA47-71CA-11E1-9E33-C80AA9429562:28-57", ""},
180+
{"3E11FA47-71CA-11E1-9E33-C80AA9429562:20-21", "3E11FA47-71CA-11E1-9E33-C80AA9429562:21", "3E11FA47-71CA-11E1-9E33-C80AA9429562:20"},
181+
{"582A11ED-786C-11EC-ACCC-E0356662B76E:1-209692", "582A11ED-786C-11EC-ACCC-E0356662B76E:1-146519", "582A11ED-786C-11EC-ACCC-E0356662B76E:146520-209692"},
182+
{"582A11ED-786C-11EC-ACCC-E0356662B76E:1-209692", "582A11ED-786C-11EC-ACCC-E0356662B76E:2-146519", "582A11ED-786C-11EC-ACCC-E0356662B76E:1:146520-209692"},
180183
}
181184

182185
for _, tc := range testCases {

0 commit comments

Comments
 (0)