Skip to content

Fix Warning 1300 for varbinary columns with bytes invalid as utf8mb4#1661

Merged
meiji163 merged 3 commits intogithub:masterfrom
ggilder:fix-varbinary-charset-warning
Apr 22, 2026
Merged

Fix Warning 1300 for varbinary columns with bytes invalid as utf8mb4#1661
meiji163 merged 3 commits intogithub:masterfrom
ggilder:fix-varbinary-charset-warning

Conversation

@ggilder
Copy link
Copy Markdown
Contributor

@ggilder ggilder commented Apr 22, 2026

Related issue: #1660

Description

From the related issue:

When gh-ost replays a binlog DML event, the go-mysql library returns varbinary column values as a Go string (not []byte). In convertArg, the existing code only converted string → []byte when the column had a non-empty Charset (e.g. utf8mb4 for varchar). varbinary columns have no character set, so Charset is always "", and the string fell through unconverted.

The Go MySQL driver sends string args as MYSQL_TYPE_VAR_STRING with the connection's utf8mb4 charset metadata attached, causing MySQL to validate the bytes. If a varbinary value (e.g. a binary UUID) contains byte sequences that are invalid utf8mb4, MySQL emits Warning 1300. With gh-ost's panic-on-warnings enabled, this aborts the migration.

varbinary columns are commonly used for UUIDs which have arbitrary bytes and can easily trigger this problem.

Fix: add an else-if branch that detects binary storage types by MySQLType (binary, varbinary, *blob) and returns []byte, so the driver sends MYSQL_TYPE_BLOB (binary data) with no charset validation.

MySQLType is used rather than Charset == "" alone because test Column objects built via NewColumnList leave MySQLType unset, which would have changed the return type for all no-charset columns in existing tests. In production, inspect.go always populates MySQLType from information_schema.data_type.

In case this PR introduced Go code changes:

  • contributed code is using same conventions as original code
  • script/cibuild returns with no formatting errors, build errors or unit test errors.

When gh-ost replays a binlog DML event, the go-mysql library returns
varbinary column values as a Go `string` (not `[]byte`). In convertArg,
the existing code only converted string → []byte when the column had a
non-empty Charset (e.g. utf8mb4 for varchar). varbinary columns have no
character set, so Charset is always "", and the string fell through
unconverted.

The Go MySQL driver sends `string` args as MYSQL_TYPE_VAR_STRING with
the connection's utf8mb4 charset metadata attached, causing MySQL to
validate the bytes. If a varbinary value (e.g. a binary UUID) contains
byte sequences that are invalid utf8mb4, MySQL emits Warning 1300. With
gh-ost's panic-on-warnings enabled, this aborts the migration.

Fix: add an else-if branch that detects binary storage types by
MySQLType (binary, varbinary, *blob) and returns []byte, so the driver
sends MYSQL_TYPE_BLOB (binary data) with no charset validation.

MySQLType is used rather than Charset == "" alone because test Column
objects built via NewColumnList leave MySQLType unset, which would have
changed the return type for all no-charset columns in existing tests.
In production, inspect.go always populates MySQLType from
information_schema.data_type.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ggilder ggilder requested review from meiji163 and rashiq as code owners April 22, 2026 22:44
Copilot AI review requested due to automatic review settings April 22, 2026 22:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses MySQL Warning 1300 during binlog DML replay when varbinary (and other binary-storage) column values are provided as Go strings and end up being sent by the MySQL driver as text with connection charset metadata.

Changes:

  • Update Column.convertArg to return []byte for binary-storage types (binary/varbinary/*blob) when Charset is empty.
  • Add unit tests ensuring varbinary values returned as string or []uint8 are converted to []byte, preventing charset validation warnings.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
go/sql/types.go Converts args for binary-storage types to []byte so the driver sends them as binary (avoiding Warning 1300).
go/sql/types_test.go Adds regression tests for varbinary values containing invalid UTF-8 byte sequences.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread go/sql/types_test.go Outdated
Comment thread go/sql/types_test.go Outdated
Comment thread go/sql/types.go Outdated
- Use MySQLType "varbinary(16)" in tests instead of bare "varbinary",
  matching the real value produced by information_schema COLUMN_TYPE
  (which includes length). Guards against future refactors that might
  switch from substring matching to exact matching.
- Correct test comment: MySQLType is populated from COLUMN_TYPE, not
  data_type.
- Broaden types.go comment to say "the connection's charset/collation
  metadata (often utf8mb4)" since gh-ost's connection charset is
  configurable via --charset.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@meiji163
Copy link
Copy Markdown
Contributor

Just ran into this myself 😄 nice timing!

Comment thread go/sql/types_test.go Outdated
@meiji163 meiji163 merged commit a3d0115 into github:master Apr 22, 2026
9 checks passed
@ggilder ggilder deleted the fix-varbinary-charset-warning branch April 23, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants