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",