Skip to content

Commit 7d08105

Browse files
committed
Bug#18345346 Assertion failed: table_ref->view && table_ref->table == 0
An assert was misplaced in mysql_multi_delete_prepare(), which might trigger for an attempted multi-table update on a view that was defined over multiple tables. The assert has been refined and moved out of the error check.
1 parent e5fd4ee commit 7d08105

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

mysql-test/r/delete.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,14 @@ Error 1451 Cannot delete or update a parent row: a foreign key constraint fails
559559
DEALLOCATE PREPARE stm;
560560
DROP TABLE t2, t1;
561561
DROP PROCEDURE p1;
562+
#
563+
# Bug#18345346 Assertion failed: table_ref->view && table_ref->table == 0
564+
#
565+
CREATE TABLE b(a INTEGER);
566+
CREATE VIEW y AS SELECT 1 FROM b, b AS e;
567+
CREATE VIEW x AS SELECT 1 FROM y;
568+
CREATE VIEW z AS SELECT 1 FROM x LIMIT 1;
569+
DELETE z FROM (SELECT 1) AS x, z;
570+
ERROR HY000: Can not delete from join view 'test.z'
571+
DROP VIEW z, x, y;
572+
DROP TABLE b;

mysql-test/t/delete.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,18 @@ DEALLOCATE PREPARE stm;
632632

633633
DROP TABLE t2, t1;
634634
DROP PROCEDURE p1;
635+
636+
--echo #
637+
--echo # Bug#18345346 Assertion failed: table_ref->view && table_ref->table == 0
638+
--echo #
639+
640+
CREATE TABLE b(a INTEGER);
641+
CREATE VIEW y AS SELECT 1 FROM b, b AS e;
642+
CREATE VIEW x AS SELECT 1 FROM y;
643+
CREATE VIEW z AS SELECT 1 FROM x LIMIT 1;
644+
645+
--error ER_VIEW_DELETE_MERGE_VIEW
646+
DELETE z FROM (SELECT 1) AS x, z;
647+
648+
DROP VIEW z, x, y;
649+
DROP TABLE b;

sql/sql_delete.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ int mysql_multi_delete_prepare(THD *thd, uint *table_count)
722722
// DELETE does not allow deleting from multi-table views
723723
if (table_ref->multitable_view)
724724
{
725-
DBUG_ASSERT(table_ref->view && table_ref->table == NULL);
726725
my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0),
727726
table_ref->view_db.str, table_ref->view_name.str);
728727
DBUG_RETURN(true);
@@ -736,6 +735,9 @@ int mysql_multi_delete_prepare(THD *thd, uint *table_count)
736735
DBUG_RETURN(true);
737736
}
738737

738+
// A view must be merged, and thus cannot have a TABLE
739+
DBUG_ASSERT(!table_ref->view || table_ref->table == NULL);
740+
739741
// Enable the following code if allowing LIMIT with multi-table DELETE
740742
DBUG_ASSERT(select->select_limit == 0);
741743

0 commit comments

Comments
 (0)