Skip to content

Commit 894df7e

Browse files
committed
Adieu find_sys_var_ex()
Only take LOCK_plugin for plugin system variables. Reverted optimisation that was originally done for session tracker: it makes much less sense now. Specifically only if connections would want to track plugin session variables changes and these changes would actually happen frequently. If this ever becomes an issue, there're much better ways to optimise this workload. Part of MDEV-14984 - regression in connect performance
1 parent 53671a1 commit 894df7e

File tree

5 files changed

+17
-67
lines changed

5 files changed

+17
-67
lines changed

sql/session_tracker.cc

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
135135
token= var_list.str;
136136

137137
track_all= false;
138-
/*
139-
If Lock to the plugin mutex is not acquired here itself, it results
140-
in having to acquire it multiple times in find_sys_var_ex for each
141-
token value. Hence the mutex is handled here to avoid a performance
142-
overhead.
143-
*/
144-
mysql_mutex_lock(&LOCK_plugin);
145138
for (;;)
146139
{
147140
sys_var *svar;
@@ -165,11 +158,10 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
165158
{
166159
track_all= true;
167160
}
168-
else if ((svar=
169-
find_sys_var_ex(thd, var.str, var.length, throw_error, true)))
161+
else if ((svar= find_sys_var(thd, var.str, var.length, throw_error)))
170162
{
171163
if (insert(svar) == TRUE)
172-
goto error;
164+
return true;
173165
}
174166
else if (throw_error && thd)
175167
{
@@ -179,20 +171,14 @@ bool Session_sysvars_tracker::vars_list::parse_var_list(THD *thd,
179171
"be ignored.", (int)var.length, token);
180172
}
181173
else
182-
goto error;
174+
return true;
183175

184176
if (lasts)
185177
token= lasts + 1;
186178
else
187179
break;
188180
}
189-
mysql_mutex_unlock(&LOCK_plugin);
190-
191181
return false;
192-
193-
error:
194-
mysql_mutex_unlock(&LOCK_plugin);
195-
return true;
196182
}
197183

198184

@@ -211,14 +197,6 @@ bool sysvartrack_validate_value(THD *thd, const char *str, size_t len)
211197

212198
token= var_list.str;
213199

214-
/*
215-
If Lock to the plugin mutex is not acquired here itself, it results
216-
in having to acquire it multiple times in find_sys_var_ex for each
217-
token value. Hence the mutex is handled here to avoid a performance
218-
overhead.
219-
*/
220-
if (!thd)
221-
mysql_mutex_lock(&LOCK_plugin);
222200
for (;;)
223201
{
224202
LEX_CSTRING var;
@@ -237,22 +215,14 @@ bool sysvartrack_validate_value(THD *thd, const char *str, size_t len)
237215
/* Remove leading/trailing whitespace. */
238216
trim_whitespace(system_charset_info, &var);
239217

240-
if(!strcmp(var.str, "*") &&
241-
!find_sys_var_ex(thd, var.str, var.length, false, true))
242-
{
243-
if (!thd)
244-
mysql_mutex_unlock(&LOCK_plugin);
218+
if (!strcmp(var.str, "*") && !find_sys_var(thd, var.str, var.length))
245219
return true;
246-
}
247220

248221
if (lasts)
249222
token= lasts + 1;
250223
else
251224
break;
252225
}
253-
if (!thd)
254-
mysql_mutex_unlock(&LOCK_plugin);
255-
256226
return false;
257227
}
258228

sql/set_var.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ extern SHOW_COMP_OPTION have_openssl;
398398
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted, enum enum_var_type type);
399399
int fill_sysvars(THD *thd, TABLE_LIST *tables, COND *cond);
400400

401-
sys_var *find_sys_var(THD *thd, const char *str, size_t length=0);
401+
sys_var *find_sys_var(THD *thd, const char *str, size_t length= 0,
402+
bool throw_error= false);
402403
int sql_set_variables(THD *thd, List<set_var_base> *var_list, bool free);
403404

404405
#define SYSVAR_AUTOSIZE(VAR,VAL) \

sql/sql_lex.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7254,8 +7254,7 @@ bool LEX::set_system_variable(THD *thd, enum_var_type var_type,
72547254
{
72557255
sys_var *tmp;
72567256
if (unlikely(check_reserved_words(name1)) ||
7257-
unlikely(!(tmp= find_sys_var_ex(thd, name2->str, name2->length, true,
7258-
false))))
7257+
unlikely(!(tmp= find_sys_var(thd, name2->str, name2->length, true))))
72597258
{
72607259
my_error(ER_UNKNOWN_STRUCTURED_VARIABLE, MYF(0),
72617260
(int) name1->length, name1->str);
@@ -7649,7 +7648,7 @@ int set_statement_var_if_exists(THD *thd, const char *var_name,
76497648
my_error(ER_SP_BADSTATEMENT, MYF(0), "[NO]WAIT");
76507649
return 1;
76517650
}
7652-
if ((sysvar= find_sys_var_ex(thd, var_name, var_name_length, true, false)))
7651+
if ((sysvar= find_sys_var(thd, var_name, var_name_length, true)))
76537652
{
76547653
Item *item= new (thd->mem_root) Item_uint(thd, value);
76557654
set_var *var= new (thd->mem_root) set_var(thd, OPT_SESSION, sysvar,

sql/sql_plugin.cc

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,37 +2822,25 @@ static void update_func_double(THD *thd, struct st_mysql_sys_var *var,
28222822
System Variables support
28232823
****************************************************************************/
28242824

2825-
sys_var *find_sys_var_ex(THD *thd, const char *str, size_t length,
2826-
bool throw_error, bool locked)
2825+
sys_var *find_sys_var(THD *thd, const char *str, size_t length,
2826+
bool throw_error)
28272827
{
28282828
sys_var *var;
2829-
sys_var_pluginvar *pi= NULL;
2830-
plugin_ref plugin;
2831-
DBUG_ENTER("find_sys_var_ex");
2829+
sys_var_pluginvar *pi;
2830+
DBUG_ENTER("find_sys_var");
28322831
DBUG_PRINT("enter", ("var '%.*s'", (int)length, str));
28332832

2834-
if (!locked)
2835-
mysql_mutex_lock(&LOCK_plugin);
28362833
mysql_prlock_rdlock(&LOCK_system_variables_hash);
28372834
if ((var= intern_find_sys_var(str, length)) &&
28382835
(pi= var->cast_pluginvar()))
28392836
{
2840-
mysql_prlock_unlock(&LOCK_system_variables_hash);
2841-
LEX *lex= thd ? thd->lex : 0;
2842-
if (!(plugin= intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
2837+
mysql_mutex_lock(&LOCK_plugin);
2838+
if (!intern_plugin_lock(thd ? thd->lex : 0, plugin_int_to_ref(pi->plugin),
2839+
PLUGIN_IS_READY))
28432840
var= NULL; /* failed to lock it, it must be uninstalling */
2844-
else
2845-
if (!(plugin_state(plugin) & PLUGIN_IS_READY))
2846-
{
2847-
/* initialization not completed */
2848-
var= NULL;
2849-
intern_plugin_unlock(lex, plugin);
2850-
}
2851-
}
2852-
else
2853-
mysql_prlock_unlock(&LOCK_system_variables_hash);
2854-
if (!locked)
28552841
mysql_mutex_unlock(&LOCK_plugin);
2842+
}
2843+
mysql_prlock_unlock(&LOCK_system_variables_hash);
28562844

28572845
if (unlikely(!throw_error && !var))
28582846
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0),
@@ -2861,11 +2849,6 @@ sys_var *find_sys_var_ex(THD *thd, const char *str, size_t length,
28612849
}
28622850

28632851

2864-
sys_var *find_sys_var(THD *thd, const char *str, size_t length)
2865-
{
2866-
return find_sys_var_ex(thd, str, length, false, false);
2867-
}
2868-
28692852
/*
28702853
called by register_var, construct_options and test_plugin_options.
28712854
Returns the 'bookmark' for the named variable.

sql/sql_plugin.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ extern void sync_dynamic_session_variables(THD* thd, bool global_lock);
196196
extern bool plugin_dl_foreach(THD *thd, const LEX_CSTRING *dl,
197197
plugin_foreach_func *func, void *arg);
198198

199-
sys_var *find_sys_var_ex(THD *thd, const char *str, size_t length,
200-
bool throw_error, bool locked);
201-
202199
extern void sync_dynamic_session_variables(THD* thd, bool global_lock);
203200
#endif
204201

0 commit comments

Comments
 (0)