Skip to content

Commit

Permalink
sync_diff_inspector: Table range should be FALSE when all the columns…
Browse files Browse the repository at this point in the history
… are equal (#614)

close #615
  • Loading branch information
Leavrth authored Apr 28, 2022
1 parent 748edcb commit b870b1b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sync_diff_inspector/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ func (c *Range) ToString(collation string) (string, []interface{}) {
sameArgs = append(sameArgs, bound.Lower)
}

if i == len(c.Bounds) && i > 0 {
// All the columns are equal in bounds, should return FALSE!
return "FALSE", nil
}

for ; i < len(c.Bounds); i++ {
bound := c.Bounds[i]
lowerSymbol := gt
Expand Down
34 changes: 34 additions & 0 deletions sync_diff_inspector/chunk/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,40 @@ func TestChunkToString(t *testing.T) {
}
require.Equal(t, chunk.String(), `{"index":null,"type":0,"bounds":[{"column":"a","lower":"1","upper":"1","has-lower":false,"has-upper":false},{"column":"b","lower":"3","upper":"4","has-lower":false,"has-upper":false},{"column":"c","lower":"5","upper":"6","has-lower":false,"has-upper":false}],"is-first":false,"is-last":false,"where":"","args":null}`)
require.Equal(t, chunk.ToMeta(), "range in sequence: Full")

// all equal
chunk = &Range{
Bounds: []*Bound{
{
Column: "a",
Lower: "1",
Upper: "1",
HasLower: true,
HasUpper: true,
}, {
Column: "b",
Lower: "3",
Upper: "3",
HasLower: true,
HasUpper: true,
}, {
Column: "c",
Lower: "6",
Upper: "6",
HasLower: true,
HasUpper: true,
},
},
}
conditions, args = chunk.ToString("")
require.Equal(t, conditions, "FALSE")
expectArgs = []string{}
for i, arg := range args {
require.Equal(t, arg, expectArgs[i])
}
require.Equal(t, chunk.String(), `{"index":null,"type":0,"bounds":[{"column":"a","lower":"1","upper":"1","has-lower":true,"has-upper":true},{"column":"b","lower":"3","upper":"3","has-lower":true,"has-upper":true},{"column":"c","lower":"6","upper":"6","has-lower":true,"has-upper":true}],"is-first":false,"is-last":false,"where":"","args":null}`)
require.Equal(t, chunk.ToMeta(), "range in sequence: (1,3,6) < (a,b,c) <= (1,3,6)")

}

func TestChunkInit(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion sync_diff_inspector/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,8 @@ func (df *Diff) binSearch(ctx context.Context, targetSource source.Source, table
zap.Int64("count1", count1),
zap.Int64("count2", count2))

if !isEqual1 && !isEqual2 {
// If there is a count zero, we think the range is very small.
if (!isEqual1 && !isEqual2) || (count1 == 0 || count2 == 0) {
return tableRange, nil
} else if !isEqual1 {
c, err := df.binSearch(ctx, targetSource, tableRange1, count1, tableDiff, indexColumns)
Expand Down

0 comments on commit b870b1b

Please sign in to comment.