summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/view.result8
-rw-r--r--mysql-test/t/view.test11
-rw-r--r--sql/sql_rename.cc2
-rw-r--r--sql/sql_table.cc14
4 files changed, 35 insertions, 0 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index a7af6a30f5c..613939bfdf6 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -3836,6 +3836,14 @@ call p();
call p();
drop view a;
drop procedure p;
+#
+# Bug #44860: ALTER TABLE on view crashes server
+#
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 AS SELECT a FROM t1;
+ALTER TABLE v1;
+DROP VIEW v1;
+DROP TABLE t1;
# -----------------------------------------------------------------
# -- End of 5.1 tests.
# -----------------------------------------------------------------
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 39db92ee1bc..a788b5ab41e 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -3859,6 +3859,17 @@ drop procedure p;
###########################################################################
+
+--echo #
+--echo # Bug #44860: ALTER TABLE on view crashes server
+--echo #
+CREATE TABLE t1 (a INT);
+CREATE VIEW v1 AS SELECT a FROM t1;
+ALTER TABLE v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+
--echo # -----------------------------------------------------------------
--echo # -- End of 5.1 tests.
--echo # -----------------------------------------------------------------
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index d4331b12cd4..7cc9130cc4a 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -261,6 +261,8 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
old_alias= ren_table->table_name;
new_alias= new_table_name;
}
+ DBUG_ASSERT(new_alias);
+
build_table_filename(name, sizeof(name),
new_db, new_alias, reg_ext, 0);
if (!access(name,F_OK))
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 2744619e138..5397128855a 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -6140,6 +6140,20 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (frm_type == FRMTYPE_VIEW && !(alter_info->flags & ~ALTER_RENAME))
{
/*
+ The following branch handles "ALTER VIEW v1 /no arguments/;"
+ This feature is not documented one.
+ However, before "OPTIMIZE TABLE t1;" was implemented,
+ ALTER TABLE with no alter_specifications was used to force-rebuild
+ the table. That's why this grammar is allowed. That's why we ignore
+ it for views. So just do nothing in such a case.
+ */
+ if (!new_name)
+ {
+ my_ok(thd);
+ DBUG_RETURN(FALSE);
+ }
+
+ /*
Avoid problems with a rename on a table that we have locked or
if the user is trying to to do this in a transcation context
*/