diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 87d322cf7fa..ac33bbc6a7e 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -900,7 +900,7 @@ void partition_info::vers_set_hist_part(THD *thd) if (vers_info->interval.is_set()) { - if (vers_info->hist_part->range_value > thd->system_time) + if (vers_info->hist_part->range_value > thd->systime()) return; partition_element *next= NULL; @@ -911,7 +911,7 @@ void partition_info::vers_set_hist_part(THD *thd) while ((next= it++) != vers_info->now_part) { vers_info->hist_part= next; - if (next->range_value > thd->system_time) + if (next->range_value > thd->systime()) return; } goto warn; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index f10a5e51b59..c696ee897f2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -819,8 +819,7 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock) // Must be reset to handle error with THD's created for init of mysqld lex->current_select= 0; start_utime= utime_after_query= 0; - system_time= 0; - system_time_sec_part= 0; + system_time.start.val= system_time.sec= system_time.sec_part= 0; utime_after_lock= 0L; progress.arena= 0; progress.report_to_client= 0; diff --git a/sql/sql_class.h b/sql/sql_class.h index e5f9328703f..74950cd4243 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2418,8 +2418,6 @@ public: // track down slow pthread_create ulonglong prior_thr_create_utime, thr_create_utime; ulonglong utime_after_query; - my_time_t system_time; - ulong system_time_sec_part; // Process indicator struct { @@ -3430,30 +3428,37 @@ public: { query_start_sec_part_used=1; return start_time_sec_part; } MYSQL_TIME query_start_TIME(); -private: - bool system_time_ge(my_time_t secs, ulong usecs) - { - return (system_time == secs && system_time_sec_part >= usecs) || - system_time > secs; - } + struct { + my_hrtime_t start; + my_time_t sec; + ulong sec_part; + } system_time; + ulong systime_sec_part() { return system_time.sec_part; } + my_time_t systime() { return system_time.sec; } + +private: void set_system_time() { my_hrtime_t hrtime= my_hrtime(); - my_time_t secs= hrtime_to_my_time(hrtime); - ulong usecs= hrtime_sec_part(hrtime); - if (system_time_ge(secs, usecs)) + my_time_t sec= hrtime_to_my_time(hrtime); + ulong sec_part= hrtime_sec_part(hrtime); + if (sec > system_time.sec || + (sec == system_time.sec && sec_part > system_time.sec_part) || + hrtime.val < system_time.start.val) { - if (++system_time_sec_part == HRTIME_RESOLUTION) - { - ++system_time; - system_time_sec_part= 0; - } + system_time.sec= sec; + system_time.sec_part= sec_part; } else { - system_time= secs; - system_time_sec_part= usecs; + if (system_time.sec_part < TIME_MAX_SECOND_PART) + system_time.sec_part++; + else + { + system_time.sec++; + system_time.sec_part= 0; + } } } @@ -3468,8 +3473,8 @@ public: } else { - start_time= system_time; - start_time_sec_part= system_time_sec_part; + start_time= system_time.sec; + start_time_sec_part= system_time.sec_part; } PSI_CALL_set_thread_start_time(start_time); } diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 239e8098ffd..18d991a6f72 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -1574,7 +1574,7 @@ static bool check_vers_constants(THD *thd, partition_info *part_info) my_tz_OFFSET0->TIME_to_gmt_sec(<ime, &error); if (error) goto err; - if (vers_info->hist_part->range_value <= thd->system_time) + if (vers_info->hist_part->range_value <= thd->systime()) vers_info->hist_part= el; } return 0; @@ -5314,7 +5314,7 @@ that are reorganised. if (*fast_alter_table && tab_part_info->vers_info->interval.is_set()) { partition_element *hist_part= tab_part_info->vers_info->hist_part; - if (hist_part->range_value <= thd->system_time) + if (hist_part->range_value <= thd->systime()) hist_part->part_state= PART_CHANGED; } } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index fa9dc2d5c6c..2ebcb057c32 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5872,7 +5872,7 @@ opt_versioning_rotation: opt_versioning_interval_start: /* empty */ { - $$= thd->system_time; + $$= thd->systime(); } | remember_tok_start STARTS_SYM ulong_num { diff --git a/sql/table.cc b/sql/table.cc index 59bff2f6f42..4f90d429ce5 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7764,8 +7764,8 @@ void TABLE::vers_update_fields() { if (!vers_write) return; - if (vers_start_field()->store_timestamp(in_use->system_time, - in_use->system_time_sec_part)) + if (vers_start_field()->store_timestamp(in_use->systime(), + in_use->systime_sec_part())) DBUG_ASSERT(0); } else @@ -7780,8 +7780,8 @@ void TABLE::vers_update_fields() void TABLE::vers_update_end() { - if (vers_end_field()->store_timestamp(in_use->system_time, - in_use->system_time_sec_part)) + if (vers_end_field()->store_timestamp(in_use->systime(), + in_use->systime_sec_part())) DBUG_ASSERT(0); } @@ -8622,9 +8622,9 @@ bool TR_table::update(ulonglong start_id, ulonglong end_id) if (!table && open()) return true; - timeval start_time= {thd->system_time, long(thd->system_time_sec_part)}; + timeval start_time= {thd->systime(), long(thd->systime_sec_part())}; thd->set_start_time(); - timeval end_time= {thd->system_time, long(thd->system_time_sec_part)}; + timeval end_time= {thd->systime(), long(thd->systime_sec_part())}; store(FLD_TRX_ID, start_id); store(FLD_COMMIT_ID, end_id); store(FLD_BEGIN_TS, start_time);