Bug #79765 MySQL Slow Query log should include query generated warnings
Submitted: 23 Dec 2015 16:19 Modified: 10 Mar 17:01
Reporter: Joe Kislo Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S4 (Feature request)
Version:8.0.41 OS:Any
Assigned to: CPU Architecture:Any

[23 Dec 2015 16:19] Joe Kislo
Description:
When warnings are generated by queries logged into the slow-query log, the warnings should be captured and put out to the log.  Sometimes the warnings are very relevant as to why the query is in the slow query log.  For example this warning:
| Warning | 3170 | Memory capacity of 1536000 bytes for 'range_optimizer_max_mem_size' exceeded. Range optimization was not done for this query.

It's extremely relevant as to why something is in the slow query log.  When people run into issue #78973, it will be very useful to have the warnings available.

How to repeat:
Run a slow query that generates warnings. 
Look in the slow query log and you won't see the warnings

Suggested fix:
Output warnings to the slow query log
[10 Mar 17:01] MySQL Verification Team
Thanks for the feature request. 8.0.41 also doesn't log warning even with 
log-slow-extra=ON

mysql> select sum(b) from t force index(PRIMARY) where a in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
+--------+
| sum(b) |
+--------+
|    448 |
+--------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
---+
| Level   | Code | Message                                                                                                                     |
+-
| Warning | 3170 | Memory capacity of 10000 bytes for 'range_optimizer_max_mem_size' exceeded. Range optimization was not done for this query. |
+--
1 row in set (0.00 sec)

Slow log;
# Time: 2025-03-10T16:57:11.177115Z
# User@Host: root[root] @ localhost [127.0.0.1]  Id:     8
# Query_time: 0.000449  Lock_time: 0.000002 Rows_sent: 1  Rows_examined: 1010 Thread_id: 8 Errno: 0 Killed: 0 Bytes_received: 111 Bytes_sent: 56 Read_first: 1 Read_last: 0 Read_key: 1 Read_next: 0 Read_prev: 0 Read_rnd: 0 Read_rnd_next: 1011 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-03-10T16:57:11.176666Z End: 2025-03-10T16:57:11.177115Z
SET timestamp=1741625831;
select sum(b) from t force index(PRIMARY) where a in(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);