summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Olav Hauglid <jon.hauglid@sun.com>2009-12-10 13:02:37 +0100
committerJon Olav Hauglid <jon.hauglid@sun.com>2009-12-10 13:02:37 +0100
commit0b874e3e09570250acd00e355bfb92c77dbd3ca5 (patch)
treec7882ec1d412110aa5f5f278c9d7d39720d0a95e
parent84e35f5e1c627a7129b3a4d79140219de81acb1e (diff)
downloadmariadb-git-0b874e3e09570250acd00e355bfb92c77dbd3ca5.tar.gz
Backport of revno: 2617.68.43
Bug #47335 assert in get_table_share The assert would happen if ALTER VIEW was used to alter a view (existing or non-existing) and a temporary table with the same name already existed. The assert is triggered if the current statement does not have a MDL lock on the view to be altered. This would happen because open_table() would open the temporary table instead and MDL locks are not taken for temporary tables (since they are local to one connection). The patch changes open_type for CREATE/ALTER VIEW to OT_BASE_ONLY. This prevents open_table() from trying to open a temporary table with the same name should one exist. Now the view will be altered if it exists or ER_NO_SUCH_TABLE will be reported if it does not. Test case added to view.test
-rw-r--r--mysql-test/r/view.result17
-rw-r--r--mysql-test/t/view.test21
-rw-r--r--sql/sql_view.cc1
3 files changed, 39 insertions, 0 deletions
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 7e9739173df..cb53bf462f5 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -3959,3 +3959,20 @@ DROP TABLE t1;
# -----------------------------------------------------------------
# -- End of 5.1 tests.
# -----------------------------------------------------------------
+#
+# Bug #47335 assert in get_table_share
+#
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+CREATE TEMPORARY TABLE t1 (id INT);
+ALTER VIEW t1 AS SELECT 1 AS f1;
+ERROR 42S02: Table 'test.t1' doesn't exist
+DROP TABLE t1;
+CREATE VIEW v1 AS SELECT 1 AS f1;
+CREATE TEMPORARY TABLE v1 (id INT);
+ALTER VIEW v1 AS SELECT 2 AS f1;
+DROP TABLE v1;
+SELECT * FROM v1;
+f1
+2
+DROP VIEW v1;
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index c3ff58880c9..13a557dda60 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -3906,3 +3906,24 @@ DROP TABLE t1;
--echo # -----------------------------------------------------------------
--echo # -- End of 5.1 tests.
--echo # -----------------------------------------------------------------
+
+--echo #
+--echo # Bug #47335 assert in get_table_share
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP VIEW IF EXISTS v1;
+--enable_warnings
+
+CREATE TEMPORARY TABLE t1 (id INT);
+--error ER_NO_SUCH_TABLE
+ALTER VIEW t1 AS SELECT 1 AS f1;
+DROP TABLE t1;
+
+CREATE VIEW v1 AS SELECT 1 AS f1;
+CREATE TEMPORARY TABLE v1 (id INT);
+ALTER VIEW v1 AS SELECT 2 AS f1;
+DROP TABLE v1;
+SELECT * FROM v1;
+DROP VIEW v1;
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 0f920bca101..6d2836afc0d 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -397,6 +397,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
lex->link_first_table_back(view, link_to_local);
view->open_strategy= TABLE_LIST::OPEN_STUB;
view->lock_strategy= TABLE_LIST::EXCLUSIVE_MDL;
+ view->open_type= OT_BASE_ONLY;
if (open_and_lock_tables(thd, lex->query_tables))
{