Skip to content

Commit fda980c

Browse files
committed
Per-user session variable default values
Summary: This diff introduces per-user session variable default values. This is for MyRocks and MySQL production debugging. A new global variable 'per-user-session-var-default-val' with type of string is introduced, it defines the default values of multiple session variables for multiple users, e.g. --per-user-session-var-default-val="user1:user2:user3:tx_isolation=read-committed,gap_lock_raise_error=0,user4:user5:big_tables=1,auto_increment_increment=12345,long_query_time=123.45" In this example, the default values of session variables tx_isolation and gap_lock_raise_error for user1, user2, and user3 are defined, the default values of session variables big_tables, auto_increment_increment, and long_query_time for user4 and user 5 are defined. When these users connect to server, the corresponding session variables will be set with these values so that these users don't have to execute SET command to set these session variables before executing queries. The cost of an extra round trip is saved. (1) This global variable is dynamic so it can be set at runtime. (2) Sys-vars have many types. The per-user session variables supported types are enum/bool/int/uint/double, which are the most common types for session variables. Other types like string(charptr)/proxy_user/external_user/key_cache/plugin/struct etc are *not* supported. (3) The users won't be validated when per-user-session-var-default-val is set since users can be changed any time after the global is set (4) The session variables will be validated when per-user-session-var-default-val is set. Invalid command line value will cause server fail to start. Invalid value in SET command will fail the command. Test Plan: New tests added: sys_vars.per_user_session_var_default_val_basic.test sys_vars.per_user_session_var_default_val_null.test sys_vars.per_user_session_var_default_val_empty.test sys_vars.per_user_session_var_default_val.test sys_vars.per_user_session_var_default_validation.test Reviewers: santoshb, jkedgar Reviewed By: jkedgar Subscribers: webscalesql-eng Differential Revision: https://reviews.facebook.net/D55791
1 parent c5a7b3b commit fda980c

24 files changed

+3554
-8
lines changed

include/my_getopt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ extern my_bool my_getopt_print_errors;
107107
extern my_bool my_getopt_skip_unknown;
108108
extern my_error_reporter my_getopt_error_reporter;
109109

110+
extern my_bool my_get_bool_argument(const struct my_option *opts,
111+
const char *argument,
112+
int *error);
113+
extern longlong getopt_ll(char *arg, const struct my_option *optp, int *err);
114+
extern ulonglong getopt_ull(char *, const struct my_option *, int *);
115+
extern double getopt_double(char *arg, const struct my_option *optp, int *err);
116+
110117
extern int handle_options (int *argc, char ***argv,
111118
const struct my_option *longopts, my_get_one_option);
112119
extern int handle_options_with_logging (int *argc, char ***argv,

mysql-test/r/mysqld--help-notwin-profiling.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ The following options may be given as the first argument:
673673
The rate of sampling replayed events on slave to
674674
determine the peak replication lag over some period.
675675
--peak-lag-time=# The time frame peak lag is measured within, in seconds.
676+
--per-user-session-var-default-val[=name]
677+
Per user session variable default value
676678
--performance-schema
677679
Enable the performance schema.
678680
(Defaults to on; use --skip-performance-schema to disable.)
@@ -1684,6 +1686,7 @@ optimizer-trace-offset -1
16841686
part-scan-max 10
16851687
peak-lag-sample-rate 100
16861688
peak-lag-time 60
1689+
per-user-session-var-default-val (No default value)
16871690
performance-schema TRUE
16881691
performance-schema-accounts-size -1
16891692
performance-schema-consumer-events-stages-current FALSE

mysql-test/r/mysqld--help-notwin.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ The following options may be given as the first argument:
673673
The rate of sampling replayed events on slave to
674674
determine the peak replication lag over some period.
675675
--peak-lag-time=# The time frame peak lag is measured within, in seconds.
676+
--per-user-session-var-default-val[=name]
677+
Per user session variable default value
676678
--performance-schema
677679
Enable the performance schema.
678680
(Defaults to on; use --skip-performance-schema to disable.)
@@ -1682,6 +1684,7 @@ optimizer-trace-offset -1
16821684
part-scan-max 10
16831685
peak-lag-sample-rate 100
16841686
peak-lag-time 60
1687+
per-user-session-var-default-val (No default value)
16851688
performance-schema TRUE
16861689
performance-schema-accounts-size -1
16871690
performance-schema-consumer-events-stages-current FALSE

mysql-test/suite/sys_vars/r/per_user_session_var_default_val.result

Lines changed: 2354 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
SET @original_val = @@global.per_user_session_var_default_val;
2+
SELECT @original_val;
3+
@original_val
4+
NULL
5+
SELECT @@GLOBAL.per_user_session_var_default_val = VARIABLE_VALUE
6+
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
7+
WHERE VARIABLE_NAME='per_user_session_var_default_val';
8+
@@GLOBAL.per_user_session_var_default_val = VARIABLE_VALUE
9+
NULL
10+
SELECT @@SESSION.per_user_session_var_default_val;
11+
ERROR HY000: Variable 'per_user_session_var_default_val' is a GLOBAL variable
12+
SET SESSION per_user_session_var_default_val = "";
13+
ERROR HY000: Variable 'per_user_session_var_default_val' is a GLOBAL variable and should be set with SET GLOBAL
14+
SELECT @@GLOBAL.per_user_session_var_default_val;
15+
@@GLOBAL.per_user_session_var_default_val
16+
NULL
17+
## default value is NULL
18+
SET GLOBAL per_user_session_var_default_val = DEFAULT;
19+
SELECT @@GLOBAL.per_user_session_var_default_val;
20+
@@GLOBAL.per_user_session_var_default_val
21+
NULL
22+
## NULL is a valid value
23+
SET GLOBAL per_user_session_var_default_val = NULL;
24+
SELECT @@GLOBAL.per_user_session_var_default_val;
25+
@@GLOBAL.per_user_session_var_default_val
26+
NULL
27+
## "" is a valid value
28+
SET GLOBAL per_user_session_var_default_val = "";
29+
SELECT @@GLOBAL.per_user_session_var_default_val;
30+
@@GLOBAL.per_user_session_var_default_val
31+
32+
SET @@global.per_user_session_var_default_val = @original_val;
33+
SELECT @@global.per_user_session_var_default_val;
34+
@@global.per_user_session_var_default_val
35+
NULL
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# empty string is a valid value
2+
SELECT @@GLOBAL.per_user_session_var_default_val;
3+
@@GLOBAL.per_user_session_var_default_val
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# default value is NULL ptr
2+
SELECT @@GLOBAL.per_user_session_var_default_val;
3+
@@GLOBAL.per_user_session_var_default_val
4+
NULL
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
flush privileges;
2+
create user usr1@localhost;
3+
grant all privileges on *.* to admin1@localhost identified by password '' with grant option;
4+
flush user_resources;
5+
SET @original_val = @@global.per_user_session_var_default_val;
6+
SELECT @original_val;
7+
@original_val
8+
NULL
9+
## default value is NULL
10+
SET GLOBAL per_user_session_var_default_val = DEFAULT;
11+
SELECT @@GLOBAL.per_user_session_var_default_val;
12+
@@GLOBAL.per_user_session_var_default_val
13+
NULL
14+
## NULL is a valid value
15+
SET GLOBAL per_user_session_var_default_val = NULL;
16+
SELECT @@GLOBAL.per_user_session_var_default_val;
17+
@@GLOBAL.per_user_session_var_default_val
18+
NULL
19+
## "" is a valid value
20+
SET GLOBAL per_user_session_var_default_val = "";
21+
SELECT @@GLOBAL.per_user_session_var_default_val;
22+
@@GLOBAL.per_user_session_var_default_val
23+
24+
##
25+
## Invalid values. SET command will fail
26+
##
27+
SET GLOBAL per_user_session_var_default_val = " ";
28+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of ' '
29+
SET GLOBAL per_user_session_var_default_val = " ";
30+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of ' '
31+
SET GLOBAL per_user_session_var_default_val = ":";
32+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of ':'
33+
SET GLOBAL per_user_session_var_default_val = "=";
34+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of '='
35+
SET GLOBAL per_user_session_var_default_val = ",";
36+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of ','
37+
SET GLOBAL per_user_session_var_default_val = ";";
38+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of ';'
39+
SET GLOBAL per_user_session_var_default_val = "\"";
40+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of '"'
41+
SET GLOBAL per_user_session_var_default_val = "'";
42+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of '''
43+
SET GLOBAL per_user_session_var_default_val = "\\";
44+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of '\'
45+
SET GLOBAL per_user_session_var_default_val = "/";
46+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of '/'
47+
SET GLOBAL per_user_session_var_default_val = "u";
48+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u'
49+
SET GLOBAL per_user_session_var_default_val = "gap_lock_raise_error=0";
50+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'gap_lock_raise_error=0'
51+
SET GLOBAL per_user_session_var_default_val = "gap_lock_raise_error=0,u2:gap_lock_raise_error=1";
52+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'gap_lock_raise_error=0,u2:gap_lock_raise_error=1'
53+
SET GLOBAL per_user_session_var_default_val = " u";
54+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of ' u'
55+
SET GLOBAL per_user_session_var_default_val = "u ";
56+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u '
57+
SET GLOBAL per_user_session_var_default_val = "u :";
58+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u :'
59+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error";
60+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error'
61+
SET GLOBAL per_user_session_var_default_val = "u: ";
62+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u: '
63+
SET GLOBAL per_user_session_var_default_val = " u:gap_lock_raise_error";
64+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of ' u:gap_lock_raise_error'
65+
SET GLOBAL per_user_session_var_default_val = "u:v:";
66+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:v:'
67+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error=";
68+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error='
69+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error=0:";
70+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error=0:'
71+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error=0=";
72+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error=0='
73+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error=0=1";
74+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error=0=1'
75+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error=0,u:gap_lock_write_log=0";
76+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error=0,u:gap_lock_write_log=0'
77+
SET GLOBAL per_user_session_var_default_val = "u:= 0";
78+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:= 0'
79+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error= 0";
80+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error= 0'
81+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error= ";
82+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error= '
83+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error=0,";
84+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error=0,'
85+
SET GLOBAL per_user_session_var_default_val = "u:gap_lock_raise_error=0;";
86+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u:gap_lock_raise_error=0;'
87+
SET GLOBAL per_user_session_var_default_val = "u1:u2:gap_lock_raise_error=0,gap_lock_write_log=0,,u3:big_tables=1";
88+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:u2:gap_lock_raise_error=0,gap_lock_write_log=0,,u3:big_tables=1'
89+
SET GLOBAL per_user_session_var_default_val = "u1::u2:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1";
90+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1::u2:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1'
91+
SET GLOBAL per_user_session_var_default_val = "u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1 ";
92+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1 '
93+
SET GLOBAL per_user_session_var_default_val = "u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1,";
94+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1,'
95+
SET GLOBAL per_user_session_var_default_val = "u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1'";
96+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=1''
97+
SET GLOBAL per_user_session_var_default_val = "u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables='1'";
98+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables='1''
99+
SET GLOBAL per_user_session_var_default_val = "u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables=\"1\"";
100+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:gap_lock_raise_error=0,gap_lock_write_log=0,u3:big_tables="1"'
101+
SET GLOBAL per_user_session_var_default_val = "u1:time_zone=\'+10:00\'";
102+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:time_zone='+10:00''
103+
## Syntax error
104+
SET GLOBAL per_user_session_var_default_val = "u1:optimizer_switch=index_merge=on";
105+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:optimizer_switch=index_merge=on'
106+
## Unsupported type 'flagset'
107+
SET GLOBAL per_user_session_var_default_val = "u1:optimizer_switch=xyz";
108+
ERROR 42000: Variable 'per_user_session_var_default_val' can't be set to the value of 'u1:optimizer_switch=xyz'
109+
##
110+
## root privilege is required to set session variable binglog_format
111+
## root privilege will be granted to usr1 temporarily to get this done
112+
##
113+
SET GLOBAL per_user_session_var_default_val = "usr1:binlog_format=MIXED";
114+
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
115+
@@GLOBAL.binlog_format @@SESSION.binlog_format
116+
STATEMENT MIXED
117+
SET GLOBAL per_user_session_var_default_val = "usr1:binlog_format=ROW";
118+
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
119+
@@GLOBAL.binlog_format @@SESSION.binlog_format
120+
STATEMENT ROW
121+
SET GLOBAL per_user_session_var_default_val = "admin1:binlog_format=MIXED";
122+
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
123+
@@GLOBAL.binlog_format @@SESSION.binlog_format
124+
STATEMENT MIXED
125+
SET GLOBAL per_user_session_var_default_val = "admin1:binlog_format=ROW";
126+
SELECT @@GLOBAL.binlog_format, @@SESSION.binlog_format;
127+
@@GLOBAL.binlog_format @@SESSION.binlog_format
128+
STATEMENT ROW
129+
drop user usr1@localhost;
130+
drop user admin1@localhost;
131+
SET @@global.per_user_session_var_default_val = @original_val;
132+
SELECT @@global.per_user_session_var_default_val;
133+
@@global.per_user_session_var_default_val
134+
NULL
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--echo ## create connection batch $i
2+
let $j=1;
3+
while ($j<=5) {
4+
connect (con_tao_$i$j,localhost,tao$j,,);
5+
connect (con_tao_ssl_$i$j,localhost,tao$j,,,,,SSL);
6+
inc $j;
7+
}
8+
connect (con_root_$i,localhost,root,,);
9+
connect (con_root_ssl_$i,localhost,root,,,,,SSL);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--per-user-session-var-default-val="tao2:tao3:root:tx_isolation=read-committed,gap_lock_raise_error=0,gap_lock_write_log=0,big_tables=1,tao1:bulk_insert_buffer_size=16M,gap_lock_raise_error=0,gap_lock_write_log=0,auto_increment_increment=12345,long_query_time=123.45"

0 commit comments

Comments
 (0)