[MDEV-21451] (Feature) Database name missing from Slow Query Log entires Created: 2020-01-09  Updated: 2020-02-14  Resolved: 2020-02-14

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 10.3.20
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Johnathan Elmore Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: need_feedback
Environment:

RHEL 7



 Description   

When searching through the Slow Query Log we cannot identify the database which had the slow query. We have a number of databases on our instances, most of which do not include the name of the database in the query itself.

It would be helpful to include the name of the database somewhere in the log entry. One recommendation is to place it on the same line as the User (user@host/database).



 Comments   
Comment by Elena Stepanova [ 2020-01-13 ]

It already has the database field, it is called db in the log table and Schema in the log file (I'm not sure which of them you are talking about).
Naturally, it is populated with the current default database name, if any; but it's the only important one, because if you don't have a current database or you are using tables from different ones, table names will be fully qualified anyway.

MariaDB [(none)]> create database test;
Query OK, 1 row affected (0.000 sec)
 
MariaDB [(none)]> use test;
Database changed
MariaDB [test]> set long_query_time=0.1;
Query OK, 0 rows affected (0.000 sec)
 
MariaDB [test]> create table t1 as select sleep(0.5);
Query OK, 1 row affected (0.805 sec)
Records: 1  Duplicates: 0  Warnings: 0

log table

    start_time: 2020-01-13 15:43:02.474999
     user_host: root[root] @ localhost [::1]
    query_time: 00:00:00.804504
     lock_time: 00:00:00.204743
     rows_sent: 0
 rows_examined: 0
            db: test
last_insert_id: 0
     insert_id: 0
     server_id: 1
      sql_text: create table t1 as select sleep(0.5)
     thread_id: 41
 rows_affected: 1

log file

# Time: 200113 15:43:02
# User@Host: root[root] @ localhost [::1]
# Thread_id: 41  Schema: test  QC_hit: No
# Query_time: 0.804504  Lock_time: 0.204743  Rows_sent: 0  Rows_examined: 0
# Rows_affected: 1  Bytes_sent: 50
use test;
SET timestamp=1578922982;
create table t1 as select sleep(0.5);

Generated at Thu Feb 08 09:07:14 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.