Skip to content

Commit e8cff8e

Browse files
committed
MDEV-35219 Unexpected ER_DUP_KEY after OPTIMIZE on MyISAM table with vector key
in-engine optimize can break hlindexes. let's fallback to ALTER
1 parent 8988dec commit e8cff8e

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

mysql-test/main/vector2.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,15 @@ d count(*)
292292
1 2
293293
2 1
294294
drop table t;
295+
#
296+
# MDEV-35219 Unexpected ER_DUP_KEY after OPTIMIZE on MyISAM table with vector key
297+
#
298+
create table t (v vector(1) not null default 0x30303030, vector(v)) engine=myisam;
299+
insert into t () values (),(),(),();
300+
delete from t limit 1;
301+
optimize table t;
302+
Table Op Msg_type Msg_text
303+
test.t optimize note Table does not support optimize, doing recreate + analyze instead
304+
test.t optimize status OK
305+
insert into t select * from t;
306+
drop table t;

mysql-test/main/vector2.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,13 @@ create table t (a int, v vector(1) not null, primary key (a), vector(v));
226226
insert into t values (1,vec_fromtext('[-1]')),(2,vec_fromtext('[1]')),(3,vec_fromtext('[2]'));
227227
select vec_distance_euclidean(v,vec_fromtext('[0]')) d, count(*) from t group by d order by d limit 2;
228228
drop table t;
229+
230+
--echo #
231+
--echo # MDEV-35219 Unexpected ER_DUP_KEY after OPTIMIZE on MyISAM table with vector key
232+
--echo #
233+
create table t (v vector(1) not null default 0x30303030, vector(v)) engine=myisam;
234+
insert into t () values (),(),(),();
235+
delete from t limit 1;
236+
optimize table t;
237+
insert into t select * from t;
238+
drop table t;

sql/handler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5534,7 +5534,8 @@ handler::ha_optimize(THD* thd, HA_CHECK_OPT* check_opt)
55345534
m_lock_type == F_WRLCK);
55355535
mark_trx_read_write();
55365536

5537-
return optimize(thd, check_opt);
5537+
// in-engine optimize can modify rowids, which will break hlindexes
5538+
return table->s->hlindexes() ? HA_ADMIN_TRY_ALTER : optimize(thd, check_opt);
55385539
}
55395540

55405541

0 commit comments

Comments
 (0)