From c4a18b6af34cee61bcb933f1b0a2597bdfcf098a Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Mon, 4 Oct 2010 10:25:04 +0200 Subject: [PATCH] Bug #51099 Assertion in mysql_multi_delete_prepare() This assert was triggered if DELETE was done on a view that referenced another view which in turn (directly or indirectly) referenced more than one table. Delete from a view referencing more than one table (a join view) is not supported and is supposed to give ER_VIEW_DELETE_MERGE_VIEW error. Before this error was reported from the multi table delete code, an assert verified that the view from the DELETE statement had more than one underlying table. However, this assert did not take into account that the view could refer to another view which in turn referenced the actual tables. This patch fixes the problem by adjusting the assert to take this possibility into account. This problem was only noticeable on debug builds of the server. On release builds, ER_VIEW_DELETE_MERGE_VIEW was correctly reported. Test case added to delete.test. --- mysql-test/r/delete.result | 15 +++++++++++++++ mysql-test/t/delete.test | 26 ++++++++++++++++++++++++++ sql/sql_delete.cc | 4 +--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/delete.result b/mysql-test/r/delete.result index 702b9348b7d..5e4adbbd6dc 100644 --- a/mysql-test/r/delete.result +++ b/mysql-test/r/delete.result @@ -509,3 +509,18 @@ CREATE TABLE t3 LIKE t1; DELETE FROM t1.*, test.t2.*, a.* USING t1, t2, t3 AS a; DROP TABLE t1, t2, t3; End of 5.1 tests +# +# Bug#51099 Assertion in mysql_multi_delete_prepare() +# +DROP TABLE IF EXISTS t1, t2; +DROP VIEW IF EXISTS v1, v2; +CREATE TABLE t1(a INT); +CREATE TABLE t2(b INT); +CREATE VIEW v1 AS SELECT a, b FROM t1, t2; +CREATE VIEW v2 AS SELECT a FROM v1; +DELETE FROM v2; +ERROR HY000: Can not delete from join view 'test.v2' +DELETE v2 FROM v2; +ERROR HY000: Can not delete from join view 'test.v2' +DROP VIEW v2, v1; +DROP TABLE t1, t2; diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test index 15aade73ab7..6a72ae9c38b 100644 --- a/mysql-test/t/delete.test +++ b/mysql-test/t/delete.test @@ -554,3 +554,29 @@ DELETE FROM t1.*, test.t2.*, a.* USING t1, t2, t3 AS a; DROP TABLE t1, t2, t3; --echo End of 5.1 tests + + +--echo # +--echo # Bug#51099 Assertion in mysql_multi_delete_prepare() +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +DROP VIEW IF EXISTS v1, v2; +--enable_warnings + +CREATE TABLE t1(a INT); +CREATE TABLE t2(b INT); +CREATE VIEW v1 AS SELECT a, b FROM t1, t2; +CREATE VIEW v2 AS SELECT a FROM v1; + +# This is a normal delete +--error ER_VIEW_DELETE_MERGE_VIEW +DELETE FROM v2; +# This is a multi table delete, check that we get the same error +# This caused the assertion. +--error ER_VIEW_DELETE_MERGE_VIEW +DELETE v2 FROM v2; + +DROP VIEW v2, v1; +DROP TABLE t1, t2; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 2f69bac917e..685ce1c7b42 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -525,9 +525,7 @@ int mysql_multi_delete_prepare(THD *thd) if (!(target_tbl->table= target_tbl->correspondent_table->table)) { DBUG_ASSERT(target_tbl->correspondent_table->view && - target_tbl->correspondent_table->merge_underlying_list && - target_tbl->correspondent_table->merge_underlying_list-> - next_local); + target_tbl->correspondent_table->multitable_view); my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0), target_tbl->correspondent_table->view_db.str, target_tbl->correspondent_table->view_name.str);