Skip to content

Commit bd5cf02

Browse files
committed
MDEV-11741 handler::ha_reset(): Assertion `bitmap_is_set_all(&table->s->all_set)' failed or server crash in mi_reset or buffer overrun or unexpected ER_CANT_REMOVE_ALL_FIELDS
MEMORY table could be renamed into a non-extistent database. rename() is documented to return ENOENT when the source file does not exist OR when the target directory not exist. Nonexistent source .frm file is ok (table can still exist in the engine), nonexistent target directory is not. Make my_rename to use ENOTDIR for the latter case. Make RENAME TABLE issue an appropriate error ("unknown database" instead of "unknown table")
1 parent 0b3e28a commit bd5cf02

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

mysql-test/r/rename.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,7 @@ select * from t2;
133133
a
134134
1
135135
drop table tmp,t2;
136+
create table t1 (a int) engine=memory;
137+
rename table t1 to non_existent.t2;
138+
ERROR 42000: Unknown database 'non_existent'
139+
drop table t1;

mysql-test/t/rename.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,10 @@ select * from tmp;
141141
select * from t2;
142142
drop table tmp,t2;
143143

144+
#
145+
# MDEV-11741 handler::ha_reset(): Assertion `bitmap_is_set_all(&table->s->all_set)' failed or server crash in mi_reset or buffer overrun or unexpected ER_CANT_REMOVE_ALL_FIELDS
146+
#
147+
create table t1 (a int) engine=memory;
148+
--error ER_BAD_DB_ERROR
149+
rename table t1 to non_existent.t2;
150+
drop table t1;

mysys/my_rename.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ int my_rename(const char *from, const char *to, myf MyFlags)
3939
if (link(from, to) || unlink(from))
4040
{
4141
#endif
42-
my_errno=errno;
42+
if (errno == ENOENT && !access(from, F_OK))
43+
my_errno= ENOTDIR;
44+
else
45+
my_errno= errno;
4346
error = -1;
4447
if (MyFlags & (MY_FAE+MY_WME))
4548
my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno);

sql/sql_table.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5257,6 +5257,8 @@ mysql_rename_table(handlerton *base, const char *old_db,
52575257
delete file;
52585258
if (error == HA_ERR_WRONG_COMMAND)
52595259
my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER TABLE");
5260+
else if (error == ENOTDIR)
5261+
my_error(ER_BAD_DB_ERROR, MYF(0), new_db);
52605262
else if (error)
52615263
my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error);
52625264
else if (!(flags & FN_IS_TMP))

0 commit comments

Comments
 (0)