Bug #51099 Assertion in mysql_multi_delete_prepare()
Submitted: 11 Feb 2010 14:16 Modified: 16 Nov 2010 2:36
Reporter: Philip Stoev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S2 (Serious)
Version:5.1, 5.5 OS:Any
Assigned to: Jon Olav Hauglid CPU Architecture:Any

[11 Feb 2010 14:16] Philip Stoev
Description:
When executing a DDL workload with autocommit=on, mysqld asserted as follows:

mysqld: sql_delete.cc:556: int mysql_multi_delete_prepare(THD*): Assertion `target_tbl->correspondent_table->view && target_tbl->correspondent_table->merge_underlying_list && target_tbl->correspondent_table->merge_underlying_list-> next_local' failed.

#6  0x000000315a42bec9 in __assert_fail () from /lib64/libc.so.6
#7  0x0000000000714b86 in mysql_multi_delete_prepare (thd=0x7fc9cc096578) at sql_delete.cc:553
#8  0x0000000000657d2c in mysql_execute_command (thd=0x7fc9cc096578) at sql_parse.cc:3116
#9  0x000000000065c6da in mysql_parse (thd=0x7fc9cc096578, inBuf=0x3200078 "DELETE   A FROM testdb_S . t1_view1_S  AS A WHERE `pk` BETWEEN 2 AND 2 + 1",
    length=74, found_semicolon=0x7fc9d1734ee0) at sql_parse.cc:5589
#10 0x000000000065d2f3 in dispatch_command (command=COM_QUERY, thd=0x7fc9cc096578,
    packet=0x7fc9cc099229 "DELETE   A FROM testdb_S . t1_view1_S  AS A WHERE `pk` BETWEEN 2 AND 2 + 1", packet_length=74) at sql_parse.cc:1023
#11 0x000000000065e793 in do_command (thd=0x7fc9cc096578) at sql_parse.cc:709
#12 0x000000000064c967 in do_handle_one_connection (thd_arg=0x7fc9cc096578) at sql_connect.cc:1174
#13 0x000000000064ca36 in handle_one_connection (arg=0x7fc9cc096578) at sql_connect.cc:1113
#14 0x000000315b0073da in start_thread () from /lib64/libpthread.so.0
#15 0x000000315a4e627d in clone () from /lib64/libc.so.6

(gdb) list
548            target_tbl;
549            target_tbl= target_tbl->next_local)
550       {
551         if (!(target_tbl->table= target_tbl->correspondent_table->table))
552         {
553           DBUG_ASSERT(target_tbl->correspondent_table->view &&
554                       target_tbl->correspondent_table->merge_underlying_list &&
555                       target_tbl->correspondent_table->merge_underlying_list->
556                       next_local);
557           my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0),

(gdb) print target_tbl->correspondent_table->view
$1 = (LEX *) 0x32d07e8
(gdb) print target_tbl->correspondent_table->merge_underlying_list
$2 = (TABLE_LIST *) 0x3201a58
(gdb) print target_tbl->correspondent_table->merge_underlying_list->next_local
$3 = (TABLE_LIST *) 0x0

How to repeat:
This assertion does not appear to be readily repeatable. In the meantime, the core and the binary will be made available.
[11 Feb 2010 14:29] Philip Stoev
Core and binary:

http://mysql-systemqa.s3.amazonaws.com/var-bug51099.zip

Source:

revision-id: alik@sun.com-20100210163134-wuz4fea0hcwgdijm
date: 2010-02-10 19:31:34 +0300
build-date: 2010-02-11 14:05:09 +0200
revno: 3089
branch-nick: mysql-next-4284
[15 May 2010 8:59] Philip Stoev
Unfortunately, this is not readily repeatable. Setting this to Verified so that a fix attempt can be made based on core file. If this is not possible, please set to "Can't Repeat". Thanks.
[18 May 2010 22:39] Omer Barnir
triage: setting to SR55RC assuming information is sufficient as verified. If more information will need to be re-triaged
[19 May 2010 13:47] Jon Olav Hauglid
Unable to reproduce with mysql-trunk-runtime (5.5.5-m3). 
Closing as "Can't repeat".
Please reopen the bug if the assertion is seen again.
[26 May 2010 12:03] Matthias Leich
I just replayed this problem on
  mysql-next-mr-wl3561
which is
  mysql-next-mr ~ End of April 2010
  + wl3561
Therefor I set this bug to "Analyzing".
[16 Aug 2010 14:10] Jon Olav Hauglid
Updated stack trace from mysql-5.5-runtime-stage:

#6  0x00007faa38165941 in *__GI___assert_fail (
    assertion=0xc16128 "target_tbl->correspondent_table->view && target_tbl->correspondent_table->merge_underlying_list && target_tbl->correspondent_table->merge_underlying_list-> next_local", 
    file=<value optimized out>, line=530, function=0xc16440 "int mysql_multi_delete_prepare(THD*)")
    at assert.c:81
#7  0x0000000000869b78 in mysql_multi_delete_prepare (thd=0x7faa1c18b530)
    at /export/home/x/mysql-5.5-runtime-stage-test/sql/sql_delete.cc:530
#8  0x00000000005dea68 in mysql_execute_command (thd=0x7faa1c18b530)
    at /export/home/x/mysql-5.5-runtime-stage-test/sql/sql_parse.cc:3373
#9  0x00000000005e59ac in mysql_parse (thd=0x7faa1c18b530, 
    rawbuf=0x2e887f0 "DELETE  QUICK  A , B FROM testdb_S . t1_view2_S  AS A NATURAL JOIN testdb_N . t1_view2_N  B WHERE testdb_N . f1_1_N  () = 1 AND `pk` = 2", length=136, 
    parser_state=0x7faa29f40130)

(gdb) p target_tbl->correspondent_table->view
$2 = (st_lex_local *) 0x2e9ea00
(gdb) p target_tbl->correspondent_table->merge_underlying_list 
$3 = (TABLE_LIST *) 0x2bc3230
(gdb) p target_tbl->correspondent_table->merge_underlying_list->next_local 
$4 = (TABLE_LIST *) 0x0
[21 Sep 2010 13:55] Jon Olav Hauglid
MTR test case:

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 triggers the assert.
DELETE v2 FROM v2;

Using this test case, the bug is repeatable on 5.1 as well.
[27 Sep 2010 12:19] Matthias Leich
Some additional observation:
If I replace the 
   DELETE v2 FROM v2;
by
   DELETE FROM v2;
I get
query 'DELETE FROM v2' failed: 1395: Can not delete from join view 'test.v2'
[27 Sep 2010 15:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/119182

3146 Jon Olav Hauglid	2010-09-27
      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 only verify
      that we are trying to insert into a view, rather than also try to verify
      there are more than one underlying table.
      
      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.
[4 Oct 2010 8:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/119788

3151 Jon Olav Hauglid	2010-10-04
      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.
[4 Oct 2010 8:29] Jon Olav Hauglid
Pushed to mysql-5.5-runtime (5.5.7-rc).
[9 Nov 2010 19:49] Bugs System
Pushed into mysql-5.5 5.5.7-rc (revid:sunanda.menon@sun.com-20101109182959-otkxq8vo2dcd13la) (version source revid:sunanda.menon@sun.com-20101109182959-otkxq8vo2dcd13la) (merge vers: 5.5.7-rc) (pib:21)
[13 Nov 2010 16:21] Bugs System
Pushed into mysql-trunk 5.6.99-m5 (revid:alexander.nozdrin@oracle.com-20101113155825-czmva9kg4n31anmu) (version source revid:alexander.nozdrin@oracle.com-20101113152450-2zzcm50e7i4j35v7) (merge vers: 5.6.1-m4) (pib:21)
[13 Nov 2010 16:42] Bugs System
Pushed into mysql-next-mr (revid:alexander.nozdrin@oracle.com-20101113160336-atmtmfb3mzm4pz4i) (version source revid:vasil.dimov@oracle.com-20100629074804-359l9m9gniauxr94) (pib:21)
[16 Nov 2010 2:36] Paul DuBois
Noted in 5.5.7 changelog.

An assertion could be raised by DELETE on a view that referenced
another view which in turn (directly or indirectly) referenced more
than one table.