Skip to content

Commit bd19da6

Browse files
author
Shlomi Noach
authored
Merge pull request #236 from Wattpad/binlog_insert_column_lookup_issue
Fix value fetch and convert issue in binlog insert path
2 parents de2513b + 51f0c0d commit bd19da6

File tree

15 files changed

+134
-4
lines changed

15 files changed

+134
-4
lines changed

go/sql/builder.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func BuildDMLInsertQuery(databaseName, tableName string, tableColumns, sharedCol
344344
databaseName = EscapeName(databaseName)
345345
tableName = EscapeName(tableName)
346346

347-
for _, column := range mappedSharedColumns.Columns() {
347+
for _, column := range sharedColumns.Columns() {
348348
tableOrdinal := tableColumns.Ordinals[column.Name]
349349
arg := column.convertArg(args[tableOrdinal])
350350
sharedArgs = append(sharedArgs, arg)
@@ -392,10 +392,9 @@ func BuildDMLUpdateQuery(databaseName, tableName string, tableColumns, sharedCol
392392
databaseName = EscapeName(databaseName)
393393
tableName = EscapeName(tableName)
394394

395-
for i, column := range sharedColumns.Columns() {
396-
mappedColumn := mappedSharedColumns.Columns()[i]
395+
for _, column := range sharedColumns.Columns() {
397396
tableOrdinal := tableColumns.Ordinals[column.Name]
398-
arg := mappedColumn.convertArg(valueArgs[tableOrdinal])
397+
arg := column.convertArg(valueArgs[tableOrdinal])
399398
sharedArgs = append(sharedArgs, arg)
400399
}
401400

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id int auto_increment,
4+
t1 varchar(128) charset latin1 collate latin1_swedish_ci,
5+
t2 varchar(128) charset latin1 collate latin1_swedish_ci,
6+
tutf8 varchar(128) charset utf8,
7+
tutf8mb4 varchar(128) charset utf8mb4,
8+
random_value varchar(128) charset ascii,
9+
primary key(id)
10+
) auto_increment=1;
11+
12+
drop event if exists gh_ost_test;
13+
delimiter ;;
14+
create event gh_ost_test
15+
on schedule every 1 second
16+
starts current_timestamp
17+
ends current_timestamp + interval 60 second
18+
on completion not preserve
19+
enable
20+
do
21+
begin
22+
insert into gh_ost_test values (null, md5(rand()), md5(rand()), md5(rand()), md5(rand()), md5(rand()));
23+
insert into gh_ost_test values (null, 'átesting', 'átesting', 'átesting', 'átesting', md5(rand()));
24+
insert into gh_ost_test values (null, 'átesting_del', 'átesting', 'átesting', 'átesting', md5(rand()));
25+
insert into gh_ost_test values (null, 'testátest', 'testátest', 'testátest', '🍻😀', md5(rand()));
26+
update gh_ost_test set t1='átesting2' where t1='átesting' order by id desc limit 1;
27+
delete from gh_ost_test where t1='átesting_del' order by id desc limit 1;
28+
end ;;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--alter='MODIFY `t1` varchar(128) CHARACTER SET utf8mb4 NOT NULL, MODIFY `t2` varchar(128) CHARACTER SET latin2 NOT NULL, MODIFY `tutf8` varchar(128) CHARACTER SET latin1 NOT NULL'

localtests/alter-charset/create.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id int auto_increment,
4+
t1 varchar(128) charset latin1 collate latin1_swedish_ci,
5+
t2 varchar(128) charset latin1 collate latin1_swedish_ci,
6+
tutf8 varchar(128) charset utf8,
7+
tutf8mb4 varchar(128) charset utf8mb4,
8+
primary key(id)
9+
) auto_increment=1;
10+
11+
drop event if exists gh_ost_test;
12+
delimiter ;;
13+
create event gh_ost_test
14+
on schedule every 1 second
15+
starts current_timestamp
16+
ends current_timestamp + interval 60 second
17+
on completion not preserve
18+
enable
19+
do
20+
begin
21+
insert into gh_ost_test values (null, md5(rand()), md5(rand()), md5(rand()), md5(rand()));
22+
insert into gh_ost_test values (null, 'átesting', 'átesting', 'átesting', 'átesting');
23+
insert into gh_ost_test values (null, 'testátest', 'testátest', 'testátest', '🍻😀');
24+
end ;;

localtests/alter-charset/extra_args

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--alter='MODIFY `t1` varchar(128) CHARACTER SET utf8mb4 NOT NULL, MODIFY `t2` varchar(128) CHARACTER SET latin2 NOT NULL, MODIFY `tutf8` varchar(128) CHARACTER SET latin1 NOT NULL'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id int auto_increment,
4+
c1 int not null,
5+
c2 int not null,
6+
primary key (id)
7+
) auto_increment=1;
8+
9+
drop event if exists gh_ost_test;
10+
delimiter ;;
11+
create event gh_ost_test
12+
on schedule every 1 second
13+
starts current_timestamp
14+
ends current_timestamp + interval 60 second
15+
on completion not preserve
16+
enable
17+
do
18+
begin
19+
insert into gh_ost_test values (null, 11, 23);
20+
insert into gh_ost_test values (null, 13, 23);
21+
insert into gh_ost_test values (null, floor(rand()*pow(2,32)), floor(rand()*pow(2,32)));
22+
end ;;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--alter="change column c2 c3 int not null" --approve-renamed-columns

localtests/unsigned-rename/create.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id int auto_increment,
4+
i int not null,
5+
bi bigint not null,
6+
iu int unsigned not null,
7+
biu bigint unsigned not null,
8+
primary key(id)
9+
) auto_increment=1;
10+
11+
drop event if exists gh_ost_test;
12+
delimiter ;;
13+
create event gh_ost_test
14+
on schedule every 1 second
15+
starts current_timestamp
16+
ends current_timestamp + interval 60 second
17+
on completion not preserve
18+
enable
19+
do
20+
begin
21+
insert into gh_ost_test values (null, -2147483647, -9223372036854775807, 4294967295, 18446744073709551615);
22+
set @last_insert_id := cast(last_insert_id() as signed);
23+
update gh_ost_test set i=-2147483647+@last_insert_id, bi=-9223372036854775807+@last_insert_id, iu=4294967295-@last_insert_id, biu=18446744073709551615-@last_insert_id where id < @last_insert_id order by id desc limit 1;
24+
end ;;

localtests/unsigned-rename/extra_args

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--alter="change column iu iu_renamed int unsigned not null" --approve-renamed-columns
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
id, i, bi, iu_renamed, biu

0 commit comments

Comments
 (0)