Commit 9aeefefb authored by Sergei Golubchik's avatar Sergei Golubchik

post-fixes for TRUNCATE

* fix the truncate-by-handler variant, used by InnoDB
* test that insert works after truncate, meaning graph table was emptied
* test that the vector index size is zero after truncate in MyISAM
parent 29cd7cd7
--- a/mysql-test/main/vector.result
+++ b/mysql-test/main/vector.result
@@ -305,8 +305,30 @@
create table t1 (id int auto_increment primary key, v blob not null, vector index (v));
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
+
+MyISAM file: datadir/test/t1#i#01
+Record format: Packed
+Character set: ? (0)
+Data records: 0 Deleted blocks: 0
+Recordlength: 30
+
+table description:
+Key Start Len Index Type
+1 3 6 unique varbin NULL
+2 2 1 multip. int8
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
+
+MyISAM file: datadir/test/t1#i#01
+Record format: Packed
+Character set: ? (0)
+Data records: 0 Deleted blocks: 0
+Recordlength: 30
+
+table description:
+Key Start Len Index Type
+1 3 6 unique varbin NULL
+2 2 1 multip. int8
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
select id, hex(v) from t1;
id hex(v)
......@@ -303,11 +303,14 @@ id hex(v)
drop table t1, t2;
db.opt
create table t1 (id int auto_increment primary key, v blob not null, vector index (v));
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d');
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
select * from t1;
id v
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
select id, hex(v) from t1;
id hex(v)
1 E360D63EBE554F3FCDBC523F4522193F5236083D
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
......@@ -315,6 +318,6 @@ t1 CREATE TABLE `t1` (
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
db.opt
......@@ -103,10 +103,20 @@ drop table t1, t2;
list_files $datadir/test;
create table t1 (id int auto_increment primary key, v blob not null, vector index (v));
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d');
if ($MTR_COMBINATION_MYISAM) {
--replace_result $datadir datadir
--exec $MYISAMCHK -d $datadir/test/t1#i#01
}
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
truncate table t1;
select * from t1;
if ($MTR_COMBINATION_MYISAM) {
--replace_result $datadir datadir
--exec $MYISAMCHK -d $datadir/test/t1#i#01
}
insert t1 (id, v) values (1, x'e360d63ebe554f3fcdbc523f4522193f5236083d');
select id, hex(v) from t1;
replace_result InnoDB MyISAM;
show create table t1;
drop table t1;
......
......@@ -5477,7 +5477,7 @@ handler::ha_delete_all_rows()
int err= delete_all_rows();
if (!err)
err= table->hlindexes_on_delete_all();
err= table->hlindexes_on_delete_all(false);
return err;
}
......@@ -5496,7 +5496,14 @@ handler::ha_truncate()
m_lock_type == F_WRLCK);
mark_trx_read_write();
return truncate();
int err= truncate();
if (!err && table->s->total_keys > table->s->keys)
{
if (!(err= table->hlindex_open(table->s->keys)))
err= table->hlindexes_on_delete_all(true);
}
return err;
}
......
......@@ -9945,11 +9945,11 @@ int TABLE::hlindexes_on_delete(const uchar *buf)
return 0;
}
int TABLE::hlindexes_on_delete_all()
int TABLE::hlindexes_on_delete_all(bool truncate)
{
DBUG_ASSERT(s->total_keys - s->keys == (hlindex != NULL));
if (hlindex && hlindex->in_use)
if (int err= mhnsw_delete_all(this, key_info + s->keys))
if (int err= mhnsw_delete_all(this, key_info + s->keys, truncate))
return err;
return 0;
}
......
......@@ -1798,7 +1798,7 @@ struct TABLE
int hlindexes_on_insert();
int hlindexes_on_update();
int hlindexes_on_delete(const uchar *buf);
int hlindexes_on_delete_all();
int hlindexes_on_delete_all(bool truncate);
int reset_hlindexes();
void prepare_triggers_for_insert_stmt_or_event();
......
......@@ -1249,7 +1249,7 @@ int mhnsw_invalidate(TABLE *table, const uchar *rec, KEY *keyinfo)
return 0;
}
int mhnsw_delete_all(TABLE *table, KEY *keyinfo)
int mhnsw_delete_all(TABLE *table, KEY *keyinfo, bool truncate)
{
TABLE *graph= table->hlindex;
......@@ -1258,7 +1258,8 @@ int mhnsw_delete_all(TABLE *table, KEY *keyinfo)
DBUG_ASSERT(keyinfo->algorithm == HA_KEY_ALG_VECTOR);
DBUG_ASSERT(keyinfo->usable_key_parts == 1);
if (int err= graph->file->ha_delete_all_rows())
if (int err= truncate ? graph->file->truncate()
: graph->file->delete_all_rows())
return err;
MHNSW_Context *ctx;
......
......@@ -25,7 +25,7 @@ const LEX_CSTRING mhnsw_hlindex_table_def(THD *thd, uint ref_length);
int mhnsw_insert(TABLE *table, KEY *keyinfo);
int mhnsw_first(TABLE *table, KEY *keyinfo, Item *dist, ulonglong limit);
int mhnsw_invalidate(TABLE *table, const uchar *rec, KEY *keyinfo);
int mhnsw_delete_all(TABLE *table, KEY *keyinfo);
int mhnsw_delete_all(TABLE *table, KEY *keyinfo, bool truncate);
int mhnsw_next(TABLE *table);
void mhnsw_free(TABLE_SHARE *share);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment