diff --git a/go/test/endtoend/preparestmt/stmt_methods_test.go b/go/test/endtoend/preparestmt/stmt_methods_test.go index 8b38b717425..ae60de79414 100644 --- a/go/test/endtoend/preparestmt/stmt_methods_test.go +++ b/go/test/endtoend/preparestmt/stmt_methods_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/vt/vtgate/engine" ) @@ -564,13 +565,25 @@ func validateJoinSpecializedPlan(t *testing.T, p map[string]any) { func validateBaselineErrSpecializedPlan(t *testing.T, p map[string]any) { t.Helper() + + vtgateVer, err := cluster.GetMajorVersion("vtgate") + require.NoError(t, err) + + // v24+ uses the following error message due to the work in: + // https://github.com/vitessio/vitess/pull/18903 + expectedErr := "VT12001: unsupported: window functions are only supported for single-shard queries" + if vtgateVer < 24 { + // v23 and earlier uses the old error which reflected the limitation before that work. + expectedErr = "VT12001: unsupported: OVER CLAUSE with sharded keyspace" + } + plan, exist := p["Instructions"] require.True(t, exist, "plan Instructions not found") pm, ok := plan.(map[string]any) require.True(t, ok, "plan is not of type map[string]any") require.EqualValues(t, "PlanSwitcher", pm["OperatorType"]) - require.EqualValues(t, "VT12001: unsupported: OVER CLAUSE with sharded keyspace", pm["BaselineErr"]) + require.EqualValues(t, expectedErr, pm["BaselineErr"]) pd, err := engine.PrimitiveDescriptionFromMap(plan.(map[string]any)) require.NoError(t, err) diff --git a/go/vt/vttablet/tabletmanager/vdiff/table_differ.go b/go/vt/vttablet/tabletmanager/vdiff/table_differ.go index f62bd734fb8..f63fced008d 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/table_differ.go +++ b/go/vt/vttablet/tabletmanager/vdiff/table_differ.go @@ -944,6 +944,13 @@ func (td *tableDiffer) getSourcePKCols() error { return vterrors.Wrapf(err, "failed to get the schema for table %s from source tablet %s", td.table.Name, topoproto.TabletAliasString(sourceTablet.Tablet.Alias)) } + if len(sourceSchema.TableDefinitions) == 0 { + // The table no longer exists on the source. Any rows that exist on the target will be + // reported as extra rows. + log.Warningf("The %s table was not found on source tablet %s during VDiff for the %s workflow; any rows on the target will be reported as extra", + td.table.Name, topoproto.TabletAliasString(sourceTablet.Tablet.Alias), td.wd.ct.workflow) + return nil + } sourceTable := sourceSchema.TableDefinitions[0] if len(sourceTable.PrimaryKeyColumns) == 0 { // We use the columns from a PKE if there is one. diff --git a/go/vt/vttablet/tabletmanager/vdiff/table_differ_test.go b/go/vt/vttablet/tabletmanager/vdiff/table_differ_test.go index 03ba218cd66..2ed23168235 100644 --- a/go/vt/vttablet/tabletmanager/vdiff/table_differ_test.go +++ b/go/vt/vttablet/tabletmanager/vdiff/table_differ_test.go @@ -129,3 +129,35 @@ func TestUpdateTableProgress(t *testing.T) { }) } } + +func TestGetSourcePKCols_TableDroppedOnSource(t *testing.T) { + tvde := newTestVDiffEnv(t) + defer tvde.close() + + ct := tvde.createController(t, 1) + + table := &tabletmanagerdatapb.TableDefinition{ + Name: "dropped_table", + Columns: []string{"c1", "c2"}, + PrimaryKeyColumns: []string{"c1"}, + Fields: sqltypes.MakeTestFields("c1|c2", "int64|varchar"), + } + + tvde.tmc.schema = &tabletmanagerdatapb.SchemaDefinition{ + TableDefinitions: []*tabletmanagerdatapb.TableDefinition{}, + } + + td := &tableDiffer{ + wd: &workflowDiffer{ + ct: ct, + }, + table: table, + tablePlan: &tablePlan{ + table: table, + }, + } + + err := td.getSourcePKCols() + require.NoError(t, err) + require.Nil(t, td.tablePlan.sourcePkCols) +}