Bug #105540 the incorrect value of start_time field in the system table 'mysql.slow_log'
Submitted: 12 Nov 2021 7:10 Modified: 12 Nov 2021 7:40
Reporter: mengchu shi (OCA) Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: Logging Severity:S3 (Non-critical)
Version:5.7,8.0 OS:Any
Assigned to: CPU Architecture:Any

[12 Nov 2021 7:10] mengchu shi
The value of start_time field in the system table 'mysql.slow_log' is the query finish time or record logged time, not the real query start time which confuses the slow log analysis.

this is not too hard to fix. However, this bug existed for so many years (https://bugs.mysql.com/bug.php?spm=a2o8d.corp_prod_req_detail.0.0.512d1bb7YEwN6I&id=50954), I want to know whether this is a bug or a feature now. Is there any official plan to fix this bug? Or fix may break some community tools.

How to repeat:
mysqld options:
--slow-query-log=1 --log_output=TABLE

Run a query longer then log_query_time and check the start_time.

select t1.start_time_ from (select unix_timestamp(NOW(6)) as start_time_, sleep(15))t1;
select unix_timestamp(start_time) from mysql.slow_log;

Suggested fix:
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1041,7 +1041,7 @@ bool Log_to_csv_event_handler::log_slow(THD *thd, ulonglong current_utime,

  /* store the time and user values */
  assert(table->field[SQLT_FIELD_START_TIME]->type() == MYSQL_TYPE_TIMESTAMP);
- ull2timeval(current_utime, &tv);
- ull2timeval(query_start_arg, &tv);

  table->field[SQLT_FIELD_USER_HOST]->store(user_host, user_host_len,
[12 Nov 2021 7:39] MySQL Verification Team
Hello mengchu shi,

Thank you for the report and feedback.

[12 Nov 2021 7:40] MySQL Verification Team
Thank you very much for your patch contribution, we appreciate it!

Please note that in order for us to continue the process of reviewing your contribution to MySQL, please send us a signed copy of the Oracle Contributor Agreement (OCA) as outlined in https://oca.opensource.oracle.com

Signing an OCA needs to be done only once and it's valid for all other Oracle governed Open Source projects as well.

Getting a signed/approved OCA on file will help us facilitate your contribution - this one, and others in the future.  

Please let me know, if you have any questions.

Thank you for your interest in MySQL.