Skip to content

Commit 9f5f6b6

Browse files
MDEV-38179 Lock system_variables_hash outside of find_sys_var in Session_sysvars_tracker::vars_list::parse_var_list
This saves 10 calls to pthread_mutex_lock when constructing the initial OK packet for the default session_track_system_variables which has 6 variables Also added a testcase showing there's no need to worry about wildcard session_track_system_variables as it causes construction of empty string in the initial OK packet.
1 parent da66549 commit 9f5f6b6

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ select @@session.session_track_system_variables;
254254
@@session.session_track_system_variables
255255
character_set_client,example_int_var,max_connections,sql_slave_skip_counter
256256
connection default;
257+
disconnect foo;
258+
set global session_track_system_variables='sql_slave_skip_counter,*';
259+
select @@global.session_track_system_variables;
260+
@@global.session_track_system_variables
261+
*
262+
connect foo,localhost,root;
263+
select @@session.session_track_system_variables;
264+
@@session.session_track_system_variables
265+
*
266+
connection default;
257267
SET global session_track_system_variables = @global_saved_tmp;
258268
disconnect foo;
259269
uninstall soname 'ha_example.so';

mysql-test/suite/sys_vars/t/session_track_system_variables_basic.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ enable_session_track_info;
209209
connect foo,localhost,root;
210210
select @@session.session_track_system_variables;
211211

212+
connection default;
213+
disconnect foo;
214+
215+
set global session_track_system_variables='sql_slave_skip_counter,*';
216+
select @@global.session_track_system_variables;
217+
enable_session_track_info;
218+
219+
connect foo,localhost,root;
220+
select @@session.session_track_system_variables;
221+
212222
connection default;
213223

214224
SET global session_track_system_variables = @global_saved_tmp;

sql/session_tracker.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
166166
token= var_list.str;
167167

168168
track_all= false;
169+
mysql_prlock_rdlock(&LOCK_system_variables_hash);
169170
for (;;)
170171
{
171172
sys_var *svar;
@@ -189,7 +190,8 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
189190
{
190191
track_all= true;
191192
}
192-
else if ((svar= find_sys_var(thd, var.str, var.length, throw_error)))
193+
else if ((svar= find_sys_var(thd, var.str, var.length, throw_error,
194+
/*hash_already_locked=*/true)))
193195
{
194196
if (insert(svar) == TRUE)
195197
return true;
@@ -209,6 +211,7 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
209211
else
210212
break;
211213
}
214+
mysql_prlock_unlock(&LOCK_system_variables_hash);
212215
return false;
213216
}
214217

sql/set_var.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted, enum enum_var_type type);
439439
int fill_sysvars(THD *thd, TABLE_LIST *tables, COND *cond);
440440

441441
sys_var *find_sys_var(THD *thd, const char *str, size_t length= 0,
442-
bool throw_error= false);
442+
bool throw_error= false, bool hash_already_locked= false);
443443
int sql_set_variables(THD *thd, List<set_var_base> *var_list, bool free);
444444

445445
#define SYSVAR_AUTOSIZE(VAR,VAL) \

sql/sql_plugin.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2963,14 +2963,15 @@ static void update_func_double(THD *thd, struct st_mysql_sys_var *var,
29632963
****************************************************************************/
29642964

29652965
sys_var *find_sys_var(THD *thd, const char *str, size_t length,
2966-
bool throw_error)
2966+
bool throw_error, bool hash_already_locked)
29672967
{
29682968
sys_var *var;
29692969
sys_var_pluginvar *pi;
29702970
DBUG_ENTER("find_sys_var");
29712971
DBUG_PRINT("enter", ("var '%.*s'", (int)length, str));
29722972

2973-
mysql_prlock_rdlock(&LOCK_system_variables_hash);
2973+
if (!hash_already_locked)
2974+
mysql_prlock_rdlock(&LOCK_system_variables_hash);
29742975
if ((var= intern_find_sys_var(str, length)) &&
29752976
(pi= var->cast_pluginvar()))
29762977
{
@@ -2980,7 +2981,8 @@ sys_var *find_sys_var(THD *thd, const char *str, size_t length,
29802981
var= NULL; /* failed to lock it, it must be uninstalling */
29812982
mysql_mutex_unlock(&LOCK_plugin);
29822983
}
2983-
mysql_prlock_unlock(&LOCK_system_variables_hash);
2984+
if (!hash_already_locked)
2985+
mysql_prlock_unlock(&LOCK_system_variables_hash);
29842986

29852987
if (unlikely(!throw_error && !var))
29862988
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0),

0 commit comments

Comments
 (0)