Skip to content

Conversation

@altmannmarcelo
Copy link
Contributor

@altmannmarcelo altmannmarcelo commented Apr 18, 2025

This commit fixes the issue where we only advance the iterators for
columns that are present in the row image. The problem is that in
the table map event, the optional metadata is populated for all
columns, thus we need to advance the iterators even for columns that
are not present in the row event, otherwise we will be reading
metadata for the wrong column.

The fix is to keep all the logic of advancing the iterators for all
columns, and only populate the Column and value objects for the
columns that are present in the row event.

Test created with:

SET binlog_row_image = minimal;
CREATE TABLE t1 (
    `col_1` int NOT NULL,
    `col_2` blob,
    `col_3` char(2) DEFAULT NULL,
    `col_4` int,
    `col_5` int unsigned,
    PRIMARY KEY (`col_1`)
);
INSERT INTO `t1` (
    `col_1`,
    `col_3`,
    `col_5`
) VALUES (
    1,
    'a',
    '3230202323'
);

If we are not correctly parsing the row metadata, the following will
happen:

  • col_3 will be parsed as collation 63 (BINARY) instead of 255
    (UTF8MB4_0900_AI_CI) as we did not advance the metadata iterator due
    to missing col_2 in the row image.
  • col_5 will be intercepted as signed integer, as we are parsing it as metadata from col_4. And because we are
    using the highest bit, the value will be interpreted as negative.

Closes: #162

Test case to explore minimal row metadata fetching wrong field
if not all columns are set.

Test created with:

```sql
SET binlog_row_image = minimal;
CREATE TABLE t1 (
    `col_1` int NOT NULL,
    `col_2` blob,
    `col_3` char(2) DEFAULT NULL,
    `col_4` int,
    `col_5` int unsigned,
    PRIMARY KEY (`col_1`)
);
INSERT INTO `t1` (
    `col_1`,
    `col_3`,
    `col_5`
) VALUES (
    1,
    'a',
    '3230202323'
);
```

If we are not correctly parsing the row metadata, the following will
happen:

* col_3 will be parsed as collation 63 (BINARY) instead of 255
 (UTF8MB4_0900_AI_CI) as we did not advance the metadata iterator due
 to missing col_2 in the row image.
* col_4 will be intercepted as signed integer, and because we are
using the highest bit, the value will be interpreted as negative.

Ref: blackbeam#162
This commit fixes the issue where we only advance the iterators for
columns that are present in the row image. The problem is that in
the table map event, the optional metadata is populated for all
columns, thus we need to advance the iterators even for columns that
are not present in the row event, otherwise we will be reading
metadata for the wrong column.

The fix is to keep all the logic of advancing the iterators for all
columns, and only populate the Column and value objects for the
columns that are present in the row event.

Fixes: blackbeam#162
@altmannmarcelo
Copy link
Contributor Author

Hi @blackbeam! When you have a chance, could you please take a look at this PR? I’d really appreciate any feedback. Thanks!

@blackbeam blackbeam merged commit a1be12b into blackbeam:master Apr 24, 2025
1 check passed
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.

Wrong signedness for Minimal Row Based Replication

2 participants