Skip to content

Commit

Permalink
MDEV-32839 LONG UNIQUE gives error when used with REPLACE
Browse files Browse the repository at this point in the history
calculate auto-inc value even if long duplicate check fails -
this is what the engine does for normal uniques.

auto-inc value is needed if it's a REPLACE
  • Loading branch information
vuvova committed Dec 4, 2023
1 parent 4f2d054 commit c8d0f33
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mysql-test/main/long_unique_bugs.result
Original file line number Diff line number Diff line change
Expand Up @@ -574,5 +574,27 @@ insert into t1 values (1,10),(2,20);
update t1 set b = 30 limit 1;
drop table t1;
#
# MDEV-32839 LONG UNIQUE gives error when used with REPLACE
#
create table t1 (
f1 bigint(20) not null auto_increment primary key,
f2 varchar(30) default null,
f3 varchar(30) default null,
f4 varchar(255) default null,
f5 varchar(30) default null,
f6 varchar(255) default null,
f7 varchar(255) default null,
unique problem_key (f3,f5,f6,f2,f4,f7) using hash
);
insert t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'd');
replace t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'd');
insert t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'e');
replace t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'e');
select * from t1;
f1 f2 f3 f4 f5 f6 f7
2 00004 0001009089999 netstes psit d
4 00004 0001009089999 netstes psit e
drop table t1;
#
# End of 10.5 tests
#
20 changes: 20 additions & 0 deletions mysql-test/main/long_unique_bugs.test
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,26 @@ insert into t1 values (1,10),(2,20);
update t1 set b = 30 limit 1;
drop table t1;

--echo #
--echo # MDEV-32839 LONG UNIQUE gives error when used with REPLACE
--echo #
create table t1 (
f1 bigint(20) not null auto_increment primary key,
f2 varchar(30) default null,
f3 varchar(30) default null,
f4 varchar(255) default null,
f5 varchar(30) default null,
f6 varchar(255) default null,
f7 varchar(255) default null,
unique problem_key (f3,f5,f6,f2,f4,f7) using hash
);
insert t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'd');
replace t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'd');
insert t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'e');
replace t1 (f2, f3, f4, f5, f6, f7) values ('00004', '0001009089999', '', 'netstes', 'psit', 'e');
select * from t1;
drop table t1;

--echo #
--echo # End of 10.5 tests
--echo #
5 changes: 5 additions & 0 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7639,7 +7639,12 @@ int handler::ha_write_row(const uchar *buf)
{
DBUG_ASSERT(inited == NONE || lookup_handler != this);
if ((error= check_duplicate_long_entries(buf)))
{
if (table->next_number_field && buf == table->record[0])
if (int err= update_auto_increment())
error= err;
DBUG_RETURN(error);
}
}

MYSQL_INSERT_ROW_START(table_share->db.str, table_share->table_name.str);
Expand Down

0 comments on commit c8d0f33

Please sign in to comment.