{"record":{"id":"b52f9d6e766717df","repo":"vitessio/vitess","slug":"schema-looks-incorrect-s-expecting-at-least-fou","errorCode":null,"errorMessage":"schema looks incorrect: %s, expecting at least four lines","messagePattern":"schema looks incorrect: (.+?), expecting at least four lines","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/materializer.go","lineNumber":671,"sourceCode":"\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\n\tif vindex.Params[\"data_type\"] == \"\" || strings.EqualFold(vindex.Type, \"consistent_lookup_unique\") || strings.EqualFold(vindex.Type, \"consistent_lookup\") {\n\t\tmodified = append(modified, fmt.Sprintf(\"  %s varbinary(128),\", sqlescape.EscapeID(vindexToCol)))\n\t} else {\n\t\tmodified = append(modified, fmt.Sprintf(\"  %s %s,\", sqlescape.EscapeID(vindexToCol), sqlescape.EscapeID(vindex.Params[\"data_type\"])))\n\t}\n\tbuf := sqlparser.NewTrackedBuffer(nil)\n\tfmt.Fprintf(buf, \"  PRIMARY KEY (\")","sourceCodeStart":653,"sourceCodeEnd":689,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/materializer.go#L653-L689","documentation":"When generating the CREATE TABLE DDL for the new lookup table, the source table's schema string is split into lines and must have at least three lines (header, at least one column, closing paren). A shorter schema string is malformed, so preparation aborts. The code comments this as effectively unreachable.","triggerScenarios":"The CREATE TABLE statement stored in TableDefinitions[0].Schema contains fewer than 3 newline-separated lines — e.g. a single-line or truncated schema string returned by the tablet.","commonSituations":"Corrupted or nonstandard schema dump; a table definition fetched from an unusual MySQL flavor or proxy that reformats DDL onto one line.","solutions":["Re-fetch/reload the schema on the source primary (`vtctldclient ReloadSchema`) and retry","Inspect the actual CREATE TABLE on the source primary and recreate the table with a standard multi-line DDL if it is malformed","Report to Vitess maintainers if a normal table triggers this — it indicates a schema-serialization problem"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"func schemaLooksSane(createTableSQL string) bool {\n    return len(strings.Split(createTableSQL, \"\\n\")) >= 3\n}","tryCatchPattern":"if err := createLookupVindex(...); err != nil {\n    if strings.Contains(err.Error(), \"schema looks incorrect\") {\n        _ = reloadTabletSchema(ctx, primaryAlias) // retry once after reload\n        return createLookupVindex(...)\n    }\n    return err\n}","preventionTips":["Inspect SHOW CREATE TABLE output if it ever appears single-line or truncated","Reload schema on tablets after unusual restore/clone operations","Report occurrences upstream — this path is expected to be unreachable"],"tags":["vitess","schema","ddl"],"backgroundTag":"malformed-schema-ddl","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}