Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync-diff-inspector: add sql-hint-use-index in config for automatically apply hint in check SQL #837

Merged
merged 32 commits into from
Mar 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove some code
joechenrh committed Jan 9, 2025
commit d6a68f28acdcaedbe2a661cd571c72c3284f20b5
1 change: 0 additions & 1 deletion pkg/diff/spliter_test.go
Original file line number Diff line number Diff line change
@@ -455,7 +455,6 @@ func createFakeResultForBucketSplit(mock sqlmock.Sqlmock, aRandomValues, bRandom
for i := 0; i < 5; i++ {
statsRows.AddRow("test", "test", "PRIMARY", 1, (i+1)*64, (i+1)*64, 1, fmt.Sprintf("(%d, %d)", i*64, i*12), fmt.Sprintf("(%d, %d)", (i+1)*64-1, (i+1)*12-1))
}

mock.ExpectQuery("SHOW STATS_BUCKETS").WillReturnRows(statsRows)

for i := 0; i < len(aRandomValues); i++ {
22 changes: 11 additions & 11 deletions sync_diff_inspector/splitter/random.go
Original file line number Diff line number Diff line change
@@ -203,7 +203,6 @@ func (s *RandomIterator) Close() {
}

// GetSplitFields returns fields to split chunks, order by pk, uk, index, columns.
// Return the columns, corresponding index name and error
func GetSplitFields(table *model.TableInfo, splitFields []string) ([]*model.ColumnInfo, error) {
colsMap := make(map[string]*model.ColumnInfo)

@@ -225,19 +224,20 @@ func GetSplitFields(table *model.TableInfo, splitFields []string) ([]*model.Colu
colsMap[col.Name.O] = col
}

// First try to get column from index
indices := dbutil.FindAllIndex(table)
NEXTINDEX:
for _, idx := range indices {
cols := make([]*model.ColumnInfo, 0, len(table.Columns))
for _, icol := range idx.Columns {
col := colsMap[icol.Name.O]
if col.Hidden {
continue NEXTINDEX
if len(indices) != 0 {
NEXTINDEX:
for _, idx := range indices {
cols := make([]*model.ColumnInfo, 0, len(table.Columns))
for _, icol := range idx.Columns {
col := colsMap[icol.Name.O]
if col.Hidden {
continue NEXTINDEX
}
cols = append(cols, col)
}
cols = append(cols, col)
return cols, nil
}
return cols, nil
}

for _, col := range table.Columns {
3 changes: 1 addition & 2 deletions sync_diff_inspector/utils/utils_test.go
Original file line number Diff line number Diff line change
@@ -269,8 +269,7 @@ func TestGetCountAndMd5Checksum(t *testing.T) {
tableInfo, err := dbutil.GetTableInfoBySQL(createTableSQL, parser.New())
require.NoError(t, err)

mock.ExpectQuery("SELECT COUNT.*FROM `test_schema`\\.`test_table`").WithArgs("123", "234").WillReturnRows(sqlmock.NewRows([]string{"CNT", "CHECKSUM"}).AddRow(123, 456))

mock.ExpectQuery("SELECT COUNT.*FROM `test_schema`\\.`test_table` WHERE \\[23 45\\].*").WithArgs("123", "234").WillReturnRows(sqlmock.NewRows([]string{"CNT", "CHECKSUM"}).AddRow(123, 456))
count, checksum, err := GetCountAndMd5Checksum(ctx, conn, "test_schema", "test_table", tableInfo, "[23 45]", "", []interface{}{"123", "234"})
require.NoError(t, err)
require.Equal(t, count, int64(123))