diff --git a/mysql-test/main/mysqldump-system.result b/mysql-test/main/mysqldump-system.result index 7c4d06a6031..559f6f29f44 100644 --- a/mysql-test/main/mysqldump-system.result +++ b/mysql-test/main/mysqldump-system.result @@ -23,16 +23,17 @@ create table mysql.tz like mysql.time_zone_transition; alter table mysql.tz engine=innodb; insert into mysql.tz select * from mysql.time_zone_transition; set global innodb_stats_persistent=1; +set time_zone="+03:00"; +SET TIMESTAMP= UNIX_TIMESTAMP('2022-01-07 07:07:00'); ANALYZE TABLE mysql.tz PERSISTENT FOR ALL; Table Op Msg_type Msg_text mysql.tz analyze status Engine-independent statistics collected mysql.tz analyze status OK delete from mysql.index_stats where prefix_arity!=1; delete from mysql.column_stats where column_name!='Time_zone_id'; -set time_zone="+03:00"; update mysql.innodb_index_stats set last_update="2020-01-01" where database_name="mysql" and table_name="tz"; update mysql.innodb_table_stats set last_update="2020-01-01" where database_name="mysql" and table_name="tz"; -update mysql.column_stats set histogram=json_replace(histogram, '$.collected_at', '2020-01-02 03:04:05 UTC', '$.collected_by', 'this very version'); +update mysql.column_stats set histogram=json_replace(histogram, '$.collected_by', replace(json_value(histogram, '$.collected_by'), @@version, 'version')); set global innodb_stats_persistent= @save_innodb_stats_persistent; alter table mysql.time_zone_name ORDER BY Name; CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(Host 'localhost'); @@ -95,7 +96,7 @@ USE mysql; LOCK TABLES `column_stats` WRITE; /*!40000 ALTER TABLE `column_stats` DISABLE KEYS */; REPLACE INTO `column_stats` VALUES -('mysql','tz','Time_zone_id','1','5',0.0000,4.0000,98.2500,4,'JSON_HB','{\"target_histogram_size\": 254, \"collected_at\": \"2020-01-02 03:04:05 UTC\", \"collected_by\": \"this very version\", \"histogram_hb\": [{\"start\": \"1\", \"size\": 0.340966921, \"ndv\": 1}, {\"start\": \"3\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"4\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"5\", \"end\": \"5\", \"size\": 0.002544529, \"ndv\": 1}]}'); +('mysql','tz','Time_zone_id','1','5',0.0000,4.0000,98.2500,4,'JSON_HB','{\"target_histogram_size\": 254, \"collected_at\": \"2022-01-07 07:07:00\", \"collected_by\": \"version\", \"histogram_hb\": [{\"start\": \"1\", \"size\": 0.340966921, \"ndv\": 1}, {\"start\": \"3\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"4\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"5\", \"end\": \"5\", \"size\": 0.002544529, \"ndv\": 1}]}'); /*!40000 ALTER TABLE `column_stats` ENABLE KEYS */; UNLOCK TABLES; @@ -709,7 +710,7 @@ USE mysql; LOCK TABLES `column_stats` WRITE; /*!40000 ALTER TABLE `column_stats` DISABLE KEYS */; REPLACE INTO `column_stats` VALUES -('mysql','tz','Time_zone_id','1','5',0.0000,4.0000,98.2500,4,'JSON_HB','{\"target_histogram_size\": 254, \"collected_at\": \"2020-01-02 03:04:05 UTC\", \"collected_by\": \"this very version\", \"histogram_hb\": [{\"start\": \"1\", \"size\": 0.340966921, \"ndv\": 1}, {\"start\": \"3\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"4\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"5\", \"end\": \"5\", \"size\": 0.002544529, \"ndv\": 1}]}'); +('mysql','tz','Time_zone_id','1','5',0.0000,4.0000,98.2500,4,'JSON_HB','{\"target_histogram_size\": 254, \"collected_at\": \"2022-01-07 07:07:00\", \"collected_by\": \"version\", \"histogram_hb\": [{\"start\": \"1\", \"size\": 0.340966921, \"ndv\": 1}, {\"start\": \"3\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"4\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"5\", \"end\": \"5\", \"size\": 0.002544529, \"ndv\": 1}]}'); /*!40000 ALTER TABLE `column_stats` ENABLE KEYS */; UNLOCK TABLES; @@ -1300,7 +1301,7 @@ USE mysql; LOCK TABLES `column_stats` WRITE; /*!40000 ALTER TABLE `column_stats` DISABLE KEYS */; INSERT IGNORE INTO `column_stats` VALUES -('mysql','tz','Time_zone_id','1','5',0.0000,4.0000,98.2500,4,'JSON_HB','{\"target_histogram_size\": 254, \"collected_at\": \"2020-01-02 03:04:05 UTC\", \"collected_by\": \"this very version\", \"histogram_hb\": [{\"start\": \"1\", \"size\": 0.340966921, \"ndv\": 1}, {\"start\": \"3\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"4\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"5\", \"end\": \"5\", \"size\": 0.002544529, \"ndv\": 1}]}'); +('mysql','tz','Time_zone_id','1','5',0.0000,4.0000,98.2500,4,'JSON_HB','{\"target_histogram_size\": 254, \"collected_at\": \"2022-01-07 07:07:00\", \"collected_by\": \"version\", \"histogram_hb\": [{\"start\": \"1\", \"size\": 0.340966921, \"ndv\": 1}, {\"start\": \"3\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"4\", \"size\": 0.328244275, \"ndv\": 1}, {\"start\": \"5\", \"end\": \"5\", \"size\": 0.002544529, \"ndv\": 1}]}'); /*!40000 ALTER TABLE `column_stats` ENABLE KEYS */; UNLOCK TABLES; diff --git a/mysql-test/main/mysqldump-system.test b/mysql-test/main/mysqldump-system.test index 43c99187fe2..85ad44211a8 100644 --- a/mysql-test/main/mysqldump-system.test +++ b/mysql-test/main/mysqldump-system.test @@ -43,14 +43,15 @@ create table mysql.tz like mysql.time_zone_transition; alter table mysql.tz engine=innodb; insert into mysql.tz select * from mysql.time_zone_transition; set global innodb_stats_persistent=1; +set time_zone="+03:00"; +SET TIMESTAMP= UNIX_TIMESTAMP('2022-01-07 07:07:00'); ANALYZE TABLE mysql.tz PERSISTENT FOR ALL; # for predictable output in tests delete from mysql.index_stats where prefix_arity!=1; delete from mysql.column_stats where column_name!='Time_zone_id'; -set time_zone="+03:00"; update mysql.innodb_index_stats set last_update="2020-01-01" where database_name="mysql" and table_name="tz"; update mysql.innodb_table_stats set last_update="2020-01-01" where database_name="mysql" and table_name="tz"; -update mysql.column_stats set histogram=json_replace(histogram, '$.collected_at', '2020-01-02 03:04:05 UTC', '$.collected_by', 'this very version'); +update mysql.column_stats set histogram=json_replace(histogram, '$.collected_by', replace(json_value(histogram, '$.collected_by'), @@version, 'version')); set global innodb_stats_persistent= @save_innodb_stats_persistent; alter table mysql.time_zone_name ORDER BY Name; diff --git a/sql/opt_histogram_json.cc b/sql/opt_histogram_json.cc index a749bc27e6e..6458059e5fe 100644 --- a/sql/opt_histogram_json.cc +++ b/sql/opt_histogram_json.cc @@ -178,22 +178,13 @@ private: void append_histogram_params() { char buf[128]; + String str(buf, sizeof(buf), system_charset_info); + THD *thd= current_thd; + timeval tv= {thd->query_start(), 0}; // we do not need microseconds - time_t cur_time_t= my_time(0); - struct tm curtime; - localtime_r(&cur_time_t, &curtime); - - my_snprintf(buf, sizeof(buf), "%d-%02d-%02d %2d:%02d:%02d %s", - curtime.tm_year + 1900, - curtime.tm_mon+1, - curtime.tm_mday, - curtime.tm_hour, - curtime.tm_min, - curtime.tm_sec, - system_time_zone); - + Timestamp(tv).to_datetime(thd).to_string(&str, 0); writer.add_member("target_histogram_size").add_ull(hist_width); - writer.add_member("collected_at").add_str(buf); + writer.add_member("collected_at").add_str(str.ptr()); writer.add_member("collected_by").add_str(server_version); } /*