{"record":{"id":"93e86c9b80e85a60","repo":"vitessio/vitess","slug":"could-not-determine-create-table-statement-from-ta","errorCode":null,"errorMessage":"could not determine CREATE TABLE statement from table schema %q","messagePattern":"could not determine CREATE TABLE statement from table schema %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vreplicator.go","lineNumber":896,"sourceCode":"\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 {\n\t\tif fkDef, ok := constraint.Details.(*sqlparser.ForeignKeyDefinition); ok {\n\t\t\tfkCols := make([]string, len(fkDef.Source))\n\t\t\tfor i, fkCol := range fkDef.Source {\n\t\t\t\tfkCols[i] = fkCol.Lowered()\n\t\t\t}\n\t\t\tfkIndexCols[strings.Join(fkCols, \",\")] = true\n\t\t}\n\t}\n\tfor _, index := range tableSpec.Indexes {\n\t\tif index.Info.Type != sqlparser.IndexTypePrimary {\n\t\t\tcols := make([]string, len(index.Columns))\n\t\t\tfor i, col := range index.Columns {\n\t\t\t\tcols[i] = col.Column.Lowered()","sourceCodeStart":878,"sourceCodeEnd":914,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go#L878-L914","documentation":"During VReplication's copy phase, deferred secondary keys must be re-added after the bulk copy. To find which indexes exist, the table's SHOW CREATE TABLE output is fetched and parsed; this error is thrown when the parsed statement is not a sqlparser.CreateTable or its table spec is missing, so the CREATE TABLE statement cannot be analyzed. It is a defensive internal check that normally only fires if the stored schema is not a plain CREATE TABLE statement.","triggerScenarios":"getTableSecondaryKeys (called from stashSecondaryKeys and execPostCopyActions) runs GetSchema for a table, parses the schema with ParseStrictDDL, and the result fails the (*sqlparser.CreateTable) type assertion, is nil, or GetTableSpec() returns nil — e.g. the schema text is not a plain CREATE TABLE (views, unusual dialect syntax, or an unexpectedly truncated/modified schema).","commonSituations":"Moving or migrating a table whose schema string on the target tablet is not a standard MySQL CREATE TABLE statement; running a workflow against a view or table whose schema was manually edited; parser incompatibility with MariaDB/MySQL-specific DDL that Vitess's parser mishandles.","solutions":["Inspect the target table's SHOW CREATE TABLE output and confirm it is a plain CREATE TABLE (not a view or non-table object) for the table named in the error","Retry the workflow; if the schema was edited mid-copy, restore the expected schema or recreate the table and restart MoveTables/Migrate/Reshard","Check the Vitess version for parser limitations with the DDL features used (e.g. exotic index/constraint syntax) and upgrade if a fix exists","If it persists, file an issue with the table schema — this is a defensive check that should not fire for valid CREATE TABLE output"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"schema, _ := mysqld.GetSchema(ctx, dbName, &tabletmanagerdatapb.GetSchemaRequest{Tables: []string{tableName}})\nstmt, err := parser.ParseStrictDDL(schema.TableDefinitions[0].Schema)\nif err != nil { return err }\nif _, ok := stmt.(*sqlparser.CreateTable); !ok || stmt.(*sqlparser.CreateTable).GetTableSpec() == nil {\n    return fmt.Errorf(\"table %s schema is not a plain CREATE TABLE; fix before starting workflow\", tableName)\n}","typeGuard":"func isPlainCreateTable(stmt sqlparser.Statement) (*sqlparser.CreateTable, bool) {\n    ct, ok := stmt.(*sqlparser.CreateTable)\n    if !ok || ct == nil || ct.GetTableSpec() == nil {\n        return nil, false\n    }\n    return ct, true\n}","tryCatchPattern":null,"preventionTips":["Run SHOW CREATE TABLE on the target table before starting MoveTables/Migrate and confirm it is a plain CREATE TABLE, not a view","Avoid manually editing table schemas on target tablets while a copy phase is running","Keep Vitess updated — parser gaps with newer MySQL/MariaDB DDL syntax are fixed over time","Test the workflow on a staging copy of the schema if you use exotic DDL features"],"tags":["vreplication","sqlparser","schema","go"],"backgroundTag":"unparseable-table-schema","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}