{"record":{"id":"866ea0fc202979f2","repo":"vitessio/vitess","slug":"empty-create-table-statement-for-v","errorCode":null,"errorMessage":"empty create table statement for %v","messagePattern":"empty create table statement for (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/mysqlctl/schema.go","lineNumber":255,"sourceCode":"\tif !tableSchemaOnly {\n\t\tfields, columns, err = mysqld.GetColumns(ctx, dbName, tableName)\n\t\tif err != nil {\n\t\t\treturn nil, nil, \"\", err\n\t\t}\n\t}\n\n\treturn fields, columns, schema, nil\n}\n\n// normalizedSchema returns a table schema with database names replaced, and auto_increment annotations removed.\nfunc (mysqld *Mysqld) normalizedSchema(ctx context.Context, dbName, tableName, tableType string) (string, error) {\n\tbacktickDBName := sqlescape.EscapeID(dbName)\n\tqr, fetchErr := mysqld.FetchSuperQuery(ctx, fmt.Sprintf(\"SHOW CREATE TABLE %s.%s\", backtickDBName, sqlescape.EscapeID(tableName)))\n\tif fetchErr != nil {\n\t\treturn \"\", vterrors.Wrapf(fetchErr, \"in Mysqld.normalizedSchema()\")\n\t}\n\tif len(qr.Rows) == 0 {\n\t\treturn \"\", fmt.Errorf(\"empty create table statement for %v\", tableName)\n\t}\n\n\t// Normalize & remove auto_increment because it changes on every insert\n\t// FIXME(alainjobart) find a way to share this with\n\t// vt/tabletserver/table_info.go:162\n\tnorm := qr.Rows[0][1].ToString()\n\tnorm = autoIncr.ReplaceAllLiteralString(norm, \"\")\n\tif tableType == tmutils.TableView {\n\t\t// Views will have the dbname in there, replace it\n\t\t// with {{.DatabaseName}}\n\t\tnorm = strings.ReplaceAll(norm, backtickDBName, \"{{.DatabaseName}}\")\n\t}\n\n\treturn norm, nil\n}\n\n// ResolveTables returns a list of actual tables+views matching a list\n// of regexps","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/mysqlctl/schema.go#L237-L273","documentation":"normalizedSchema executes `SHOW CREATE TABLE db.table` and expects at least one row containing the CREATE statement. Zero rows means MySQL gave no table definition, so normalization fails with this error.","triggerScenarios":"Calling collectSchema/GetSchema for a table that returns no rows from SHOW CREATE TABLE — typically the table was dropped concurrently, doesn't exist, or the server responds unusually.","commonSituations":"Schema drift between topodata and MySQL (table dropped while exporting); querying views/materialized structures unsupported by the flavor; stale table lists captured before a DROP.","solutions":["Confirm the table exists: run `SHOW CREATE TABLE db.table` manually","Refresh the table list before export (re-run GetSchema after DDL completes)","Check for concurrent schema migrations and retry after they finish","If the table legitimately cannot be shown (permissions), grant SELECT/SHOW privileges to the vt user"],"exampleFix":"// before: iterating a stale table list containing dropped_table\n// after: re-list tables first\n// SHOW TABLES FROM db; then normalizedSchema for existing tables only","handlingStrategy":"validation","validationCode":"qr, err := mysqld.FetchSuperQuery(ctx, \"SHOW TABLES FROM \"+sqlescape.EscapeID(dbName))\nif err == nil {\n    existing := map[string]bool{}\n    for _, r := range qr.Rows { existing[r[0].ToString()] = true }\n    if !existing[tableName] {\n        return fmt.Errorf(\"table %s.%s does not exist\", dbName, tableName)\n    }\n}","typeGuard":null,"tryCatchPattern":"norm, err := mysqld.NormalizedSchema(ctx, dbName, tableName)\nif err != nil && strings.Contains(err.Error(), \"empty create table statement\") {\n    log.Warn(\"table missing during schema export; refreshing table list\")\n    return refreshAndRetry(dbName)\n}","preventionTips":["Refresh table lists immediately before schema export","Block DDL migrations during schema export windows","Grant SHOW/SELECT privileges to the vt MySQL user"],"tags":["mysql","schema","mysqlctl"],"backgroundTag":"empty-schema-result","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}