{"record":{"id":"d1204a6cffc7851e","repo":"bytebase/bytebase","slug":"failed-to-extract-suffix-select-statement","errorCode":null,"errorMessage":"failed to extract suffix select statement","messagePattern":"failed to extract suffix select statement","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/parser/mysql/backup.go","lineNumber":609,"sourceCode":"\t\t\tif _, err := buf.WriteString(\"SELECT \"); err != nil {\n\t\t\t\treturn nil, errors.Wrap(err, \"failed to write select statement\")\n\t\t\t}\n\t\t\tfor j, column := range normalColumns {\n\t\t\t\tif j > 0 {\n\t\t\t\t\tif err := buf.WriteByte(','); err != nil {\n\t\t\t\t\t\treturn nil, errors.Wrap(err, \"failed to write comma\")\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif _, err := fmt.Fprintf(&buf, \"`%s`.`%s`\", tableNameOrAlias, column); err != nil {\n\t\t\t\t\treturn nil, errors.Wrap(err, \"failed to write column\")\n\t\t\t\t}\n\t\t\t}\n\t\t\tif _, err := buf.WriteString(\" FROM \"); err != nil {\n\t\t\t\treturn nil, errors.Wrap(err, \"failed to write from\")\n\t\t\t}\n\t\t}\n\t\tif err := writeSuffixSelectClause(&buf, item.Node, item.FullSQL); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"failed to extract suffix select statement\")\n\t\t}\n\t}\n\n\tif err := buf.WriteByte(';'); err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to write semicolon\")\n\t}\n\n\treturn &base.BackupStatement{\n\t\tStatement:       buf.String(),\n\t\tSourceTableName: table.Table,\n\t\tTargetTableName: targetTable,\n\t\tStartPosition:   statementInfoList[0].StartPosition,\n\t\tEndPosition:     statementInfoList[len(statementInfoList)-1].EndPosition,\n\t}, nil\n}\n\nfunc nodeStmtLoc(node ast.Node) ast.Loc {\n\tswitch n := node.(type) {","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/parser/mysql/backup.go#L591-L627","documentation":"generateSQLForTable wraps any error returned by writeSuffixSelectClause — the function that copies the FROM/WHERE/ORDER BY/LIMIT suffix of the original UPDATE or DELETE into the generated INSERT ... SELECT backup statement — with this message. The wrapped error is almost always a strings.Builder write failure, which in practice only occurs if the builder previously failed or memory allocation failed.","triggerScenarios":"generateSQL -> generateSQLForTable -> writeSuffixSelectClause returning a non-nil error from buf.WriteString / fmt.Fprintf inside writeUpdateSuffix or writeDeleteSuffix while reconstructing the SELECT suffix from the original SQL text.","commonSituations":"Extremely rare in practice; may surface under memory pressure, or if a bug in suffix slicing (bad Loc offsets producing pathological output) triggers a builder error. Mostly a defensive wrapper.","solutions":["Inspect the wrapped error for the actual strings.Builder failure reason.","Retry the operation; transient memory pressure is the usual reversible cause.","If reproducible on ordinary statements, report a bug with the failing SQL — Loc offsets in the parsed AST may be out of range.","Check available memory on the process if it correlates with large statements."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"stmts, err := TransformDMLToSelect(ctx, tCtx, sql, src, dst, prefix)\nif err != nil && strings.Contains(err.Error(), \"failed to extract suffix select statement\") {\n  // transient builder/memory failure; retry once\n  stmts, err = TransformDMLToSelect(ctx, tCtx, sql, src, dst, prefix)\n}","preventionTips":["Ensure adequate process memory for large DML batches.","If reproducible, file a bug with the offending SQL (likely AST Loc offset issue)."],"tags":["mysql","backup","sql-generation"],"backgroundTag":"sql-query-failed","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}