Bug #110098 add database message into slow log file
Submitted: 16 Feb 2023 11:57 Modified: 16 Feb 2023 12:32
Reporter: bin wang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:Ver 8.0.32 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[16 Feb 2023 11:57] bin wang
Description:
when there are too many slow query in the slow.log, we have to  look forward to search the keyword "use" to find which databases the slow query belongs.
It is not friendly for dba to analyze slow query and not  convenient  for slow log
auto collecting and analyze  sed/awk .

 

How to repeat:
# Time: 2022-02-16T01:59:18.368780Z
# User@Host: root[root] @ localhost [::1]  Id:     3
# Query_time: 1.006281  Lock_time: 0.000755 Rows_sent: 2  Rows_examined: 1034  
use test;
select count(*) sbtest1;
# Time: 2022-02-16T02:01:18.368780Z
# User@Host: root[root] @ localhost [::1]  Id:     3
# Query_time: 1.0081  Lock_time: 0.000755 Rows_sent: 2  Rows_examined: 1034
select count(*) sbtest2;
...............many slow query ..............
.............................................
# Time: 2022-02-16T02:02:18.368780Z
# User@Host: root[root] @ localhost [::1]  Id:     3
# Query_time: 1.12381  Lock_time: 0.000755 Rows_sent: 2  Rows_examined: 1034
select count(*) sbtest3;
# Time: 2022-02-16T02:05:18.368780Z
# User@Host: root[root] @ localhost [::1]  Id:     3
# Query_time: 1.466281  Lock_time: 0.000755 Rows_sent: 2  Rows_examined: 1034
select count(*) sbtest4;
# Time: 2022-02-16T02:06:18.368780Z
# User@Host: root[root] @ localhost [::1]  Id:     3
# Query_time: 1.1550281  Lock_time: 0.000755 Rows_sent: 2  Rows_examined: 1034
select count(*) sbtest5;
# Time: 2022-02-16T02:09:18.368780Z
# User@Host: root[root] @ localhost [::1]  Id:     3
# Query_time: 1.13292  Lock_time: 0.000755 Rows_sent: 2  Rows_examined: 1034
select count(*) sbtest6;

Suggested fix:

add a database name  in every query when print a slow query 

# Time: 2022-02-16T02:06:18.368780Z
# User@Host: root[root] @ localhost [::1]  Id:     3
# Query_time: 1.181 Lock_time: 0.755 Rows_sent: 2 Rows_examined:1034 Database:test
select count(*) sbtest5;

+++ mysql-8.0.32/sql/log.cc	2023-02-16 19:26:00.155830417 +0800
@@ -755,7 +755,8 @@
             " Sort_rows: %lu Sort_scan_count: %lu"
             " Created_tmp_disk_tables: %lu"
             " Created_tmp_tables: %lu"
-            " Start: %s End: %s\n",
+            " Start: %s End: %s"
+	    " Database: %s\n",
[16 Feb 2023 11:58] bin wang
suggested add  patch

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: log.patch (application/octet-stream, text), 994 bytes.

[16 Feb 2023 12:32] MySQL Verification Team
Hello bin wang,

Thank you for the report and contribution.

regards,
Umesh