diff --git a/sync_diff_inspector/chunk/chunk.go b/sync_diff_inspector/chunk/chunk.go index d266d3bd2..e971df8cd 100644 --- a/sync_diff_inspector/chunk/chunk.go +++ b/sync_diff_inspector/chunk/chunk.go @@ -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 diff --git a/sync_diff_inspector/chunk/chunk_test.go b/sync_diff_inspector/chunk/chunk_test.go index 28b8fe69a..b5d62dd94 100644 --- a/sync_diff_inspector/chunk/chunk_test.go +++ b/sync_diff_inspector/chunk/chunk_test.go @@ -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) { diff --git a/sync_diff_inspector/diff.go b/sync_diff_inspector/diff.go index 90606de55..71bfe7d63 100644 --- a/sync_diff_inspector/diff.go +++ b/sync_diff_inspector/diff.go @@ -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)