Skip to content

Commit 66f55a0

Browse files
MDEV-27730 Add PLUGIN_VAR_DEPRECATED flag to plugin variables
The sys_var class has the deprecation_substitute member to mark the deprecated variables. As it's set, the server produces warnings when these variables are used. However, the plugin has no means to utilize that functionality. So, the PLUGIN_VAR_DEPRECATED flag is introduced to set the deprecation_substitute with the empty string. A non-empty string can make the warning more informative, but there's no nice way seen to specify it, and not that needed at the moment.
1 parent 5b237e5 commit 66f55a0

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

include/mysql/plugin.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, void *,
229229
#define PLUGIN_VAR_NOCMDARG 0x1000 /* No argument for cmd line */
230230
#define PLUGIN_VAR_RQCMDARG 0x0000 /* Argument required for cmd line */
231231
#define PLUGIN_VAR_OPCMDARG 0x2000 /* Argument optional for cmd line */
232+
#define PLUGIN_VAR_DEPRECATED 0x4000 /* Server variable is deprecated */
232233
#define PLUGIN_VAR_MEMALLOC 0x8000 /* String needs memory allocated */
233234

234235
struct st_mysql_sys_var;
@@ -282,7 +283,8 @@ typedef void (*mysql_var_update_func)(MYSQL_THD thd,
282283
#define PLUGIN_VAR_MASK \
283284
(PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | \
284285
PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_NOCMDARG | \
285-
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_MEMALLOC)
286+
PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_RQCMDARG | \
287+
PLUGIN_VAR_DEPRECATED | PLUGIN_VAR_MEMALLOC)
286288

287289
#define MYSQL_PLUGIN_VAR_HEADER \
288290
int flags; \

mysql-test/main/plugin.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ a
4040
set global example_ulong_var=500;
4141
set global example_enum_var= e1;
4242
set session example_int_var= -1;
43+
set global example_deprecated_var=1;
44+
Warnings:
45+
Warning 1287 '@@example_deprecated_var' is deprecated and will be removed in a future release
4346
show status like 'example%';
4447
Variable_name Value
4548
Example_func_example enum_var is 0, ulong_var is 500, int_var is -1, double_var is 8.500000, really
4649
show variables like 'example%';
4750
Variable_name Value
51+
example_deprecated_var 0
4852
example_double_thdvar 8.500000
4953
example_double_var 8.500000
5054
example_enum_var e1

mysql-test/main/plugin.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SELECT * FROM t1;
2727
set global example_ulong_var=500;
2828
set global example_enum_var= e1;
2929
set session example_int_var= -1;
30+
set global example_deprecated_var=1;
3031
show status like 'example%';
3132
show variables like 'example%';
3233

sql/sql_plugin.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ class sys_var_pluginvar: public sys_var, public Sql_alloc
291291
struct st_mysql_sys_var *plugin_var;
292292

293293
sys_var_pluginvar(sys_var_chain *chain, const char *name_arg,
294-
st_plugin_int *p, st_mysql_sys_var *plugin_var_arg);
294+
st_plugin_int *p, st_mysql_sys_var *plugin_var_arg,
295+
const char *substitute);
295296
sys_var_pluginvar *cast_pluginvar() { return this; }
296297
uchar* real_value_ptr(THD *thd, enum_var_type type) const;
297298
TYPELIB* plugin_var_typelib(void) const;
@@ -3338,11 +3339,11 @@ static int pluginvar_sysvar_flags(const st_mysql_sys_var *p)
33383339
}
33393340

33403341
sys_var_pluginvar::sys_var_pluginvar(sys_var_chain *chain, const char *name_arg,
3341-
st_plugin_int *p, st_mysql_sys_var *pv)
3342+
st_plugin_int *p, st_mysql_sys_var *pv, const char *substitute)
33423343
: sys_var(chain, name_arg, pv->comment, pluginvar_sysvar_flags(pv),
33433344
0, pv->flags & PLUGIN_VAR_NOCMDOPT ? -1 : 0, NO_ARG,
33443345
pluginvar_show_type(pv), 0,
3345-
NULL, VARIABLE_NOT_IN_BINLOG, NULL, NULL, NULL),
3346+
NULL, VARIABLE_NOT_IN_BINLOG, NULL, NULL, substitute),
33463347
plugin(p), plugin_var(pv)
33473348
{
33483349
plugin_var->name= name_arg;
@@ -4076,7 +4077,8 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
40764077
my_casedn_str(&my_charset_latin1, varname);
40774078
convert_dash_to_underscore(varname, len-1);
40784079
}
4079-
v= new (mem_root) sys_var_pluginvar(&chain, varname, tmp, o);
4080+
const char *s= o->flags & PLUGIN_VAR_DEPRECATED ? "" : NULL;
4081+
v= new (mem_root) sys_var_pluginvar(&chain, varname, tmp, o, s);
40804082
v->test_load= (var ? &var->loaded : &static_unload);
40814083
DBUG_ASSERT(static_unload == FALSE);
40824084

storage/example/ha_example.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,12 +1054,17 @@ static MYSQL_THDVAR_DOUBLE(
10541054
1000.5,
10551055
0);
10561056

1057+
static MYSQL_THDVAR_INT(
1058+
deprecated_var, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_DEPRECATED, "-1..1",
1059+
NULL, NULL, 0, -1, 1, 0);
1060+
10571061
static struct st_mysql_sys_var* example_system_variables[]= {
10581062
MYSQL_SYSVAR(enum_var),
10591063
MYSQL_SYSVAR(ulong_var),
10601064
MYSQL_SYSVAR(int_var),
10611065
MYSQL_SYSVAR(double_var),
10621066
MYSQL_SYSVAR(double_thdvar),
1067+
MYSQL_SYSVAR(deprecated_var),
10631068
MYSQL_SYSVAR(varopt_default),
10641069
NULL
10651070
};

0 commit comments

Comments
 (0)