Description:
When a long query gets aborted due to the client shutdown, or its MySQL session gets killed, it does not get slow logged.
This is a serious flaw for investigating locking and contention issues, as the culprit query will be missing, and only victims appear in the slow log.
Let's say the culprit query holds locks for a long time, leading to other queries failing with innodb lock wait timeout, but the culprit gets killed before it ends, we will find only the victims in the slow log.
Now, when the query gets killed with the "kill query" command, it will get logged as expected.
Not sure what has changed here, as an older bug describes that both were logged, and only the slow log table method was not working:
https://bugs.mysql.com/bug.php?id=98046
How to repeat:
-- session 1
mysql > select @@version,@@log_output,@@slow_query_log,@@long_query_time;
+-----------+--------------+------------------+-------------------+
| @@version | @@log_output | @@slow_query_log | @@long_query_time |
+-----------+--------------+------------------+-------------------+
| 8.4.6 | FILE | 1 | 1.000000 |
+-----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql > select sleep(100);
ERROR 2013 (HY000): Lost connection to MySQL server during query
-- session 2
mysql > kill 22;
(and kill the next re-tries as the client reconnects)
No entry in the slow log, regardless of time spent.
But when I do:
mysql > kill query 28;
The slow log has:
# Time: 2025-09-10T14:51:35.842761Z
# User@Host: msandbox[msandbox] @ localhost [] Id: 28
# Query_time: 7.733090 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 1 Thread_id: 28 Errno: 0 Killed: 0 Bytes_received: 24 Bytes_sent: 58 Read_first: 0 Read_last: 0 Read_key: 0 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 0 Sort_merge_passes: 0 Sort_range_count: 0 Sort_rows: 0 Sort_scan_count: 0 Created_tmp_disk_tables: 0 Created_tmp_tables: 0 Start: 2025-09-10T14:51:28.109671Z End: 2025-09-10T14:51:35.842761Z
SET timestamp=1757515888;
select sleep(100);
From the log_slow_extra extension, there is another issue - "Errno: 0 Killed: 0" which I believe is not correct.
Suggested fix:
If the killed query reached long_query_time, log it as usual in the slow log, even if its session was killed.