{"record":{"id":"ab41deae570a6cf6","repo":"vitessio/vitess","slug":"unexpected-number-of-tables-returned-from-schema","errorCode":null,"errorMessage":"unexpected number of tables returned from schema: %v","messagePattern":"unexpected number of tables returned from schema: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/materializer.go","lineNumber":664,"sourceCode":"\t\t}\n\t}\n\n\t// Validate against source schema\n\tsourceShards, err := wr.ts.GetServingShards(ctx, keyspace)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tonesource := sourceShards[0]\n\tif onesource.PrimaryAlias == nil {\n\t\treturn nil, nil, nil, fmt.Errorf(\"source shard has no primary: %v\", onesource.ShardName())\n\t}\n\treq := &tabletmanagerdatapb.GetSchemaRequest{Tables: []string{sourceTableName}}\n\ttableSchema, err := schematools.GetSchema(ctx, wr.ts, wr.tmc, onesource.PrimaryAlias, req)\n\tif err != nil {\n\t\treturn nil, nil, nil, err\n\t}\n\tif len(tableSchema.TableDefinitions) != 1 {\n\t\treturn nil, nil, nil, fmt.Errorf(\"unexpected number of tables returned from schema: %v\", tableSchema.TableDefinitions)\n\t}\n\n\t// Generate \"create table\" statement\n\tlines := strings.Split(tableSchema.TableDefinitions[0].Schema, \"\\n\")\n\tif len(lines) < 3 {\n\t\t// Unreachable\n\t\treturn nil, nil, nil, fmt.Errorf(\"schema looks incorrect: %s, expecting at least four lines\", tableSchema.TableDefinitions[0].Schema)\n\t}\n\tvar modified []string\n\tmodified = append(modified, strings.Replace(lines[0], sourceTableName, targetTableName, 1))\n\tfor i := range sourceVindexColumns {\n\t\tline, err := generateColDef(lines, sourceVindexColumns[i], vindexFromCols[i])\n\t\tif err != nil {\n\t\t\treturn nil, nil, nil, err\n\t\t}\n\t\tmodified = append(modified, line)\n\t}\n","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/materializer.go#L646-L682","documentation":"After fetching the source table schema from the primary tablet, Vitess expects exactly one table definition back (it queried for a single table name). Any other count — typically zero — indicates the table doesn't exist on that tablet or the schema call returned unexpected results.","triggerScenarios":"GetSchema on the source shard's primary returned zero or multiple TableDefinitions for the requested source table — usually because the table does not exist on that tablet (fresh replica set, wrong keyspace) or the filtered result unexpectedly matched more than once.","commonSituations":"Table name typo; table exists in the vschema but was never created in MySQL on the source shard; running against a shard whose schema wasn't restored; schema reload lag after a manual DROP/CREATE.","solutions":["Verify the table exists on the source primary (`SHOW TABLES`) and create it if missing","Double-check the keyspace/table name passed to CreateLookupVindex","Reload the tablet schema (`vtctldclient ReloadSchema`) and retry"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"tds, err := schematools.GetSchema(ctx, ts, tmc, primaryAlias, &tabletmanagerdatapb.GetSchemaRequest{Tables: []string{sourceTableName}})\nif err != nil { return err }\nif len(tds.TableDefinitions) != 1 {\n    return fmt.Errorf(\"table %s must exist exactly once on the source primary\", sourceTableName)\n}","typeGuard":"func exactlyOneTableDef(s *tabletmanagerdatapb.SchemaResult) *tabletmanagerdatapb.TableDefinition {\n    if len(s.TableDefinitions) == 1 { return s.TableDefinitions[0] }\n    return nil\n}","tryCatchPattern":"if err := createLookupVindex(...); err != nil {\n    if strings.Contains(err.Error(), \"unexpected number of tables returned\") {\n        return ensureTableExists(ks, table) // create/reload schema, then retry\n    }\n    return err\n}","preventionTips":["Confirm the table exists on the source primary with SHOW TABLES before creating lookup vindexes","Keep vschema table entries and physical MySQL tables in sync","Reload tablet schema after manual DDL"],"tags":["vitess","schema","table-missing"],"backgroundTag":"table-not-found","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}