{"record":{"id":"5c1d1f5a6f744d64","repo":"vitessio/vitess","slug":"batch-size-only-allowed-when-all-queries-are-cre","errorCode":null,"errorMessage":"--batch-size only allowed when all queries are CREATE TABLE|VIEW","messagePattern":"--batch-size only allowed when all queries are CREATE TABLE\\|VIEW","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/schemamanager/tablet_executor.go","lineNumber":477,"sourceCode":"\t\t\t}(result)\n\t\t}\n\t\twg.Wait()\n\t}()\n\n\tif exec.batchSize > 1 {\n\t\t// Before we proceed to batch, we need to validate there's no conflicts.\n\t\tif !exec.isDirectStrategy() {\n\t\t\treturn errorExecResult(errors.New(\"--batch-size requires 'direct' ddl_strategy\"))\n\t\t}\n\t\tif exec.hasProvidedUUIDs() {\n\t\t\treturn errorExecResult(errors.New(\"--batch-size conflicts with --uuid-list. Batching does not support UUIDs.\"))\n\t\t}\n\t\tallSQLsAreCreate, err := allSQLsAreCreateQueries(sqls, exec.parser)\n\t\tif err != nil {\n\t\t\treturn errorExecResult(err)\n\t\t}\n\t\tif !allSQLsAreCreate {\n\t\t\treturn errorExecResult(errors.New(\"--batch-size only allowed when all queries are CREATE TABLE|VIEW\"))\n\t\t}\n\n\t\tsqls = batchSQLs(sqls, int(exec.batchSize))\n\t}\n\tfor index, sql := range sqls {\n\t\t// Attempt to renew lease:\n\t\tif err := rl.Do(func() error { return topo.CheckKeyspaceLocked(ctx, exec.keyspace) }); err != nil {\n\t\t\treturn errorExecResult(vterrors.Wrapf(err, \"CheckKeyspaceLocked in ApplySchemaKeyspace %v\", exec.keyspace))\n\t\t}\n\t\texecResult.CurSQLIndex = index\n\t\tif exec.hasProvidedUUIDs() {\n\t\t\tprovidedUUID = exec.uuids[index]\n\t\t}\n\t\texecutedAsynchronously, err := exec.executeSQL(ctx, sql, providedUUID, &execResult)\n\t\tif err != nil {\n\t\t\treturn errorExecResult(err)\n\t\t}\n\t\tif !executedAsynchronously {","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/schemamanager/tablet_executor.go#L459-L495","documentation":"Batching in schemamanager works by concatenating multiple statements into a single migration, which is only supported for CREATE TABLE / CREATE VIEW statements. Execute parses all SQLs and, if any statement is not a CREATE TABLE or CREATE VIEW, returns this error before doing any work.","triggerScenarios":"Execute called with --batch-size > 1 where the SQL list contains ALTER/DROP/RENAME/INSERT or otherwise non-CREATE statements (allSQLsAreCreateQueries returns false), or where parsing a statement fails (the parse error is returned instead).","commonSituations":"Feeding a mixed migration file (ALTERs plus CREATEs) to batch mode; assuming batch-size works like a plain statement-grouping option for all DDL.","solutions":["Ensure every statement in the input is CREATE TABLE or CREATE VIEW when batching","Remove --batch-size and let each non-CREATE statement run as an individual migration","Split the file: batch the CREATEs, run the ALTERs/DROPs unbatched"],"exampleFix":"// before\n--batch-size 4 with: ALTER TABLE t1 ADD COLUMN c INT; CREATE TABLE t2(...)\n// after\n--batch-size 4 with only: CREATE TABLE t2(...); CREATE TABLE t3(...)","handlingStrategy":"validation","validationCode":"for _, stmt := range sqls {\n    up := strings.ToUpper(strings.TrimSpace(stmt))\n    if !strings.HasPrefix(up, \"CREATE TABLE\") && !strings.HasPrefix(up, \"CREATE VIEW\") {\n        return fmt.Errorf(\"batch-size unsupported statement: %s\", stmt)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"only allowed when all queries are CREATE\") {\n    // re-run with batch-size removed so each statement runs individually\n}","preventionTips":["Group only CREATE TABLE/VIEW statements into batched files","Run ALTER/DROP statements unbatched","Lint migration files for statement types before enabling batch-size"],"tags":["go","schemamanager","configuration","sql"],"backgroundTag":"incompatible-flag-combination","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}