vitessio/vitess · error
schema looks incorrect: %s, expecting at least four lines
Error message
schema looks incorrect: %s, expecting at least four lines
What it means
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.
Source
Thrown at go/vt/wrangler/materializer.go:671
}
onesource := sourceShards[0]
if onesource.PrimaryAlias == nil {
return nil, nil, nil, fmt.Errorf("source shard has no primary: %v", onesource.ShardName())
}
req := &tabletmanagerdatapb.GetSchemaRequest{Tables: []string{sourceTableName}}
tableSchema, err := schematools.GetSchema(ctx, wr.ts, wr.tmc, onesource.PrimaryAlias, req)
if err != nil {
return nil, nil, nil, err
}
if len(tableSchema.TableDefinitions) != 1 {
return nil, nil, nil, fmt.Errorf("unexpected number of tables returned from schema: %v", tableSchema.TableDefinitions)
}
// Generate "create table" statement
lines := strings.Split(tableSchema.TableDefinitions[0].Schema, "\n")
if len(lines) < 3 {
// Unreachable
return nil, nil, nil, fmt.Errorf("schema looks incorrect: %s, expecting at least four lines", tableSchema.TableDefinitions[0].Schema)
}
var modified []string
modified = append(modified, strings.Replace(lines[0], sourceTableName, targetTableName, 1))
for i := range sourceVindexColumns {
line, err := generateColDef(lines, sourceVindexColumns[i], vindexFromCols[i])
if err != nil {
return nil, nil, nil, err
}
modified = append(modified, line)
}
if vindex.Params["data_type"] == "" || strings.EqualFold(vindex.Type, "consistent_lookup_unique") || strings.EqualFold(vindex.Type, "consistent_lookup") {
modified = append(modified, fmt.Sprintf(" %s varbinary(128),", sqlescape.EscapeID(vindexToCol)))
} else {
modified = append(modified, fmt.Sprintf(" %s %s,", sqlescape.EscapeID(vindexToCol), sqlescape.EscapeID(vindex.Params["data_type"])))
}
buf := sqlparser.NewTrackedBuffer(nil)
fmt.Fprintf(buf, " PRIMARY KEY (")View on GitHub (pinned to 01a25a7d17)
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
Example fix
null
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
func schemaLooksSane(createTableSQL string) bool {
return len(strings.Split(createTableSQL, "\n")) >= 3
} Try / catch
if err := createLookupVindex(...); err != nil {
if strings.Contains(err.Error(), "schema looks incorrect") {
_ = reloadTabletSchema(ctx, primaryAlias) // retry once after reload
return createLookupVindex(...)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Corrupted or nonstandard schema dump; a table definition fetched from an unusual MySQL flavor or proxy that reformats DDL onto one line.
Related errors
- schemas differ on table %v: %s: %v differs from: %s: %v
- BeforeSchema differs
- AfterSchema differs
- cannot compile regexp %v for table: %v
- cannot compile regexp %v for excludeTable: %v
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/b52f9d6e766717df.
Report an issue: GitHub.