Skip to content

Commit 9ef20ac

Browse files
committed
MDEV-37068 Can't find record in 't1' on INSERT to Vector table
ER_DUP_ENTRY only rolls back one current statement, it doesn't abort the transaction. Thus MHNSW_Trx has to register for "statement transaction" and support "statement rollback".
1 parent a158bbb commit 9ef20ac

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

mysql-test/main/vector_innodb.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,4 +360,18 @@ drop table t;
360360
#
361361
create table t (c1 varchar(1024) not null,c2 vector(1) not null, unique key c1(c1), vector key c2 (c2)) engine=innodb default charset=utf8mb3 ;
362362
ERROR 42000: Primary key was too long for vector indexes, max length is 256 bytes
363+
#
364+
# MDEV-37068 Can't find record in 't1' on INSERT to Vector table
365+
#
366+
SET sql_mode='';
367+
create table t1 (v vector (1) not null,vector vec (v),unique vu (v)) engine=innodb;
368+
start transaction;
369+
insert t1 values (10), (20);
370+
ERROR 23000: Duplicate entry '\x00\x00\x00\x00' for key 'vu'
371+
insert t1 values (1);
372+
Warnings:
373+
Warning 4078 Cannot cast 'int' as 'vector' in assignment of `test`.`t1`.`v`
374+
Warning 1292 Incorrect vector value: '1' for column `test`.`t1`.`v` at row 1
375+
drop table t1;
376+
set sql_mode=default;
363377
# End of 11.8 tests

mysql-test/main/vector_innodb.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,16 @@ drop table t;
356356
--error ER_TOO_LONG_KEY
357357
create table t (c1 varchar(1024) not null,c2 vector(1) not null, unique key c1(c1), vector key c2 (c2)) engine=innodb default charset=utf8mb3 ;
358358

359+
--echo #
360+
--echo # MDEV-37068 Can't find record in 't1' on INSERT to Vector table
361+
--echo #
362+
SET sql_mode='';
363+
create table t1 (v vector (1) not null,vector vec (v),unique vu (v)) engine=innodb;
364+
start transaction;
365+
--error ER_DUP_ENTRY
366+
insert t1 values (10), (20);
367+
insert t1 values (1);
368+
drop table t1;
369+
set sql_mode=default;
370+
359371
--echo # End of 11.8 tests

sql/vector_mhnsw.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,11 @@ int MHNSW_Trx::do_savepoint_rollback(THD *thd, void *)
650650
return 0;
651651
}
652652

653-
int MHNSW_Trx::do_rollback(THD *thd, bool)
653+
int MHNSW_Trx::do_rollback(THD *thd, bool all)
654654
{
655+
if (!all && thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
656+
return do_savepoint_rollback(thd, nullptr);
657+
655658
MHNSW_Trx *trx_next;
656659
for (auto trx= static_cast<MHNSW_Trx*>(thd_get_ha_data(thd, &tp));
657660
trx; trx= trx_next)
@@ -663,8 +666,11 @@ int MHNSW_Trx::do_rollback(THD *thd, bool)
663666
return 0;
664667
}
665668

666-
int MHNSW_Trx::do_commit(THD *thd, bool)
669+
int MHNSW_Trx::do_commit(THD *thd, bool all)
667670
{
671+
if (!all && thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
672+
return 0;
673+
668674
MHNSW_Trx *trx_next;
669675
for (auto trx= static_cast<MHNSW_Trx*>(thd_get_ha_data(thd, &tp));
670676
trx; trx= trx_next)
@@ -734,8 +740,9 @@ MHNSW_Trx *MHNSW_Trx::get_from_thd(TABLE *table, bool for_update)
734740
thd_set_ha_data(thd, &tp, trx);
735741
if (!trx->next)
736742
{
737-
bool all= thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
738-
trans_register_ha(thd, all, &tp, 0);
743+
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
744+
trans_register_ha(thd, true, &tp, 0);
745+
trans_register_ha(thd, false, &tp, 0);
739746
}
740747
}
741748
trx->refcnt++;

0 commit comments

Comments
 (0)