From 5aae304fa0f20247dc6a11c1d45e5d268ff7820e Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 22 Nov 2017 15:24:30 +0300 Subject: [PATCH] SQL: low timer resolution hack for THD::start_time [#307] Windows platform is suffered with this problem. --- sql/sql_class.h | 30 ++++++++++++++++++++++++++++-- sql/table.cc | 8 +++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/sql/sql_class.h b/sql/sql_class.h index 29ed2121642..688b135d875 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -3323,11 +3323,37 @@ public: inline ulong query_start_sec_part() { query_start_sec_part_used=1; return start_time_sec_part; } MYSQL_TIME query_start_TIME(); + + void start_time_inc() + { + ++start_time_sec_part; + if (start_time_sec_part == HRTIME_RESOLUTION) + { + ++start_time; + start_time_sec_part= 0; + } + } + + bool start_time_ge(my_time_t secs, ulong usecs) + { + return (start_time == secs && start_time_sec_part >= usecs) || + start_time > secs; + } + inline void set_current_time() { my_hrtime_t hrtime= my_hrtime(); - start_time= hrtime_to_my_time(hrtime); - start_time_sec_part= hrtime_sec_part(hrtime); + my_time_t secs= hrtime_to_my_time(hrtime); + ulong usecs= hrtime_sec_part(hrtime); + if (start_time_ge(secs, usecs)) + { + start_time_inc(); + } + else + { + start_time= secs; + start_time_sec_part= usecs; + } #ifdef HAVE_PSI_THREAD_INTERFACE PSI_THREAD_CALL(set_thread_start_time)(start_time); #endif diff --git a/sql/table.cc b/sql/table.cc index df5504bde29..01693719585 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -8536,8 +8536,14 @@ void TR_table::store_data(ulonglong trx_id, ulonglong commit_id, timeval commit_ timeval start_time= {thd->start_time, thd->start_time_sec_part}; store(FLD_TRX_ID, trx_id); store(FLD_COMMIT_ID, commit_id); - store(FLD_COMMIT_TS, commit_ts); store(FLD_BEGIN_TS, start_time); + if (thd->start_time_ge(commit_ts.tv_sec, commit_ts.tv_usec)) + { + thd->start_time_inc(); + commit_ts.tv_sec= thd->start_time; + commit_ts.tv_usec= thd->start_time_sec_part; + } + store(FLD_COMMIT_TS, commit_ts); store_iso_level(thd->tx_isolation); }