Bug #72364 insert ignore was not rollbacked after KILL QUERY
Submitted: 17 Apr 2014 9:46 Modified: 18 Nov 2019 22:53
Reporter: zhai weixiang (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.5.37 OS:Any
Assigned to: CPU Architecture:Any

[17 Apr 2014 9:46] zhai weixiang
Description:
mysql> create table t1 (a int auto_increment primary key, b int ,c int);
mysql> insert into t1 select NULL, rand()*10000, rand()*10000 ;
mysql> insert into t1 select NULL, rand()*10000, rand()*10000  from t1 a;
mysql> insert into t1 select NULL, rand()*10000, rand()*10000  from t1 a;
mysql> insert into t1 select NULL, rand()*10000, rand()*10000  from t1 a;
.....
mysql> select count(*) from  t1;
+----------+
| count(*) |
+----------+
|  1849344 |
+----------+
1 row in set (0.39 sec)

mysql> create table t2 like t1;
Query OK, 0 rows affected (0.00 sec)

mysql> insert ignore into t2 select * from t1;
^CCtrl-C -- sending "KILL QUERY 2" to server ...
Ctrl-C -- query aborted.
Query OK, 0 rows affected (1.48 sec)

mysql> select count(*) from t2;
+----------+
| count(*) |
+----------+
|   203525 |
+----------+
1 row in set (0.04 sec)

mysql> select count(*) from t1;
+----------+
| count(*) |
+----------+
|  1849344 |
+----------+
1 row in set (0.40 sec)

mysql> show create table t1\G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `a` int(11) NOT NULL AUTO_INCREMENT,
  `b` int(11) DEFAULT NULL,
  `c` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=2031653 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

mysql> show create table t2\G
*************************** 1. row ***************************
       Table: t2
Create Table: CREATE TABLE `t2` (
  `a` int(11) NOT NULL AUTO_INCREMENT,
  `b` int(11) DEFAULT NULL,
  `c` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=219079 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

How to repeat:
described above

Suggested fix:
I don't know... seems this bug only affects 5.5.  MySQL5.6 is ok
[17 Apr 2014 11:28] MySQL Verification Team
Thank you for the bug report. Verified as described.
[17 Apr 2014 15:43] zhai weixiang
In order to find the root cause , I enabled DEBUG ,and start mysqld:
sudo /u01/my55/bin/mysqld --defaults-file=/u01/my55/my.cnf --debug=d,info,error,query,general,where:O,/tmp/mysqld.trace  -uroot

after kill QUERY "insert ...ignore", the server was crashed , and bellow is error message:

mysqld: /u01/project/mysql-5.5.37/sql/protocol.cc:518: void Protocol::end_statement(): Assertion `0' failed.
15:37:04 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.

key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=2
max_threads=5000
thread_count=1
connection_count=1
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 1986981 K  bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

Thread pointer: 0x95dc510
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 7fb6b0b8fe38 thread_stack 0x174000
/u01/my55/bin/mysqld(my_print_stacktrace+0x35)[0x8cbc97]
/u01/my55/bin/mysqld(handle_fatal_signal+0x406)[0x75923a]
/lib64/libpthread.so.0[0x3038e0f520]
/lib64/libc.so.6(gsignal+0x35)[0x3888832a45]
/lib64/libc.so.6(abort+0x175)[0x3888834225]
/lib64/libc.so.6(__assert_fail+0xf5)[0x388882b9d5]
/u01/my55/bin/mysqld(_ZN8Protocol13end_statementEv+0x24c)[0x5690a4]
/u01/my55/bin/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x1d57)[0x5f361e]
/u01/my55/bin/mysqld(_Z10do_commandP3THD+0x293)[0x5f16b7]
/u01/my55/bin/mysqld(_Z24do_handle_one_connectionP3THD+0x199)[0x6d3b66]
/u01/my55/bin/mysqld(handle_one_connection+0x33)[0x6d36a4]
/lib64/libpthread.so.0[0x3038e077e1]
/lib64/libc.so.6(clone+0x6d)[0x38888e68ed]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (7fb6a4004c90): insert ignore into t2 select * from t1
Connection ID (thread ID): 1
Status: NOT_KILLED
[18 Apr 2014 9:14] zhai weixiang
In function send_kill_message, KILL operation was treated as a fatal error. This bug was fixed in MySQL5.6 (I don't know the exact revision, Can anyone help me to find  it out ?)

quoted from 5.5.37:
  inline void send_kill_message() const
  {
    int err= killed_errno();
    if (err)
    {
      if ((err == KILL_CONNECTION) && !shutdown_in_progress)
        err = KILL_QUERY;
      my_message(err, ER(err), MYF(0));
    }
  }

quoted code from 5.6.17
  inline void send_kill_message() const
  {
    int err= killed_errno();
    if (err && !get_stmt_da()->is_set())
    {
      if ((err == KILL_CONNECTION) && !shutdown_in_progress)
        err = KILL_QUERY;
      /*
        KILL is fatal because:
        - if a condition handler was allowed to trap and ignore a KILL, one
        could create routines which the DBA could not kill
        - INSERT/UPDATE IGNORE should fail: if KILL arrives during
        JOIN::optimize(), statement cannot possibly run as its caller expected
        => "OK" would be misleading the caller.
      */
      my_message(err, ER(err), MYF(ME_FATALERROR));
    }
  }

I simply changed the param passed to my_message (use MYF(ME_FATALERROR)) and seems everything goes well .
[18 Nov 2019 22:53] Roy Lyseng
Posted by developer:
 
Fixed in 5.6