Skip to content

[DBI-855] MySQL connector: Use binlog event type and meta to determine BINARY(N) actual length and padding#4445

Merged
ilidemi merged 6 commits into
mainfrom
DBI-855/mysql/binary/padding
Jun 18, 2026
Merged

[DBI-855] MySQL connector: Use binlog event type and meta to determine BINARY(N) actual length and padding#4445
ilidemi merged 6 commits into
mainfrom
DBI-855/mysql/binary/padding

Conversation

@pfcoperez

@pfcoperez pfcoperez commented Jun 18, 2026

Copy link
Copy Markdown
Member

MySQL BINARY(N) values are right-padded, from https://dev.mysql.com/doc/refman/5.7/en/binary-varbinary.html

When BINARY values are stored, they are right-padded with the pad value to the specified length. The pad value is 0x00 (the zero byte). Values are right-padded with 0x00 for inserts, and no trailing bytes are removed for retrievals. All bytes are significant in comparisons, including ORDER BY and DISTINCT operations. 0x00 and space differ in comparisons, with 0x00 sorting before space.

In MySQL binlog, these values are:

  • zero-right-trimmed: stored without the right side zeros.
  • with the length of the zero-right-trimmed binary.

When querying the data, MySQL uses the record type and metadata to restore the original length but, when reading events from binlog directly,

Closes: DBI-855
Related to: https://github.com/ClickHouse/support-escalation/issues/8013

References:

@pfcoperez pfcoperez self-assigned this Jun 18, 2026
@pfcoperez
pfcoperez requested a review from a team as a code owner June 18, 2026 15:17
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Flaky Test Detected

Analysis: TestApiPg/TestResetMirrorSequences hit a fixed 60s polling timeout while the mirror was still in STATUS_SNAPSHOT — a timing/resource-contention flake under -p 32 parallelism, unrelated to the PR's MySQL BINARY(N) padding change.
Confidence: 0.85

✅ Automatically retrying the workflow

View workflow run

switch qkind {
case types.QValueKindBytes:
return types.QValueBytes{Val: shared.UnsafeFastStringToReadOnlyBytes(val)}, nil
b := shared.UnsafeFastStringToReadOnlyBytes(val)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks good to me
just one thing, are we sure it comes as 'string' for all flavors/versions?
i see that we also have []byte: case a bit above
not sure if we need the same padding mechanism there just in case

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Unless I am not mistaken, []byte correspond to variable length types. In contrast BINARY[N] is fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All flavors/vers have the same implementation, linked the source

@ilidemi ilidemi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is one corner-corner case where a column gets added during CDC, we miss a DDL event then infer the type from the future binlog event metadata and it ends up going around this path but this requires enough untangling that it should be a separate task

Comment thread flow/connectors/mysql/qvalue_convert.go
Comment thread flow/e2e/clickhouse_mysql_test.go Outdated
@ilidemi
ilidemi enabled auto-merge (squash) June 18, 2026 17:18
@ilidemi
ilidemi merged commit 6a5d630 into main Jun 18, 2026
16 of 19 checks passed
@ilidemi
ilidemi deleted the DBI-855/mysql/binary/padding branch June 18, 2026 17:39
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