{"record":{"id":"6e32c4e7896d5afc","repo":"vitessio/vitess","slug":"unexpected-number-of-table-definitions-returned-fr","errorCode":null,"errorMessage":"unexpected number of table definitions returned from GetSchema call for table %q: %d","messagePattern":"unexpected number of table definitions returned from GetSchema call for table %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vreplicator.go","lineNumber":883,"sourceCode":"\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn err\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (vr *vreplicator) getTableSecondaryKeys(ctx context.Context, tableName string) ([]*sqlparser.IndexDefinition, error) {\n\treq := &tabletmanagerdatapb.GetSchemaRequest{Tables: []string{tableName}}\n\tschema, err := vr.mysqld.GetSchema(ctx, vr.dbClient.DBName(), req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t// schema should never be nil, but check to be extra safe.\n\tif schema == nil || len(schema.TableDefinitions) != 1 {\n\t\treturn nil, fmt.Errorf(\"unexpected number of table definitions returned from GetSchema call for table %q: %d\",\n\t\t\ttableName, len(schema.TableDefinitions))\n\t}\n\ttableSchema := schema.TableDefinitions[0].Schema\n\tvar secondaryKeys []*sqlparser.IndexDefinition\n\tparsedDDL, err := vr.vre.env.Parser().ParseStrictDDL(tableSchema)\n\tif err != nil {\n\t\treturn secondaryKeys, err\n\t}\n\tcreateTable, ok := parsedDDL.(*sqlparser.CreateTable)\n\t// createTable or createTable.TableSpec should never be nil\n\t// if it was a valid cast, but check to be extra safe.\n\tif !ok || createTable == nil || createTable.GetTableSpec() == nil {\n\t\treturn nil, fmt.Errorf(\"could not determine CREATE TABLE statement from table schema %q\", tableSchema)\n\t}\n\n\ttableSpec := createTable.GetTableSpec()\n\tfkIndexCols := make(map[string]bool)\n\tfor _, constraint := range tableSpec.Constraints {","sourceCodeStart":865,"sourceCodeEnd":901,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go#L865-L901","documentation":"getTableSecondaryKeys asks mysqld.GetSchema for exactly the one table being processed and expects exactly one TableDefinition. If the result is nil, empty, or contains more than one definition, this error is raised. It guards against silently parsing the wrong table's schema when stashing secondary keys or running post-copy actions.","triggerScenarios":"GetSchema returns zero definitions (table dropped/renamed between planning and this call, wrong dbname) or multiple definitions (unusual GetSchema behavior). Guard also covers schema==nil defensively.","commonSituations":"Table dropped concurrently during a MoveTables copy; case-sensitivity mismatches (lower_case_table_names) causing lookups to miss; pointing the workflow at a different keyspace/dbname than expected; GetSchema filter misconfiguration.","solutions":["Confirm the table still exists in the target database and its name casing matches (check lower_case_table_names on the target mysqld).","Verify vr.dbClient.DBName() is the expected database — an empty or wrong dbname makes GetSchema return no rows.","Check concurrent operations: a DropTable/RENAME during copy causes the table to vanish; re-run the table copy (MarkTableCopied/reset copy_state and restart).","Inspect the %d count in the message: 0 means missing table, >1 means unexpected GetSchema behavior — investigate the mysqld/schema engine accordingly."],"exampleFix":"// before: table was renamed mid-copy so GetSchema returns 0 definitions\n// after: verify the table exists before/at copy time\n// mysql> SHOW CREATE TABLE customer.corder;\n// then restart the failed table copy:\n// UPDATE _vt.copy_state SET ... WHERE vrepl_id=<id>; -- or re-run MoveTables for that table","handlingStrategy":"validation","validationCode":"// Verify the table exists exactly once in the target db before copy actions:\n// SELECT COUNT(*) FROM information_schema.tables\n//  WHERE table_schema = '<dbname>' AND table_name = '<table>';  -- expect 1","typeGuard":null,"tryCatchPattern":"schema, err := vr.mysqld.GetSchema(ctx, vr.dbClient.DBName(), req)\nif err != nil {\n\treturn nil, vterrors.Wrapf(err, \"GetSchema failed for %s\", tableName)\n}\nif schema == nil || len(schema.TableDefinitions) != 1 {\n\t// count in message: 0 = table missing (dropped/renamed), >1 = unexpected\n\treturn nil, fmt.Errorf(\"unexpected number of table definitions for %q\", tableName)\n}","preventionTips":["Avoid concurrent DROP/RENAME of tables being copied by MoveTables.","Match table-name casing with lower_case_table_names on the target.","Confirm the workflow targets the intended keyspace/dbname.","Re-run the affected table's copy after schema churn resolves."],"tags":["vreplication","schema","get-schema","copy-phase"],"backgroundTag":"get-schema-table-not-found","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}