Bug #31906 No stmt rollback and wrong binlog if an error in {INSERT|CREATE} ... SELECT UNIO
Submitted: 29 Oct 2007 10:22 Modified: 29 Oct 2007 11:10
Reporter: Konstantin Osipov (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[29 Oct 2007 10:22] Konstantin Osipov
Description:
If an error occurs during INSERT ... SELECT ... UNION or CREATE ... SELECT ... UNOIN, the second step of SELECT processing, when the data is actually being
sent to the table/client, the statement is not rolled back, the binary log entry for the partial update is not written.

Demonstration of absence of statement rollback:

mysql> drop table if exists t1;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t1 (a int unique) engine=innodb;
Query OK, 0 rows affected (0.00 sec)

mysql> set @@autocommit=0;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t1 (a) select 1 union select 1;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from t1;
+------+
| a    |
+------+
|    1 | 
+------+
1 row in set (0.00 sec)

mysql> rollback;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t1;
Empty set (0.00 sec)

How to repeat:
drop table if exists t1;
create table t1 (a int unique) engine=innodb;
set @@autocommit=0;
insert into t1 (a) select 1 union select 1;
select * from t1;
rollback;
select * from t1;

Suggested fix:
call result->abort() if the last mysql_select in unit::exec fails.