Skip to content

Commit

Permalink
support high precision time in show processlist (I_S.processlist)
Browse files Browse the repository at this point in the history
Summary:
The time information from 'show processlist' and in information_schema.processlist is at the granularity of a second
This diff provides an override (system variable) to display the time at the granularity of a micro-second (e.g, 0.001234)
The variable is session settable

Differential Revision: D17239783

fbshipit-source-id: 7d58e50
  • Loading branch information
mzait authored and facebook-github-bot committed Sep 10, 2019
1 parent 8d1e178 commit b840ad7
Show file tree
Hide file tree
Showing 18 changed files with 397 additions and 191 deletions.
19 changes: 12 additions & 7 deletions include/my_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static inline my_bool validate_timestamp_range(const MYSQL_TIME *t)
return TRUE;
}

my_time_t
my_time_t
my_system_gmt_sec(const MYSQL_TIME *t, long *my_timezone,
my_bool *in_dst_time_gap);

Expand All @@ -218,19 +218,24 @@ int my_datetime_to_str(const MYSQL_TIME *l_time, char *to, uint dec);
int my_TIME_to_str(const MYSQL_TIME *l_time, char *to, uint dec);

int my_timeval_to_str(const struct timeval *tm, char *to, uint dec);
void my_timeval_minus(const struct timeval *tm_left,
const struct timeval *tm_right,
struct timeval *tm_out);
double my_timeval_to_double(const struct timeval *tm);
longlong my_timeval_to_longlong(const struct timeval *tm);

/*
/*
Available interval types used in any statement.
'interval_type' must be sorted so that simple intervals comes first,
ie year, quarter, month, week, day, hour, etc. The order based on
interval size is also important and the intervals should be kept in a
large to smaller order. (get_interval_value() depends on this)
Note: If you change the order of elements in this enum you should fix
order of elements in 'interval_type_to_name' and 'interval_names'
arrays
Note: If you change the order of elements in this enum you should fix
order of elements in 'interval_type_to_name' and 'interval_names'
arrays
See also interval_type_to_name, get_interval_value, interval_names
*/

Expand Down
4 changes: 2 additions & 2 deletions mysql-test/r/create.result
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ t1 CREATE TABLE `t1` (
`HOST` varchar(64) NOT NULL DEFAULT '',
`DB` varchar(64) DEFAULT NULL,
`COMMAND` varchar(16) NOT NULL DEFAULT '',
`TIME` int(7) NOT NULL DEFAULT '0',
`TIME` decimal(9,6) NOT NULL DEFAULT '0.000000',
`STATE` varchar(64) DEFAULT NULL,
`INFO` longtext,
`SRV_ID` bigint(21) unsigned NOT NULL DEFAULT '0'
Expand All @@ -1910,7 +1910,7 @@ t1 CREATE TEMPORARY TABLE `t1` (
`HOST` varchar(64) NOT NULL DEFAULT '',
`DB` varchar(64) DEFAULT NULL,
`COMMAND` varchar(16) NOT NULL DEFAULT '',
`TIME` int(7) NOT NULL DEFAULT '0',
`TIME` decimal(9,6) NOT NULL DEFAULT '0.000000',
`STATE` varchar(64) DEFAULT NULL,
`INFO` longtext,
`SRV_ID` bigint(21) unsigned NOT NULL DEFAULT '0'
Expand Down
24 changes: 24 additions & 0 deletions mysql-test/r/high_precision_processlist.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Test #1: variable is off (low precision)
SELECT @@session.high_precision_processlist;
@@session.high_precision_processlist
0
SELECT @@global.high_precision_processlist;
@@global.high_precision_processlist
0
select case when time=round(time) then 'success' else 'failure' end status
from information_schema.processlist where time < 1;
status
success
Test #2: variable is on (high precision)
set @@session.high_precision_processlist=on;
SELECT @@session.high_precision_processlist;
@@session.high_precision_processlist
1
SELECT @@global.high_precision_processlist;
@@global.high_precision_processlist
0
select case when time!=round(time) then 'success' else 'failure' end status
from information_schema.processlist where time < 1;
status
success
set @@session.high_precision_processlist=off;
4 changes: 4 additions & 0 deletions mysql-test/r/mysqld--help-notwin-profiling.result
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ The following options may be given as the first argument:
gtid_executed set before flushing binlog from cache to
file.
-?, --help Display this help and exit.
--high-precision-processlist
If set, MySQL will display the time in 1/1000000 of a
second precision
--high-priority-ddl Setting this flag will allow DDL commands to kill
conflicting connections (effective for admin user only).
--high-priority-lock-wait-timeout=#
Expand Down Expand Up @@ -2121,6 +2124,7 @@ group-concat-max-len 1024
gtid-mode OFF
gtid-precommit FALSE
help TRUE
high-precision-processlist FALSE
high-priority-ddl FALSE
high-priority-lock-wait-timeout 1
histogram-step-size-binlog-fsync 16ms
Expand Down
4 changes: 4 additions & 0 deletions mysql-test/r/mysqld--help-notwin.result
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ The following options may be given as the first argument:
gtid_executed set before flushing binlog from cache to
file.
-?, --help Display this help and exit.
--high-precision-processlist
If set, MySQL will display the time in 1/1000000 of a
second precision
--high-priority-ddl Setting this flag will allow DDL commands to kill
conflicting connections (effective for admin user only).
--high-priority-lock-wait-timeout=#
Expand Down Expand Up @@ -2119,6 +2122,7 @@ group-concat-max-len 1024
gtid-mode OFF
gtid-precommit FALSE
help TRUE
high-precision-processlist FALSE
high-priority-ddl FALSE
high-priority-lock-wait-timeout 1
histogram-step-size-binlog-fsync 16ms
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/r/ssl_crl.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Variable_name Value
have_openssl YES
have_ssl YES
high_precision_processlist OFF
ssl ON
ssl_ca MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
ssl_capath
Expand All @@ -14,6 +15,7 @@ ssl_key MYSQL_TEST_DIR/std_data/crl-server-key.pem
Variable_name Value
have_openssl YES
have_ssl YES
high_precision_processlist OFF
ssl ON
ssl_ca MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
ssl_capath
Expand Down
1 change: 1 addition & 0 deletions mysql-test/r/ssl_crl_clients_valid.result
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Variable_name Value
have_openssl YES
have_ssl YES
high_precision_processlist OFF
ssl ON
ssl_ca MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
ssl_capath
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/r/ssl_crl_crlpath.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Variable_name Value
have_openssl YES
have_ssl YES
high_precision_processlist OFF
ssl ON
ssl_ca MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
ssl_capath
Expand All @@ -14,6 +15,7 @@ ssl_key MYSQL_TEST_DIR/std_data/crl-server-key.pem
Variable_name Value
have_openssl YES
have_ssl YES
high_precision_processlist OFF
ssl ON
ssl_ca MYSQL_TEST_DIR/std_data/crl-ca-cert.pem
ssl_capath
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/funcs_1/r/is_columns_is.result
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def information_schema PROCESSLIST ID 1 0 NO bigint NULL NULL 20 0 NULL NULL NUL
def information_schema PROCESSLIST INFO 8 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext select
def information_schema PROCESSLIST SRV_ID 9 0 NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select
def information_schema PROCESSLIST STATE 7 NULL YES varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select
def information_schema PROCESSLIST TIME 6 0 NO int NULL NULL 10 0 NULL NULL NULL int(7) select
def information_schema PROCESSLIST TIME 6 0.000000 NO decimal NULL NULL 9 6 NULL NULL NULL decimal(9,6) select
def information_schema PROCESSLIST USER 2 NO varchar 80 240 NULL NULL NULL utf8 utf8_general_ci varchar(80) select
def information_schema QUERY_ATTRIBUTES ATTR_NAME 2 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext select
def information_schema QUERY_ATTRIBUTES ATTR_VALUE 3 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext select
Expand Down Expand Up @@ -330,7 +330,7 @@ def information_schema SRV_SESSIONS HOST 3 NO varchar 64 192 NULL NULL NULL utf
def information_schema SRV_SESSIONS ID 1 0 NO bigint NULL NULL 20 0 NULL NULL NULL bigint(21) unsigned select
def information_schema SRV_SESSIONS INFO 8 NULL YES longtext 4294967295 4294967295 NULL NULL NULL utf8 utf8_general_ci longtext select
def information_schema SRV_SESSIONS STATE 7 NULL YES varchar 64 192 NULL NULL NULL utf8 utf8_general_ci varchar(64) select
def information_schema SRV_SESSIONS TIME 6 0 NO int NULL NULL 10 0 NULL NULL NULL int(7) select
def information_schema SRV_SESSIONS TIME 6 0.000000 NO decimal NULL NULL 9 6 NULL NULL NULL decimal(9,6) select
def information_schema SRV_SESSIONS USER 2 NO varchar 80 240 NULL NULL NULL utf8 utf8_general_ci varchar(80) select
def information_schema STATISTICS CARDINALITY 10 NULL YES bigint NULL NULL 19 0 NULL NULL NULL bigint(21) select
def information_schema STATISTICS COLLATION 9 NULL YES varchar 1 3 NULL NULL NULL utf8 utf8_general_ci varchar(1) select
Expand Down Expand Up @@ -898,7 +898,7 @@ NULL information_schema PROCESSLIST ID bigint NULL NULL NULL NULL bigint(21) uns
3.0000 information_schema PROCESSLIST HOST varchar 64 192 utf8 utf8_general_ci varchar(64)
3.0000 information_schema PROCESSLIST DB varchar 64 192 utf8 utf8_general_ci varchar(64)
3.0000 information_schema PROCESSLIST COMMAND varchar 16 48 utf8 utf8_general_ci varchar(16)
NULL information_schema PROCESSLIST TIME int NULL NULL NULL NULL int(7)
NULL information_schema PROCESSLIST TIME decimal NULL NULL NULL NULL decimal(9,6)
3.0000 information_schema PROCESSLIST STATE varchar 64 192 utf8 utf8_general_ci varchar(64)
1.0000 information_schema PROCESSLIST INFO longtext 4294967295 4294967295 utf8 utf8_general_ci longtext
NULL information_schema PROCESSLIST SRV_ID bigint NULL NULL NULL NULL bigint(21) unsigned
Expand Down Expand Up @@ -996,7 +996,7 @@ NULL information_schema SRV_SESSIONS ID bigint NULL NULL NULL NULL bigint(21) un
3.0000 information_schema SRV_SESSIONS HOST varchar 64 192 utf8 utf8_general_ci varchar(64)
3.0000 information_schema SRV_SESSIONS DB varchar 64 192 utf8 utf8_general_ci varchar(64)
3.0000 information_schema SRV_SESSIONS COMMAND varchar 16 48 utf8 utf8_general_ci varchar(16)
NULL information_schema SRV_SESSIONS TIME int NULL NULL NULL NULL int(7)
NULL information_schema SRV_SESSIONS TIME decimal NULL NULL NULL NULL decimal(9,6)
3.0000 information_schema SRV_SESSIONS STATE varchar 64 192 utf8 utf8_general_ci varchar(64)
1.0000 information_schema SRV_SESSIONS INFO longtext 4294967295 4294967295 utf8 utf8_general_ci longtext
NULL information_schema SRV_SESSIONS CONN_ID bigint NULL NULL NULL NULL bigint(21) unsigned
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/funcs_1/r/processlist_priv_no_prot.result
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` (
`HOST` varchar(64) NOT NULL DEFAULT '',
`DB` varchar(64) DEFAULT NULL,
`COMMAND` varchar(16) NOT NULL DEFAULT '',
`TIME` int(7) NOT NULL DEFAULT '0',
`TIME` decimal(9,6) NOT NULL DEFAULT '0.000000',
`STATE` varchar(64) DEFAULT NULL,
`INFO` longtext,
`SRV_ID` bigint(21) unsigned NOT NULL DEFAULT '0'
Expand Down Expand Up @@ -99,7 +99,7 @@ PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` (
`HOST` varchar(64) NOT NULL DEFAULT '',
`DB` varchar(64) DEFAULT NULL,
`COMMAND` varchar(16) NOT NULL DEFAULT '',
`TIME` int(7) NOT NULL DEFAULT '0',
`TIME` decimal(9,6) NOT NULL DEFAULT '0.000000',
`STATE` varchar(64) DEFAULT NULL,
`INFO` longtext,
`SRV_ID` bigint(21) unsigned NOT NULL DEFAULT '0'
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/funcs_1/r/processlist_val_no_prot.result
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ PROCESSLIST CREATE TEMPORARY TABLE `PROCESSLIST` (
`HOST` varchar(64) NOT NULL DEFAULT '',
`DB` varchar(64) DEFAULT NULL,
`COMMAND` varchar(16) NOT NULL DEFAULT '',
`TIME` int(7) NOT NULL DEFAULT '0',
`TIME` decimal(9,6) NOT NULL DEFAULT '0.000000',
`STATE` varchar(64) DEFAULT NULL,
`INFO` longtext,
`SRV_ID` bigint(21) unsigned NOT NULL DEFAULT '0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Default value of high_precision_processlist is OFF
SELECT @@session.high_precision_processlist;
@@session.high_precision_processlist
0
Can set session value and is different from global
set @@session.high_precision_processlist=on;
SELECT @@session.high_precision_processlist;
@@session.high_precision_processlist
1
SELECT @@global.high_precision_processlist;
@@global.high_precision_processlist
0
Setting it globally does not affects the session value
set @@global.high_precision_processlist = off;
SELECT @@session.high_precision_processlist;
@@session.high_precision_processlist
1
SELECT @@global.high_precision_processlist;
@@global.high_precision_processlist
0
23 changes: 23 additions & 0 deletions mysql-test/suite/sys_vars/t/high_precision_processlist_basic.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- source include/load_sysvars.inc

####
# Verify default value is OFF
####
--echo Default value of high_precision_processlist is OFF
SELECT @@session.high_precision_processlist;

####
# Verify that this is a session variable
####
--echo Can set session value and is different from global
set @@session.high_precision_processlist=on;
SELECT @@session.high_precision_processlist;
SELECT @@global.high_precision_processlist;

####
## Verify that setting it globally does not affect the session
####
--echo Setting it globally does not affects the session value
set @@global.high_precision_processlist = off;
SELECT @@session.high_precision_processlist;
SELECT @@global.high_precision_processlist;
23 changes: 23 additions & 0 deletions mysql-test/t/high_precision_processlist.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

### the test relies on information_schema.processlist where
### it is easier to process the time using SQL statements

### 1: use high precision time, round yields same value for sub-sec time
--echo Test #1: variable is off (low precision)
SELECT @@session.high_precision_processlist;
SELECT @@global.high_precision_processlist;

select case when time=round(time) then 'success' else 'failure' end status
from information_schema.processlist where time < 1;

### 2: use high precision time, round yields higher value for sub-sec time
--echo Test #2: variable is on (high precision)
set @@session.high_precision_processlist=on;
SELECT @@session.high_precision_processlist;
SELECT @@global.high_precision_processlist;

select case when time!=round(time) then 'success' else 'failure' end status
from information_schema.processlist where time < 1;

### restore the variable to its default value
set @@session.high_precision_processlist=off;
Loading

0 comments on commit b840ad7

Please sign in to comment.