[Commits] 6ff2c0a: MDEV-5309 - RENAME TABLE does not check for existence of the table's engine

svoj at mariadb.org svoj at mariadb.org
Mon Feb 9 14:14:47 EET 2015


revision-id: 6ff2c0a05155f985484e23bd8611eb95f045907f
parent(s): f13939061d468a47985dee0268652a6fe2db7862
committer: Sergey Vojtovich
branch nick: 10.1
timestamp: 2015-02-09 16:12:00 +0400
message:

MDEV-5309 - RENAME TABLE does not check for existence of the table's engine

When RENAME TABLE is executed, it apparently does not check whether the engine
is available (unlike ALTER TABLE .. RENAME, which does). It means that if the
engine in question was not loaded on some reason, the table might become
unusable, since the engine won't know about the change.

With this patch RENAME TABLE fails if storage engine is not available.

---
 mysql-test/r/plugin.result | 10 ++++++++++
 mysql-test/t/plugin.test   | 11 +++++++++++
 sql/sql_table.cc           | 19 ++++++++++---------
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/mysql-test/r/plugin.result b/mysql-test/r/plugin.result
index d983817..5ee5463 100644
--- a/mysql-test/r/plugin.result
+++ b/mysql-test/r/plugin.result
@@ -321,3 +321,13 @@ UNUSABLE
 uninstall soname 'ha_example';
 select plugin_name from information_schema.plugins where plugin_library like 'ha_example%';
 plugin_name
+#
+# MDEV-5309 - RENAME TABLE does not check for existence of the table's
+#             engine
+#
+INSTALL PLUGIN example SONAME 'ha_example';
+CREATE TABLE t1(a INT) ENGINE=EXAMPLE;
+UNINSTALL PLUGIN example;
+RENAME TABLE t1 TO t2;
+ERROR HY000: Error on rename of './test/t1' to './test/t2' (errno: 1286 "Unknown error 1286")
+DROP TABLE t1;
diff --git a/mysql-test/t/plugin.test b/mysql-test/t/plugin.test
index 0655aff..ffb9765 100644
--- a/mysql-test/t/plugin.test
+++ b/mysql-test/t/plugin.test
@@ -252,3 +252,14 @@ select plugin_name from information_schema.plugins where plugin_library like 'ha
 uninstall soname 'ha_example';
 select plugin_name from information_schema.plugins where plugin_library like 'ha_example%';
 
+
+--echo #
+--echo # MDEV-5309 - RENAME TABLE does not check for existence of the table's
+--echo #             engine
+--echo #
+INSTALL PLUGIN example SONAME 'ha_example';
+CREATE TABLE t1(a INT) ENGINE=EXAMPLE;
+UNINSTALL PLUGIN example;
+--error ER_ERROR_ON_RENAME
+RENAME TABLE t1 TO t2;
+DROP TABLE t1;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index e9a1ae9..f1096da 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -5172,18 +5172,19 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
       error= my_errno;
     (void) file->ha_create_partitioning_metadata(to, from, CHF_RENAME_FLAG);
   }
-  else if (!file || !(error=file->ha_rename_table(from_base, to_base)))
+  else if (!file)
+  {
+    error= ER_UNKNOWN_STORAGE_ENGINE;
+  }
+  else if (!(error= file->ha_rename_table(from_base, to_base)))
   {
     if (!(flags & NO_FRM_RENAME) && rename_file_ext(from,to,reg_ext))
     {
-      error=my_errno;
-      if (file)
-      {
-        if (error == ENOENT)
-          error= 0; // this is ok if file->ha_rename_table() succeeded
-        else
-          file->ha_rename_table(to_base, from_base); // Restore old file name
-      }
+      error= my_errno;
+      if (error == ENOENT)
+        error= 0; // this is ok if file->ha_rename_table() succeeded
+      else
+        file->ha_rename_table(to_base, from_base); // Restore old file name
     }
   }
   delete file;


More information about the commits mailing list