Commit c0a0eb80 authored by Sergey Vojtovich's avatar Sergey Vojtovich Committed by Sergei Golubchik

ALTER TABLE fixes for high-level indexes

Fixes for ALTER TABLE ... ADD/DROP COLUMN, ALGORITHM=COPY.

Let quick_rm_table() remove high-level indexes along with original table.

Avoid locking uninitialized LOCK_share for INTERNAL_TMP_TABLEs.

Don't enable bulk insert when altering a table containing vector index.
InnoDB can't handle situation when bulk insert is enabled for one table
but disabled for another. We can't do bulk insert on vector index as it
does table updates currently.
parent 518f9cb7
......@@ -72,3 +72,220 @@
-t1.ibd
drop database test1;
db.opt
@@ -387,9 +387,11 @@
# ADD/DROP COLUMN, ALGORITHM=COPY
alter table t1 add column a int, algorithm=copy;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -398,12 +400,14 @@
`a` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop column a, algorithm=copy;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -415,13 +415,15 @@
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP INDEX, ALGORITHM=COPY (non-vector)
alter table t1 add index a(id), algorithm=copy;
db.opt
-t1#i#02.ibd
+t1#i#02.MYD
+t1#i#02.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -432,12 +432,14 @@
PRIMARY KEY (`id`),
KEY `a` (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop index a, algorithm=copy;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -445,13 +447,15 @@
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# CREATE/DROP INDEX, ALGORITHM=COPY (non-vector)
create index a on t1(id) algorithm=copy;
db.opt
-t1#i#02.ibd
+t1#i#02.MYD
+t1#i#02.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -460,12 +464,14 @@
PRIMARY KEY (`id`),
KEY `a` (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
-alter table t1 drop index a, algorithm=copy;
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+drop index a on t1;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -479,13 +479,15 @@
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP COLUMN IF [NOT] EXISTS, ALGORITHM=COPY (non-vector)
alter table t1 add column if not exists a int, algorithm=copy;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -494,12 +496,14 @@
`a` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop column if exists a, algorithm=copy;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -509,24 +511,27 @@
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP INDEX, ALGORITHM=COPY (vector)
alter table t1 drop index v, algorithm=copy;
db.opt
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 add vector index v(v), algorithm=copy;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -534,24 +539,27 @@
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# CREATE/DROP INDEX, ALGORITHM=COPY (vector)
alter table t1 drop index v, algorithm=copy;
db.opt
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
create vector index v on t1(v) algorithm=copy;
db.opt
-t1#i#01.ibd
+t1#i#01.MYD
+t1#i#01.MYI
+t1.MYD
+t1.MYI
t1.frm
-t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
@@ -565,5 +567,5 @@
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
+) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
......@@ -456,3 +456,178 @@ show status like 'handler_read_rnd_next';
Variable_name Value
Handler_read_rnd_next 11
drop table t1;
# Test ALTER TABLE, CREATE/DROP INDEX
create table t1 (id int auto_increment primary key, v blob not null, vector index (v));
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'),
(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'),
(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'),
(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'),
(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'),
(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'),
(x'76edfc3e4b57243f10f8423fb158713f020bda3e'),
(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'),
(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'),
(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e');
# ADD/DROP COLUMN, ALGORITHM=COPY
alter table t1 add column a int, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
`a` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop column a, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP INDEX, ALGORITHM=COPY (non-vector)
alter table t1 add index a(id), algorithm=copy;
db.opt
t1#i#02.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
KEY `a` (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop index a, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# CREATE/DROP INDEX, ALGORITHM=COPY (non-vector)
create index a on t1(id) algorithm=copy;
db.opt
t1#i#02.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
KEY `a` (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop index a, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP COLUMN IF [NOT] EXISTS, ALGORITHM=COPY (non-vector)
alter table t1 add column if not exists a int, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
`a` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 drop column if exists a, algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# ADD/DROP INDEX, ALGORITHM=COPY (vector)
alter table t1 drop index v, algorithm=copy;
db.opt
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
alter table t1 add vector index v(v), algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
# CREATE/DROP INDEX, ALGORITHM=COPY (vector)
alter table t1 drop index v, algorithm=copy;
db.opt
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
create vector index v on t1(v) algorithm=copy;
db.opt
t1#i#01.ibd
t1.frm
t1.ibd
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` blob NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
drop table t1;
......@@ -205,3 +205,79 @@ show status like 'handler_read_rnd_next';
--enable_ps2_protocol
--enable_view_protocol
drop table t1;
--echo # Test ALTER TABLE, CREATE/DROP INDEX
create table t1 (id int auto_increment primary key, v blob not null, vector index (v));
insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'),
(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'),
(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'),
(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'),
(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'),
(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'),
(x'76edfc3e4b57243f10f8423fb158713f020bda3e'),
(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'),
(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'),
(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e');
--echo # ADD/DROP COLUMN, ALGORITHM=COPY
alter table t1 add column a int, algorithm=copy;
list_files $datadir/test;
show create table t1;
alter table t1 drop column a, algorithm=copy;
list_files $datadir/test;
show create table t1;
--echo # ADD/DROP INDEX, ALGORITHM=COPY (non-vector)
alter table t1 add index a(id), algorithm=copy;
list_files $datadir/test;
show create table t1;
alter table t1 drop index a, algorithm=copy;
list_files $datadir/test;
show create table t1;
--echo # CREATE/DROP INDEX, ALGORITHM=COPY (non-vector)
create index a on t1(id) algorithm=copy;
list_files $datadir/test;
show create table t1;
if ($MTR_COMBINATION_MYISAM) {
drop index a on t1;
}
if ($MTR_COMBINATION_INNODB) {
alter table t1 drop index a, algorithm=copy;
}
list_files $datadir/test;
show create table t1;
--echo # ADD/DROP COLUMN IF [NOT] EXISTS, ALGORITHM=COPY (non-vector)
alter table t1 add column if not exists a int, algorithm=copy;
list_files $datadir/test;
show create table t1;
alter table t1 drop column if exists a, algorithm=copy;
list_files $datadir/test;
show create table t1;
--echo # ADD/DROP INDEX, ALGORITHM=COPY (vector)
alter table t1 drop index v, algorithm=copy;
list_files $datadir/test;
show create table t1;
alter table t1 add vector index v(v), algorithm=copy;
list_files $datadir/test;
show create table t1;
--echo # CREATE/DROP INDEX, ALGORITHM=COPY (vector)
if ($MTR_COMBINATION_MYISAM) {
# To be fixed to: drop index v on t1;
alter table t1 drop index v, algorithm=copy;
}
if ($MTR_COMBINATION_INNODB) {
alter table t1 drop index v, algorithm=copy;
}
list_files $datadir/test;
show create table t1;
create vector index v on t1(v) algorithm=copy;
list_files $datadir/test;
show create table t1;
drop table t1;
......@@ -9838,10 +9838,12 @@ int TABLE::hlindex_open(uint nr)
DBUG_ASSERT(nr == s->keys);
if (!hlindex)
{
mysql_mutex_lock(&s->LOCK_share);
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_lock(&s->LOCK_share);
if (!s->hlindex)
{
mysql_mutex_unlock(&s->LOCK_share);
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
TABLE_SHARE *share;
char *path= NULL;
size_t path_len= s->normalized_path.length + HLINDEX_BUF_LEN;
......@@ -9865,20 +9867,26 @@ int TABLE::hlindex_open(uint nr)
return 1;
}
mysql_mutex_lock(&s->LOCK_share);
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_lock(&s->LOCK_share);
if (!s->hlindex)
{
s->hlindex= share;
mysql_mutex_unlock(&s->LOCK_share);
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
}
else
{
mysql_mutex_unlock(&s->LOCK_share);
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
free_table_share(share);
}
}
else
mysql_mutex_unlock(&s->LOCK_share);
{
if (s->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&s->LOCK_share);
}
TABLE *table= (TABLE*)alloc_root(&mem_root, sizeof(*table));
if (!table || open_table_from_share(in_use, s->hlindex, &empty_clex_str,
db_stat, EXTRA_RECORD, in_use->open_options, table, 0))
......
......@@ -2083,6 +2083,26 @@ bool log_drop_table(THD *thd, const LEX_CSTRING *db_name,
}
static int get_hlindex_keys(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *table_name, const char *path,
uint *keys, uint *total_keys)
{
TABLE_SHARE share;
int error;
DBUG_ENTER("get_hlindex_keys");
init_tmp_table_share(thd, &share, db->str, 0, table_name->str, path, 1);
error= open_table_def(thd, &share, GTS_TABLE | GTS_USE_DISCOVERY);
if (!error)
{
*keys= share.keys;
*total_keys= share.total_keys;
}
free_table_share(&share);
DBUG_RETURN(error);
}
/**
Quickly remove a table, without any logging
......@@ -2117,7 +2137,25 @@ bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db,
delete file;
}
if (!(flags & (FRM_ONLY|NO_HA_TABLE)))
{
uint keys, total_keys;
int hlindex_error= get_hlindex_keys(thd, db, table_name, path, &keys,
&total_keys);
error|= ha_delete_table(thd, base, path, db, table_name, 0) > 0;
if (!hlindex_error)
{
char idx_path[FN_REFLEN + 1];
char *idx_path_end= strmov(idx_path, path);
for (uint i= keys; i < total_keys; i++)
{
my_snprintf(idx_path_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i);
if (ha_delete_table(thd, base, idx_path, db, table_name, 0))
error= 1;
}
}
else
error= 1;
}
if (!(flags & NO_FRM_RENAME))
{
......@@ -5374,18 +5412,17 @@ mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db,
char idx_from[FN_REFLEN + 1], idx_to[FN_REFLEN + 1];
char *idx_from_end= strmov(idx_from, from_base);
char *idx_to_end= strmov(idx_to, to_base);
TABLE_SHARE share;
uint keys, total_keys;
init_tmp_table_share(thd, &share, new_db->str, 0, new_name->str, to, 1);
if (!open_table_def(thd, &share, GTS_TABLE | GTS_USE_DISCOVERY))
if (!get_hlindex_keys(thd, new_db, new_name, to, &keys, &total_keys))
{
for (uint i= share.keys; i < share.total_keys; i++)
for (uint i= keys; i < total_keys; i++)
{
my_snprintf(idx_from_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i);
my_snprintf(idx_to_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i);
if ((error= file->ha_rename_table(idx_from, idx_to)))
{
for (; i >= share.keys; i--)
for (; i >= keys; i--)
{
my_snprintf(idx_from_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i);
my_snprintf(idx_to_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i);
......@@ -5403,7 +5440,6 @@ mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db,
rename_file_ext(to, from, reg_ext);
error= 1;
}
free_table_share(&share);
}
}
if (!error && log_query && !(flags & (FN_TO_IS_TMP | FN_FROM_IS_TMP)))
......@@ -12187,7 +12223,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
from->file->info(HA_STATUS_VARIABLE);
to->file->extra(HA_EXTRA_PREPARE_FOR_ALTER_TABLE);
if (!to->s->long_unique_table)
if (!to->s->long_unique_table && to->s->keys == to->s->total_keys)
{
to->file->ha_start_bulk_insert(from->file->stats.records,
ignore ? 0 : HA_CREATE_UNIQUE_INDEX_BY_SORT);
......@@ -12314,7 +12350,8 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
thd->progress.max_counter= from->file->records();
time_to_report_progress= MY_HOW_OFTEN_TO_WRITE/10;
if (!ignore) /* for now, InnoDB needs the undo log for ALTER IGNORE */
/* for now, InnoDB needs the undo log for ALTER IGNORE */
if (!ignore && to->s->keys == to->s->total_keys)
to->file->extra(HA_EXTRA_BEGIN_ALTER_COPY);
if (!(error= info.read_record()))
......@@ -12491,7 +12528,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
}
bulk_insert_started= 0;
if (!ignore && error <= 0)
if (!ignore && to->s->keys == to->s->total_keys && error <= 0)
{
int alt_error= to->file->extra(HA_EXTRA_END_ALTER_COPY);
if (alt_error > 0)
......
......@@ -648,7 +648,8 @@ MHNSW_Trx *MHNSW_Trx::get_from_thd(TABLE *table, bool for_update)
MHNSW_Context *MHNSW_Context::get_from_share(TABLE_SHARE *share, TABLE *table)
{
mysql_mutex_lock(&share->LOCK_share);
if (share->tmp_table == NO_TMP_TABLE)
mysql_mutex_lock(&share->LOCK_share);
auto ctx= static_cast<MHNSW_Context*>(share->hlindex->hlindex_data);
if (!ctx && table)
{
......@@ -659,7 +660,8 @@ MHNSW_Context *MHNSW_Context::get_from_share(TABLE_SHARE *share, TABLE *table)
}
if (ctx)
ctx->refcnt++;
mysql_mutex_unlock(&share->LOCK_share);
if (share->tmp_table == NO_TMP_TABLE)
mysql_mutex_unlock(&share->LOCK_share);
return ctx;
}
......
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