{"record":{"id":"25e7cfbd86a57a4d","repo":"vitessio/vitess","slug":"v-cached-columns-count-d-mismatch-binglog-row","errorCode":null,"errorMessage":"[%v] cached columns count[%d] mismatch binglog row [%d]","messagePattern":"\\[(.+?)\\] cached columns count\\[(.+?)\\] mismatch binglog row \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/binlog/binlog_streamer.go","lineNumber":740,"sourceCode":"\t}\n\treturn statements\n}\n\n// writeValuesAsSQL is a helper method to print the values as SQL in the\n// provided strings.Builder. It also returns the value for the keyspaceIDColumn,\n// and the array of values for the PK, if necessary.\nfunc writeValuesAsSQL(sql *sqlparser.TrackedBuffer, tce *tableCacheEntry, rs *mysql.Rows, rowIndex int, getPK bool) (sqltypes.Value, []sqltypes.Value, error) {\n\tvalueIndex := 0\n\tdata := rs.Rows[rowIndex].Data\n\tpos := 0\n\tvar keyspaceIDCell sqltypes.Value\n\tvar pkValues []sqltypes.Value\n\tif getPK {\n\t\tpkValues = make([]sqltypes.Value, len(tce.pkNames))\n\t}\n\n\tif len(tce.ti.Fields) != rs.DataColumns.Count() {\n\t\terr := fmt.Errorf(\"[%v] cached columns count[%d] mismatch binglog row [%d]\", tce.ti.Name, len(tce.ti.Fields), rs.DataColumns.Count())\n\t\treturn sqltypes.Value{}, nil, err\n\t}\n\n\tfor c := 0; c < rs.DataColumns.Count(); c++ {\n\t\tif !rs.DataColumns.Bit(c) {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Print a separator if needed, then print the name.\n\t\tif valueIndex > 0 {\n\t\t\tsql.WriteString(\", \")\n\t\t}\n\t\tsql.Myprintf(\"%v\", sqlparser.NewIdentifierCI(tce.ti.Fields[c].Name))\n\t\tsql.WriteByte('=')\n\n\t\tif rs.Rows[rowIndex].NullColumns.Bit(valueIndex) {\n\t\t\t// This column is represented, but its value is NULL.\n\t\t\tsql.WriteString(\"NULL\")","sourceCodeStart":722,"sourceCodeEnd":758,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/binlog/binlog_streamer.go#L722-L758","documentation":"writeValuesAsSQL reconciles the cached table schema fields (tce.ti.Fields) against the column bitmap in the binlog row event. If the counts differ — the table was ALTERed after the schema was cached but before rows were decoded — it refuses to guess column mapping and returns this (typo'd 'binglog') error.","triggerScenarios":"appendInserts or appendUpdates process a rows event whose DataColumns count != len(tce.ti.Fields): the table's column count in the source changed (ADD/DROP COLUMN) or the cached schema is stale/out-of-order relative to the binlog.","commonSituations":"Online schema change (gh-ost/LHM) running while vreplication streams rows; streamer started before a migration completed so schema snapshot is old; multiple binlog streams mixing pre/post-ALTER row formats.","solutions":["Reload the table schema and restart the stream (fresh copy) so the cached Fields match the current row format","Pause binlog streaming during ALTERs, or use vitess's schema-tracking (wait for the migration position before streaming)","Ensure the schema engine (bls.se) cache is invalidated on DDL events in the stream","If intentional mid-ALTER decoding is needed, split the stream at the ALTER position and re-copy"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"ti := schemaEngine.GetTable(sqlparser.NewIdentifierCS(tableName))\nif ti != nil && len(ti.Fields) != eventColumnCount {\n    // reload schema before streaming\n    schemaEngine.Reload(ctx)\n}","typeGuard":null,"tryCatchPattern":"err := streamer.Stream(ctx, signals)\nif err != nil && strings.Contains(err.Error(), \"mismatch binglog row\") {\n    // reload schema cache and restart the stream\n}","preventionTips":["Quiesce binlog streaming during ALTERs / gh-ost cutover","Invalidate schema cache on DDL events","Use schema tracking so Fields stay in sync with row events","Split streams at migration boundaries instead of spanning them"],"tags":["binlog","schema-mismatch","row-replication"],"backgroundTag":"schema-column-count-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}