Bug #21714 Wrong NEW.value and server abort on INSERT DELAYED to a table with a trigger
Submitted: 18 Aug 2006 9:57 Modified: 23 Aug 2006 17:11
Reporter: Tomash Brechko Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Stored Routines Severity:S2 (Serious)
Version:5.0.24, 5.1 OS:Linux (Suse Linux 10)
Assigned to: Assigned Account CPU Architecture:Any

[18 Aug 2006 9:57] Tomash Brechko
Description:
INSERT DELAYED to a table with {BEFORE|AFTER} INSERT trigger gives wrong NEW.value and aborts the server.

This bug is related to bug#21483, but is not the same.

How to repeat:
First case (BEFORE INSERT trigger):

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (i INT);
CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW
  SET @a= NEW.i;

SET @a= 0;
SELECT @a;
+------+
| @a   |
+------+
| 0    |
+------+
INSERT DELAYED INTO t1 VALUES (1);
SELECT @a;
+------+
| @a   |
+------+
| NULL | <= Should be 1
+------+
INSERT DELAYED INTO t1 VALUES (1);
mysqld: field.cc:3389: virtual longlong Field_long::val_int(): Assertion `table->in_use == _current_thd()' failed.

Second case (AFTER INSERT trigger):

DROP TABLE IF EXISTS t1, t2;

CREATE TABLE t1 (i INT);
CREATE TABLE t2 (i INT);

CREATE TRIGGER t1_ai AFTER INSERT ON t1 FOR EACH ROW
  INSERT INTO t2 VALUES (NEW.i);

INSERT DELAYED INTO t1 VALUES (1);
SELECT * FROM t1;
mysqld: sql_base.cc:2559: int lock_tables(THD*, TABLE_LIST*, uint, bool*): Assertion `thd->lock == 0' failed.

Suggested fix:
Wrong value and server abort are probably unrelated problems.
[21 Aug 2006 15:35] MySQL Verification Team
5.1BK Back trace on Suse 10 32-bits

Attachment: bt-21714.txt (text/plain), 11.28 KiB.

[21 Aug 2006 15:36] MySQL Verification Team
Thank you for the bug report.
[23 Aug 2006 17:11] Tomash Brechko
This bug is a duplicate of bug#21483.

This bug reveals a part of a problem that will be fixed with a patch for bug#21483.
[23 Aug 2006 17:12] 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/10781

ChangeSet@1.2235, 2006-08-23 21:12:02+04:00, kroki@moonlight.intranet +4 -0
  BUG#21483: Server abort or deadlock on INSERT DELAYED with another
             implicit insert
  
  If the statement operates on several tables via functions or triggers,
  it is vital to execute all operations at one time, none of the actions
  can be delayed, because all tables should be locked simultaneously.
  
  The solution is to downgrade INSERT DELAYED to normal INSERT if the
  statement uses functions that access tables or triggers, or is called
  from a function or a trigger.  This also fixes bug#20497 (Trigger with
  INSERT DELAYED causes Error 1165) and bug#21714 (Wrong NEW.value and
  server abort on INSERT DELAYED to a table with a trigger).
  
  REPLACE DELAYED is handled by the same code.
[23 Aug 2006 17:18] Tomash Brechko
The patch above was erroneously linked to this report, it belongs to bug#21483, which see.
[25 Aug 2006 14:02] Konstantin Osipov
Sent review comments by email.
Not setting myself as a reviewer as Dmitri is also looking at this patch.
[25 Aug 2006 14:03] Konstantin Osipov
Sent review comments by email.
Not setting myself as a reviewer as Dmitri is also looking at this patch.