diff --git a/mysql-test/main/vector_innodb.result b/mysql-test/main/vector_innodb.result index 8a54494fe10..329da2a7159 100644 --- a/mysql-test/main/vector_innodb.result +++ b/mysql-test/main/vector_innodb.result @@ -210,3 +210,20 @@ v commit; drop table t; set global mhnsw_max_cache_size= default; +# +# MDEV-35319 ER_LOCK_DEADLOCK not detected upon DML on table with vector key, server crashes +# +create table t (pk int, b vector(1) not null, vector(b), primary key (pk)) engine=innodb; +insert into t values (1,0x31313131),(2,0x32323232); +start transaction; +insert into t values (3,0x33333333); +connect con1,localhost,root; +DELETE from t; +connection default; +set innodb_lock_wait_timeout= 1; +delete from t; +rollback; +connection con1; +ERROR 40001: Deadlock found when trying to get lock; try restarting transaction +drop table t; +disconnect con1; diff --git a/mysql-test/main/vector_innodb.test b/mysql-test/main/vector_innodb.test index d63a6499de0..76f196a6c66 100644 --- a/mysql-test/main/vector_innodb.test +++ b/mysql-test/main/vector_innodb.test @@ -206,3 +206,28 @@ commit; --enable_view_protocol drop table t; set global mhnsw_max_cache_size= default; + +--echo # +--echo # MDEV-35319 ER_LOCK_DEADLOCK not detected upon DML on table with vector key, server crashes +--echo # +create table t (pk int, b vector(1) not null, vector(b), primary key (pk)) engine=innodb; +insert into t values (1,0x31313131),(2,0x32323232); +start transaction; +insert into t values (3,0x33333333); + +--connect con1,localhost,root +--send DELETE from t + +--connection default +--let $show_statement= show processlist +--let $field= State +--let $condition= = 'Updating' +--source include/wait_show_condition.inc +set innodb_lock_wait_timeout= 1; +delete from t; +rollback; +--connection con1 +--error ER_LOCK_DEADLOCK +--reap +drop table t; +--disconnect con1 diff --git a/sql/vector_mhnsw.cc b/sql/vector_mhnsw.cc index a67de708ec7..2669706f47e 100644 --- a/sql/vector_mhnsw.cc +++ b/sql/vector_mhnsw.cc @@ -1386,8 +1386,11 @@ int mhnsw_invalidate(TABLE *table, const uchar *rec, KEY *keyinfo) TABLE *graph= table->hlindex; handler *h= table->file; MHNSW_Share *ctx; - bool use_ctx= !MHNSW_Share::acquire(&ctx, table, true); + + int err= MHNSW_Share::acquire(&ctx, table, true); SCOPE_EXIT([ctx, table](){ ctx->release(table); }); + if (err) + return err; /* metadata are checked on open */ DBUG_ASSERT(graph); @@ -1413,12 +1416,9 @@ int mhnsw_invalidate(TABLE *table, const uchar *rec, KEY *keyinfo) if (int err= graph->file->ha_update_row(graph->record[1], graph->record[0])) return err; - if (use_ctx) - { - graph->file->position(graph->record[0]); - FVectorNode *node= ctx->get_node(graph->file->ref); - node->deleted= true; - } + graph->file->position(graph->record[0]); + FVectorNode *node= ctx->get_node(graph->file->ref); + node->deleted= true; return 0; }