From afa6ffb846ef94bddba669216fca6c0dc99ef5ab Mon Sep 17 00:00:00 2001 From: Matt Lord Date: Thu, 9 Jan 2025 16:24:18 -0500 Subject: [PATCH] Fix unit tests Signed-off-by: Matt Lord --- .../tabletmanager/vdiff/engine_test.go | 8 +- .../tabletmanager/vdiff/framework_test.go | 10 + .../vdiff/workflow_differ_test.go | 367 ++++++++++-------- 3 files changed, 213 insertions(+), 172 deletions(-) diff --git a/go/vt/vttablet/tabletmanager/vdiff/engine_test.go b/go/vt/vttablet/tabletmanager/vdiff/engine_test.go index 61d713a8e58..8849bcfea93 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/engine_test.go +++ b/go/vt/vttablet/tabletmanager/vdiff/engine_test.go @@ -139,7 +139,7 @@ func TestVDiff(t *testing.T) { "lastpk|mismatch|report", "varbinary|int64|json", ), - `fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}|0|{}`, + `source:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}} target:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}}|0|{}`, ), nil) vdenv.dbClient.ExpectRequest(fmt.Sprintf("select column_name as column_name, collation_name as collation_name from information_schema.columns where table_schema='%s' and table_name='t1' and column_name in ('c1')", vdiffDBName), sqltypes.MakeTestResult(sqltypes.MakeTestFields( "collation_name", @@ -159,7 +159,7 @@ func TestVDiff(t *testing.T) { "lastpk|mismatch|report", "varbinary|int64|json", ), - `fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}|0|{"TableName": "t1", "MatchingRows": 1, "ProcessedRows": 1, "MismatchedRows": 0, "ExtraRowsSource": 0, "ExtraRowsTarget": 0}`, + `source:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}} target:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}}|0|{}`, ), nil) vdenv.dbClient.ExpectRequest("update _vt.vdiff_table set table_rows = 1 where vdiff_id = 1 and table_name = 't1'", singleRowAffected, nil) @@ -169,7 +169,7 @@ func TestVDiff(t *testing.T) { "lastpk|mismatch|report", "varbinary|int64|json", ), - `fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}|0|{"TableName": "t1", "MatchingRows": 1, "ProcessedRows": 1, "MismatchedRows": 0, "ExtraRowsSource": 0, "ExtraRowsTarget": 0}`, + `source:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}} target:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}}|0|{}`, ), nil) vdenv.dbClient.ExpectRequest("update _vt.vdiff_table set state = 'started' where vdiff_id = 1 and table_name = 't1'", singleRowAffected, nil) vdenv.dbClient.ExpectRequest(`insert into _vt.vdiff_log(vdiff_id, message) values (1, 'started: table \'t1\'')`, singleRowAffected, nil) @@ -185,7 +185,7 @@ func TestVDiff(t *testing.T) { "lastpk|mismatch|report", "varbinary|int64|json", ), - `fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}|0|{}`, + `source:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}} target:{fields:{name:"c1" type:INT64 table:"t1" org_table:"t1" database:"vt_customer" org_name:"c1" column_length:20 charset:63 flags:53251} rows:{lengths:1 values:"1"}}|0|{}`, ), nil) vdenv.dbClient.ExpectRequest(`update _vt.vdiff_table set rows_compared = 0, report = '{"TableName":"t1","ProcessedRows":0,"MatchingRows":0,"MismatchedRows":0,"ExtraRowsSource":0,"ExtraRowsTarget":0}' where vdiff_id = 1 and table_name = 't1'`, singleRowAffected, nil) vdenv.dbClient.ExpectRequest(`update _vt.vdiff_table set state = 'completed', rows_compared = 0, report = '{"TableName":"t1","ProcessedRows":0,"MatchingRows":0,"MismatchedRows":0,"ExtraRowsSource":0,"ExtraRowsTarget":0}' where vdiff_id = 1 and table_name = 't1'`, singleRowAffected, nil) diff --git a/go/vt/vttablet/tabletmanager/vdiff/framework_test.go b/go/vt/vttablet/tabletmanager/vdiff/framework_test.go index 7d4cdb78c20..563741fcd23 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/framework_test.go +++ b/go/vt/vttablet/tabletmanager/vdiff/framework_test.go @@ -678,5 +678,15 @@ func (tvde *testVDiffEnv) createController(t *testing.T, id int) *controller { tvde.dbClient.ExpectRequest(fmt.Sprintf("select * from _vt.vdiff where id = %d", id), noResults, nil) ct, err := newController(context.Background(), controllerQR.Named().Row(), tvde.dbClientFactory, tstenv.TopoServ, tvde.vde, tvde.opts) require.NoError(t, err) + ct.sources = map[string]*migrationSource{ + tstenv.ShardName: { + vrID: 1, + shardStreamer: &shardStreamer{ + tablet: tvde.vde.thisTablet, + shard: tstenv.ShardName, + }, + }, + } + ct.sourceKeyspace = tstenv.KeyspaceName return ct } diff --git a/go/vt/vttablet/tabletmanager/vdiff/workflow_differ_test.go b/go/vt/vttablet/tabletmanager/vdiff/workflow_differ_test.go index c51b6fdf281..547341e192e 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/workflow_differ_test.go +++ b/go/vt/vttablet/tabletmanager/vdiff/workflow_differ_test.go @@ -51,6 +51,16 @@ func TestBuildPlanSuccess(t *testing.T) { vdiffenv.dbClient.ExpectRequest("select * from _vt.vdiff where id = 1", noResults, nil) ct, err := newController(context.Background(), controllerQR.Named().Row(), vdiffenv.dbClientFactory, tstenv.TopoServ, vdiffenv.vde, vdiffenv.opts) require.NoError(t, err) + ct.sources = map[string]*migrationSource{ + tstenv.ShardName: { + vrID: 1, + shardStreamer: &shardStreamer{ + tablet: vdenv.vde.thisTablet, + shard: tstenv.ShardName, + }, + }, + } + ct.sourceKeyspace = tstenv.KeyspaceName testcases := []struct { input *binlogdatapb.Rule @@ -63,14 +73,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 order by c1 asc", - targetQuery: "select c1, c2 from t1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 order by c1 asc", + targetQuery: "select c1, c2 from t1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -83,14 +94,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 where in_keyrange('-80') order by c1 asc", - targetQuery: "select c1, c2 from t1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 where in_keyrange('-80') order by c1 asc", + targetQuery: "select c1, c2 from t1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -103,14 +115,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 order by c1 asc", - targetQuery: "select c1, c2 from t1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 order by c1 asc", + targetQuery: "select c1, c2 from t1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -123,14 +136,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c2, c1 from t1 order by c1 asc", - targetQuery: "select c2, c1 from t1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{1}, - selectPks: []int{1}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c2, c1 from t1 order by c1 asc", + targetQuery: "select c2, c1 from t1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{1}, + sourcePkCols: []int{0}, + selectPks: []int{1}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -143,14 +157,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c0 as c1, c2 from t2 order by c1 asc", - targetQuery: "select c1, c2 from t1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c0 as c1, c2 from t2 order by c1 asc", + targetQuery: "select c1, c2 from t1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -164,14 +179,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "nonpktext", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["nonpktext"]], - sourceQuery: "select c1, textcol from nonpktext order by c1 asc", - targetQuery: "select c1, textcol from nonpktext order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "textcol"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["nonpktext"]], + sourceQuery: "select c1, textcol from nonpktext order by c1 asc", + targetQuery: "select c1, textcol from nonpktext order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "textcol"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -185,14 +201,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "nonpktext", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["nonpktext"]], - sourceQuery: "select textcol, c1 from nonpktext order by c1 asc", - targetQuery: "select textcol, c1 from nonpktext order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "textcol"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{1}, - selectPks: []int{1}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["nonpktext"]], + sourceQuery: "select textcol, c1 from nonpktext order by c1 asc", + targetQuery: "select textcol, c1 from nonpktext order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "textcol"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{1}, + sourcePkCols: []int{0}, + selectPks: []int{1}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -206,14 +223,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "pktext", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["pktext"]], - sourceQuery: "select textcol, c2 from pktext order by textcol asc", - targetQuery: "select textcol, c2 from pktext order by textcol asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["pktext"]], + sourceQuery: "select textcol, c2 from pktext order by textcol asc", + targetQuery: "select textcol, c2 from pktext order by textcol asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, + pkCols: []int{0}, + sourcePkCols: []int{}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("textcol")}, Direction: sqlparser.AscOrder, @@ -227,14 +245,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "pktext", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["pktext"]], - sourceQuery: "select c2, textcol from pktext order by textcol asc", - targetQuery: "select c2, textcol from pktext order by textcol asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, - comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, - pkCols: []int{1}, - selectPks: []int{1}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["pktext"]], + sourceQuery: "select c2, textcol from pktext order by textcol asc", + targetQuery: "select c2, textcol from pktext order by textcol asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, + comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, + pkCols: []int{1}, + sourcePkCols: []int{}, + selectPks: []int{1}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("textcol")}, Direction: sqlparser.AscOrder, @@ -248,14 +267,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "nopk", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["nopk"]], - sourceQuery: "select c1, c2, c3 from nopk order by c1 asc, c2 asc, c3 asc", - targetQuery: "select c1, c2, c3 from nopk order by c1 asc, c2 asc, c3 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, - pkCols: []int{0, 1, 2}, - selectPks: []int{0, 1, 2}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["nopk"]], + sourceQuery: "select c1, c2, c3 from nopk order by c1 asc, c2 asc, c3 asc", + targetQuery: "select c1, c2, c3 from nopk order by c1 asc, c2 asc, c3 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, + pkCols: []int{0, 1, 2}, + sourcePkCols: []int{0}, + selectPks: []int{0, 1, 2}, orderBy: sqlparser.OrderBy{ &sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, @@ -279,14 +299,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "nopkwithpke", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["nopkwithpke"]], - sourceQuery: "select c1, c2, c3 from nopkwithpke order by c3 asc", - targetQuery: "select c1, c2, c3 from nopkwithpke order by c3 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, - comparePKs: []compareColInfo{{2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, - pkCols: []int{2}, - selectPks: []int{2}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["nopkwithpke"]], + sourceQuery: "select c1, c2, c3 from nopkwithpke order by c3 asc", + targetQuery: "select c1, c2, c3 from nopkwithpke order by c3 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, + comparePKs: []compareColInfo{{2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c3"}}, + pkCols: []int{2}, + sourcePkCols: []int{}, + selectPks: []int{2}, orderBy: sqlparser.OrderBy{ &sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c3")}, @@ -302,14 +323,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "pktext", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["pktext"]], - sourceQuery: "select c2, a + b as textcol from pktext order by textcol asc", - targetQuery: "select c2, textcol from pktext order by textcol asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, - comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, - pkCols: []int{1}, - selectPks: []int{1}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["pktext"]], + sourceQuery: "select c2, a + b as textcol from pktext order by textcol asc", + targetQuery: "select c2, textcol from pktext order by textcol asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, + comparePKs: []compareColInfo{{1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "textcol"}}, + pkCols: []int{1}, + sourcePkCols: []int{}, + selectPks: []int{1}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("textcol")}, Direction: sqlparser.AscOrder, @@ -322,14 +344,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "multipk", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["multipk"]], - sourceQuery: "select c1, c2 from multipk order by c1 asc, c2 asc", - targetQuery: "select c1, c2 from multipk order by c1 asc, c2 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}}, - pkCols: []int{0, 1}, - selectPks: []int{0, 1}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["multipk"]], + sourceQuery: "select c1, c2 from multipk order by c1 asc, c2 asc", + targetQuery: "select c1, c2 from multipk order by c1 asc, c2 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c2"}}, + pkCols: []int{0, 1}, + sourcePkCols: []int{0}, + selectPks: []int{0, 1}, orderBy: sqlparser.OrderBy{ &sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, @@ -349,14 +372,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 where in_keyrange('-80') order by c1 asc", - targetQuery: "select c1, c2 from t1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 where in_keyrange('-80') order by c1 asc", + targetQuery: "select c1, c2 from t1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -370,14 +394,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 where c2 = 2 and in_keyrange('-80') order by c1 asc", - targetQuery: "select c1, c2 from t1 where c2 = 2 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 where c2 = 2 and in_keyrange('-80') order by c1 asc", + targetQuery: "select c1, c2 from t1 where c2 = 2 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -391,14 +416,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 where in_keyrange('-80') and c2 = 2 order by c1 asc", - targetQuery: "select c1, c2 from t1 where c2 = 2 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 where in_keyrange('-80') and c2 = 2 order by c1 asc", + targetQuery: "select c1, c2 from t1 where c2 = 2 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -412,14 +438,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 where c2 = 2 and c1 = 1 and in_keyrange('-80') order by c1 asc", - targetQuery: "select c1, c2 from t1 where c2 = 2 and c1 = 1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 where c2 = 2 and c1 = 1 and in_keyrange('-80') order by c1 asc", + targetQuery: "select c1, c2 from t1 where c2 = 2 and c1 = 1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -433,14 +460,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 where c2 = 2 and in_keyrange('-80') order by c1 asc", - targetQuery: "select c1, c2 from t1 where c2 = 2 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 where c2 = 2 and in_keyrange('-80') order by c1 asc", + targetQuery: "select c1, c2 from t1 where c2 = 2 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -454,14 +482,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "t1", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["t1"]], - sourceQuery: "select c1, c2 from t1 group by c1 order by c1 asc", - targetQuery: "select c1, c2 from t1 order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["t1"]], + sourceQuery: "select c1, c2 from t1 group by c1 order by c1 asc", + targetQuery: "select c1, c2 from t1 order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -475,14 +504,15 @@ func TestBuildPlanSuccess(t *testing.T) { }, table: "aggr", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["aggr"]], - sourceQuery: "select c1, c2, count(*) as c3, sum(c4) as c4 from t1 group by c1 order by c1 asc", - targetQuery: "select c1, c2, c3, c4 from aggr order by c1 asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c3"}, {3, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c4"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["aggr"]], + sourceQuery: "select c1, c2, count(*) as c3, sum(c4) as c4 from t1 group by c1 order by c1 asc", + targetQuery: "select c1, c2, c3, c4 from aggr order by c1 asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c2"}, {2, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c3"}, {3, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "c4"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "c1"}}, + pkCols: []int{0}, + sourcePkCols: []int{0}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("c1")}, Direction: sqlparser.AscOrder, @@ -500,14 +530,15 @@ func TestBuildPlanSuccess(t *testing.T) { sourceTimeZone: "US/Pacific", table: "datze", tablePlan: &tablePlan{ - dbName: vdiffDBName, - table: testSchema.TableDefinitions[tableDefMap["datze"]], - sourceQuery: "select id, dt from datze order by id asc", - targetQuery: "select id, convert_tz(dt, 'UTC', 'US/Pacific') as dt from datze order by id asc", - compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "id"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "dt"}}, - comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "id"}}, - pkCols: []int{0}, - selectPks: []int{0}, + dbName: vdiffDBName, + table: testSchema.TableDefinitions[tableDefMap["datze"]], + sourceQuery: "select id, dt from datze order by id asc", + targetQuery: "select id, convert_tz(dt, 'UTC', 'US/Pacific') as dt from datze order by id asc", + compareCols: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "id"}, {1, collations.MySQL8().LookupByName(sqltypes.NULL.String()), false, "dt"}}, + comparePKs: []compareColInfo{{0, collations.MySQL8().LookupByName(sqltypes.NULL.String()), true, "id"}}, + pkCols: []int{0}, + sourcePkCols: []int{}, + selectPks: []int{0}, orderBy: sqlparser.OrderBy{&sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("id")}, Direction: sqlparser.AscOrder,