Commit c4a18b6a authored by Jon Olav Hauglid's avatar Jon Olav Hauglid

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.
parent 8322cad0
......@@ -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;
......@@ -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;
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment