Skip to content

Commit c8948b0

Browse files
committed
MDEV-8931: (server part of) session state tracking
System variables tracking
1 parent e7608a7 commit c8948b0

22 files changed

+1483
-153
lines changed

include/mysql_com.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ enum enum_server_command
288288
CLIENT_MULTI_RESULTS | \
289289
CLIENT_PS_MULTI_RESULTS | \
290290
CLIENT_SSL_VERIFY_SERVER_CERT | \
291-
CLIENT_REMEMBER_OPTIONS | \
291+
CLIENT_REMEMBER_OPTIONS | \
292292
MARIADB_CLIENT_PROGRESS | \
293293
CLIENT_PLUGIN_AUTH | \
294294
CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \
@@ -556,9 +556,9 @@ enum enum_mysql_set_option
556556
*/
557557
enum enum_session_state_type
558558
{
559-
SESSION_TRACK_SYSTEM_VARIABLES, /* Session system variables */
560-
SESSION_TRACK_SCHEMA, /* Current schema */
561-
SESSION_TRACK_STATE_CHANGE, /* track session state changes */
559+
SESSION_TRACK_SYSTEM_VARIABLES, /* Session system variables */
560+
SESSION_TRACK_SCHEMA, /* Current schema */
561+
SESSION_TRACK_STATE_CHANGE, /* track session state changes */
562562
SESSION_TRACK_GTIDS,
563563
SESSION_TRACK_TRANSACTION_CHARACTERISTICS, /* Transaction chistics */
564564
SESSION_TRACK_TRANSACTION_STATE /* Transaction state */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,8 @@ The following options may be given as the first argument:
908908
(Defaults to on; use --skip-session-track-schema to disable.)
909909
--session-track-state-change
910910
Track changes to the 'session state'.
911+
--session-track-system-variables=name
912+
Track changes in registered system variables.
911913
--show-slave-auth-info
912914
Show user and password in SHOW SLAVE HOSTS on this
913915
master.
@@ -1392,6 +1394,7 @@ secure-file-priv (No default value)
13921394
server-id 1
13931395
session-track-schema TRUE
13941396
session-track-state-change FALSE
1397+
session-track-system-variables autocommit,character_set_client,character_set_connection,character_set_results,time_zone
13951398
show-slave-auth-info FALSE
13961399
silent-startup FALSE
13971400
skip-grant-tables TRUE
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#
2+
# Variable name : session_track_system_variables
3+
# Scope : Global & Session
4+
#
5+
# Global - default
6+
SELECT @@global.session_track_system_variables;
7+
@@global.session_track_system_variables
8+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
9+
# Session - default
10+
SELECT @@session.session_track_system_variables;
11+
@@session.session_track_system_variables
12+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
13+
14+
# via INFORMATION_SCHEMA.GLOBAL_VARIABLES
15+
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE 'session_track%' ORDER BY VARIABLE_NAME;
16+
VARIABLE_NAME VARIABLE_VALUE
17+
SESSION_TRACK_SCHEMA ON
18+
SESSION_TRACK_STATE_CHANGE OFF
19+
SESSION_TRACK_SYSTEM_VARIABLES autocommit,character_set_client,character_set_connection,character_set_results,time_zone
20+
# via INFORMATION_SCHEMA.SESSION_VARIABLES
21+
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE VARIABLE_NAME LIKE 'session_track%' ORDER BY VARIABLE_NAME;
22+
VARIABLE_NAME VARIABLE_VALUE
23+
SESSION_TRACK_SCHEMA ON
24+
SESSION_TRACK_STATE_CHANGE OFF
25+
SESSION_TRACK_SYSTEM_VARIABLES autocommit,character_set_client,character_set_connection,character_set_results,time_zone
26+
SET @global_saved_tmp = @@global.session_track_system_variables;
27+
28+
# Altering global variable's value
29+
SET @@global.session_track_system_variables='autocommit';
30+
SELECT @@global.session_track_system_variables;
31+
@@global.session_track_system_variables
32+
autocommit
33+
SELECT @@session.session_track_system_variables;
34+
@@session.session_track_system_variables
35+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
36+
37+
# Altering session variable's value
38+
SET @@session.session_track_system_variables='autocommit';
39+
SELECT @@global.session_track_system_variables;
40+
@@global.session_track_system_variables
41+
autocommit
42+
SELECT @@session.session_track_system_variables;
43+
@@session.session_track_system_variables
44+
autocommit
45+
46+
# Variables' values in a new session.
47+
connect con1,"127.0.0.1",root,,test,$MASTER_MYPORT,;
48+
# Global - expect "autocommit"
49+
SELECT @@global.session_track_system_variables;
50+
@@global.session_track_system_variables
51+
autocommit
52+
53+
# Session - expect "autocommit"
54+
SELECT @@session.session_track_system_variables;
55+
@@session.session_track_system_variables
56+
autocommit
57+
58+
# Switching to the default connection.
59+
connection default;
60+
SELECT @@global.session_track_system_variables;
61+
@@global.session_track_system_variables
62+
autocommit
63+
SELECT @@session.session_track_system_variables;
64+
@@session.session_track_system_variables
65+
autocommit
66+
67+
# Test if DEFAULT is working as expected.
68+
SET @@global.session_track_system_variables = DEFAULT;
69+
SET @@session.session_track_system_variables = DEFAULT;
70+
71+
SELECT @@global.session_track_system_variables;
72+
@@global.session_track_system_variables
73+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
74+
SELECT @@session.session_track_system_variables;
75+
@@session.session_track_system_variables
76+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
77+
78+
# Variables' values in a new session (con2).
79+
connect con2,"127.0.0.1",root,,test,$MASTER_MYPORT,;
80+
SELECT @@global.session_track_system_variables;
81+
@@global.session_track_system_variables
82+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
83+
SELECT @@session.session_track_system_variables;
84+
@@session.session_track_system_variables
85+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
86+
87+
# Altering session should not affect global.
88+
SET @@session.session_track_system_variables = 'sql_mode';
89+
SELECT @@global.session_track_system_variables;
90+
@@global.session_track_system_variables
91+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
92+
SELECT @@session.session_track_system_variables;
93+
@@session.session_track_system_variables
94+
sql_mode
95+
96+
# Variables' values in a new session (con3).
97+
connect con3,"127.0.0.1",root,,test,$MASTER_MYPORT,;
98+
# Altering global should not affect session.
99+
SET @@global.session_track_system_variables = 'sql_mode';
100+
SELECT @@global.session_track_system_variables;
101+
@@global.session_track_system_variables
102+
sql_mode
103+
SELECT @@session.session_track_system_variables;
104+
@@session.session_track_system_variables
105+
autocommit,character_set_client,character_set_connection,character_set_results,time_zone
106+
107+
# Switching to the default connection.
108+
connection default;
109+
# Testing NULL
110+
SET @@global.session_track_system_variables = NULL;
111+
SET @@session.session_track_system_variables = NULL;
112+
# Global - expect "" instead of NULL
113+
SELECT @@global.session_track_system_variables;
114+
@@global.session_track_system_variables
115+
NULL
116+
# Session - expect "" instead of NULL
117+
SELECT @@session.session_track_system_variables;
118+
@@session.session_track_system_variables
119+
120+
# testing with duplicate entries.
121+
SET @@global.session_track_system_variables= "time_zone";
122+
SET @@session.session_track_system_variables= "time_zone";
123+
SET @@global.session_track_system_variables= "sql_mode,sql_mode";
124+
SET @@session.session_track_system_variables= "sql_mode,sql_mode";
125+
SELECT @@global.session_track_system_variables;
126+
@@global.session_track_system_variables
127+
sql_mode
128+
SELECT @@session.session_track_system_variables;
129+
@@session.session_track_system_variables
130+
sql_mode
131+
132+
# testing ordering
133+
SET @@global.session_track_system_variables= "time_zone,sql_mode";
134+
SET @@session.session_track_system_variables= "time_zone,sql_mode";
135+
SELECT @@global.session_track_system_variables;
136+
@@global.session_track_system_variables
137+
sql_mode,time_zone
138+
SELECT @@session.session_track_system_variables;
139+
@@session.session_track_system_variables
140+
sql_mode,time_zone
141+
142+
# special values
143+
SET @@global.session_track_system_variables= "*";
144+
SET @@session.session_track_system_variables= "*";
145+
SELECT @@global.session_track_system_variables;
146+
@@global.session_track_system_variables
147+
*
148+
SELECT @@session.session_track_system_variables;
149+
@@session.session_track_system_variables
150+
*
151+
SET @@global.session_track_system_variables= "";
152+
SET @@session.session_track_system_variables= "";
153+
SELECT @@global.session_track_system_variables;
154+
@@global.session_track_system_variables
155+
156+
SELECT @@session.session_track_system_variables;
157+
@@session.session_track_system_variables
158+
159+
160+
# Restoring the original values.
161+
SET @@global.session_track_system_variables = @global_saved_tmp;
162+
# End of tests.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,6 +3817,20 @@ NUMERIC_BLOCK_SIZE NULL
38173817
ENUM_VALUE_LIST OFF,ON
38183818
READ_ONLY NO
38193819
COMMAND_LINE_ARGUMENT OPTIONAL
3820+
VARIABLE_NAME SESSION_TRACK_SYSTEM_VARIABLES
3821+
SESSION_VALUE autocommit,character_set_client,character_set_connection,character_set_results,time_zone
3822+
GLOBAL_VALUE autocommit,character_set_client,character_set_connection,character_set_results,time_zone
3823+
GLOBAL_VALUE_ORIGIN COMPILE-TIME
3824+
DEFAULT_VALUE autocommit,character_set_client,character_set_connection,character_set_results,time_zone
3825+
VARIABLE_SCOPE SESSION
3826+
VARIABLE_TYPE VARCHAR
3827+
VARIABLE_COMMENT Track changes in registered system variables.
3828+
NUMERIC_MIN_VALUE NULL
3829+
NUMERIC_MAX_VALUE NULL
3830+
NUMERIC_BLOCK_SIZE NULL
3831+
ENUM_VALUE_LIST NULL
3832+
READ_ONLY NO
3833+
COMMAND_LINE_ARGUMENT REQUIRED
38203834
VARIABLE_NAME SKIP_EXTERNAL_LOCKING
38213835
SESSION_VALUE NULL
38223836
GLOBAL_VALUE ON
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
--source include/not_embedded.inc
2+
3+
--echo #
4+
--echo # Variable name : session_track_system_variables
5+
--echo # Scope : Global & Session
6+
--echo #
7+
8+
--echo # Global - default
9+
SELECT @@global.session_track_system_variables;
10+
--echo # Session - default
11+
SELECT @@session.session_track_system_variables;
12+
--echo
13+
14+
--echo # via INFORMATION_SCHEMA.GLOBAL_VARIABLES
15+
--disable_warnings
16+
SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE 'session_track%' ORDER BY VARIABLE_NAME;
17+
--enable_warnings
18+
19+
--echo # via INFORMATION_SCHEMA.SESSION_VARIABLES
20+
--disable_warnings
21+
SELECT * FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE VARIABLE_NAME LIKE 'session_track%' ORDER BY VARIABLE_NAME;
22+
--enable_warnings
23+
24+
# Save the global value to be used to restore the original value.
25+
SET @global_saved_tmp = @@global.session_track_system_variables;
26+
--echo
27+
28+
--echo # Altering global variable's value
29+
SET @@global.session_track_system_variables='autocommit';
30+
SELECT @@global.session_track_system_variables;
31+
SELECT @@session.session_track_system_variables;
32+
--echo
33+
34+
--echo # Altering session variable's value
35+
SET @@session.session_track_system_variables='autocommit';
36+
SELECT @@global.session_track_system_variables;
37+
SELECT @@session.session_track_system_variables;
38+
--echo
39+
40+
--echo # Variables' values in a new session.
41+
connect (con1,"127.0.0.1",root,,test,$MASTER_MYPORT,);
42+
43+
--echo # Global - expect "autocommit"
44+
SELECT @@global.session_track_system_variables;
45+
--echo
46+
--echo # Session - expect "autocommit"
47+
SELECT @@session.session_track_system_variables;
48+
--echo
49+
50+
--echo # Switching to the default connection.
51+
connection default;
52+
53+
SELECT @@global.session_track_system_variables;
54+
SELECT @@session.session_track_system_variables;
55+
--echo
56+
57+
--echo # Test if DEFAULT is working as expected.
58+
SET @@global.session_track_system_variables = DEFAULT;
59+
SET @@session.session_track_system_variables = DEFAULT;
60+
--echo
61+
62+
SELECT @@global.session_track_system_variables;
63+
SELECT @@session.session_track_system_variables;
64+
--echo
65+
66+
--echo # Variables' values in a new session (con2).
67+
connect (con2,"127.0.0.1",root,,test,$MASTER_MYPORT,);
68+
69+
SELECT @@global.session_track_system_variables;
70+
SELECT @@session.session_track_system_variables;
71+
--echo
72+
73+
--echo # Altering session should not affect global.
74+
SET @@session.session_track_system_variables = 'sql_mode';
75+
SELECT @@global.session_track_system_variables;
76+
SELECT @@session.session_track_system_variables;
77+
--echo
78+
79+
--echo # Variables' values in a new session (con3).
80+
connect (con3,"127.0.0.1",root,,test,$MASTER_MYPORT,);
81+
82+
--echo # Altering global should not affect session.
83+
SET @@global.session_track_system_variables = 'sql_mode';
84+
SELECT @@global.session_track_system_variables;
85+
SELECT @@session.session_track_system_variables;
86+
--echo
87+
88+
--echo # Switching to the default connection.
89+
connection default;
90+
91+
--echo # Testing NULL
92+
SET @@global.session_track_system_variables = NULL;
93+
SET @@session.session_track_system_variables = NULL;
94+
95+
--echo # Global - expect "" instead of NULL
96+
SELECT @@global.session_track_system_variables;
97+
--echo # Session - expect "" instead of NULL
98+
SELECT @@session.session_track_system_variables;
99+
100+
--echo # testing with duplicate entries.
101+
# Lets first set it to some valid value.
102+
SET @@global.session_track_system_variables= "time_zone";
103+
SET @@session.session_track_system_variables= "time_zone";
104+
# Now set with duplicate entries (must pass)
105+
SET @@global.session_track_system_variables= "sql_mode,sql_mode";
106+
SET @@session.session_track_system_variables= "sql_mode,sql_mode";
107+
SELECT @@global.session_track_system_variables;
108+
SELECT @@session.session_track_system_variables;
109+
--echo
110+
111+
--echo # testing ordering
112+
SET @@global.session_track_system_variables= "time_zone,sql_mode";
113+
SET @@session.session_track_system_variables= "time_zone,sql_mode";
114+
SELECT @@global.session_track_system_variables;
115+
SELECT @@session.session_track_system_variables;
116+
--echo
117+
118+
--echo # special values
119+
SET @@global.session_track_system_variables= "*";
120+
SET @@session.session_track_system_variables= "*";
121+
SELECT @@global.session_track_system_variables;
122+
SELECT @@session.session_track_system_variables;
123+
SET @@global.session_track_system_variables= "";
124+
SET @@session.session_track_system_variables= "";
125+
SELECT @@global.session_track_system_variables;
126+
SELECT @@session.session_track_system_variables;
127+
--echo
128+
129+
130+
--echo # Restoring the original values.
131+
SET @@global.session_track_system_variables = @global_saved_tmp;
132+
133+
--echo # End of tests.

sql/mysqld.cc

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,14 @@ THD *next_global_thread(THD *thd)
690690
}
691691

692692
struct system_variables global_system_variables;
693+
/**
694+
Following is just for options parsing, used with a difference against
695+
global_system_variables.
696+
697+
TODO: something should be done to get rid of following variables
698+
*/
699+
const char *current_dbug_option="";
700+
693701
struct system_variables max_system_variables;
694702
struct system_status_var global_status_var;
695703

@@ -1463,7 +1471,6 @@ my_bool plugins_are_initialized= FALSE;
14631471
#ifndef DBUG_OFF
14641472
static const char* default_dbug_option;
14651473
#endif
1466-
const char *current_dbug_option="";
14671474
#ifdef HAVE_LIBWRAP
14681475
const char *libwrapName= NULL;
14691476
int allow_severity = LOG_INFO;
@@ -5278,6 +5285,17 @@ static int init_server_components()
52785285
}
52795286
plugins_are_initialized= TRUE; /* Don't separate from init function */
52805287

5288+
{
5289+
Session_tracker session_track_system_variables_check;
5290+
if (session_track_system_variables_check.
5291+
server_boot_verify(system_charset_info))
5292+
{
5293+
sql_print_error("The variable session_track_system_variables has "
5294+
"invalid values.");
5295+
unireg_abort(1);
5296+
}
5297+
}
5298+
52815299
/* we do want to exit if there are any other unknown options */
52825300
if (remaining_argc > 1)
52835301
{

0 commit comments

Comments
 (0)