3

I'm running MySql5.7 with slow query logging enabled, and the log includes more metadata than is mentioned by the docs; these three lines are printed before each query:

# Time: 2025-02-18T14:25:16.286041Z
# User@Host: root[root] @ localhost []  Id: 261083
# Query_time: 3.677193  Lock_time: 0.001193 Rows_sent: 1  Rows_examined: 4334365

The docs explain that third line only:

each statement written to the log is preceded by a line that begins with a # character and has these fields (with all fields on a single line):

  • Query_time
  • Lock_time
  • Rows_sent
  • Rows_examined

Of the other two lines, most of the fields are obvious; but does anybody know what the Id field represents? It is different for most of the entries in my slow log, but in some cases there are several which have the same Id.

Vince Bowdren
  • 439
  • 2
  • 18

2 Answers2

4

Does anybody know what the Id field represents?

The Id represents the thread ID of the MySQL session/connection that executed the query.


How to verify ?

I have enabled slow log and executed

SELECT SLEEP(100);

On another session i run SHOW PROCESSLIST(sorry for the image)

enter image description here

The output on the log file

select sleep(100);
# Time: 2025-02-18T17:30:17.642235Z
# User@Host: root[root] @ localhost [::1]  Id:    10
# Query_time: 100.001983  Lock_time: 0.000000 Rows_sent: 1  Rows_examined: 1
SET timestamp=1739899717;

Repeat the same steps after disconnecting/connecting again , you will see the Id will change.

Note. I have used MySQL 8+ , but will be the same in MySQL 5.7


It is different for most of the entries in my slow log, but in some cases there are several which have the same Id

If I have an open connection and I will execute let's say 5 different slow queries without closing the connection/session then the id in the slow log would be the same for those 5 queries.

In simple words, if the id is identical for some queries, it means those queries were executed from the same connection

Ergest Basha
  • 5,369
  • 3
  • 7
  • 22
1

The only(?) use for the "id" in the PROCESSLIST is to KILL a process.

There is probably no use for the id when looking at the slowlog.

Rick James
  • 80,479
  • 5
  • 52
  • 119