181
181
{ return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
182
182
bool check_update_type(Item_result type);
183
183
SHOW_TYPE show_type();
184
unsigned char* real_value_ptr(Session *thd, enum_var_type type);
184
unsigned char* real_value_ptr(Session *session, enum_var_type type);
185
185
TYPELIB* plugin_var_typelib(void);
186
unsigned char* value_ptr(Session *thd, enum_var_type type, LEX_STRING *base);
187
bool check(Session *thd, set_var *var);
186
unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
187
bool check(Session *session, set_var *var);
188
188
bool check_default(enum_var_type type __attribute__((unused)))
189
189
{ return is_readonly(); }
190
void set_default(Session *thd,
190
void set_default(Session *session,
191
191
enum_var_type type __attribute__((unused)));
192
bool update(Session *thd, set_var *var);
192
bool update(Session *session, set_var *var);
1308
1308
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1310
1310
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1311
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(thdvar_bool_t, bool);
1311
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
1312
1312
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1313
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(thdvar_str_t, char *);
1313
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
1315
1315
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1316
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(thdvar_enum_t, unsigned long);
1316
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
1317
1317
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1318
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(thdvar_set_t, uint64_t);
1318
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
1320
1320
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1321
1321
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1324
1324
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1325
1325
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1327
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_int_t, int);
1328
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_long_t, long);
1329
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1330
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_uint_t, uint);
1331
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_ulong_t, ulong);
1332
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
1327
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
1328
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
1329
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
1330
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
1331
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
1332
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
1334
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_thd, int offset);
1334
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1337
1337
/****************************************************************************
1338
1338
default variable data check and update functions
1339
1339
****************************************************************************/
1341
static int check_func_bool(Session *thd __attribute__((unused)),
1341
static int check_func_bool(Session *session __attribute__((unused)),
1342
1342
struct st_mysql_sys_var *var,
1343
1343
void *save, st_mysql_value *value)
1784
returns a pointer to the memory which holds the thd-local variable or
1785
a pointer to the global variable if thd==null.
1784
returns a pointer to the memory which holds the session-local variable or
1785
a pointer to the global variable if session==null.
1786
1786
If required, will sync with global variables if the requested variable
1787
1787
has not yet been allocated in the current thread.
1789
static unsigned char *intern_sys_var_ptr(Session* thd, int offset, bool global_lock)
1789
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1791
1791
assert(offset >= 0);
1792
1792
assert((uint)offset <= global_system_variables.dynamic_variables_head);
1795
1795
return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1798
1798
dynamic_variables_head points to the largest valid offset
1800
if (!thd->variables.dynamic_variables_ptr ||
1801
(uint)offset > thd->variables.dynamic_variables_head)
1800
if (!session->variables.dynamic_variables_ptr ||
1801
(uint)offset > session->variables.dynamic_variables_head)
1805
1805
rw_rdlock(&LOCK_system_variables_hash);
1807
thd->variables.dynamic_variables_ptr= (char*)
1808
my_realloc(thd->variables.dynamic_variables_ptr,
1807
session->variables.dynamic_variables_ptr= (char*)
1808
my_realloc(session->variables.dynamic_variables_ptr,
1809
1809
global_variables_dynamic_size,
1810
1810
MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1853
1853
if (global_lock)
1854
1854
pthread_mutex_unlock(&LOCK_global_system_variables);
1856
thd->variables.dynamic_variables_version=
1856
session->variables.dynamic_variables_version=
1857
1857
global_system_variables.dynamic_variables_version;
1858
thd->variables.dynamic_variables_head=
1858
session->variables.dynamic_variables_head=
1859
1859
global_system_variables.dynamic_variables_head;
1860
thd->variables.dynamic_variables_size=
1860
session->variables.dynamic_variables_size=
1861
1861
global_system_variables.dynamic_variables_size;
1863
1863
rw_unlock(&LOCK_system_variables_hash);
1865
return (unsigned char*)thd->variables.dynamic_variables_ptr + offset;
1868
static bool *mysql_sys_var_ptr_bool(Session* a_thd, int offset)
1870
return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1873
static int *mysql_sys_var_ptr_int(Session* a_thd, int offset)
1875
return (int *)intern_sys_var_ptr(a_thd, offset, true);
1878
static long *mysql_sys_var_ptr_long(Session* a_thd, int offset)
1880
return (long *)intern_sys_var_ptr(a_thd, offset, true);
1883
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_thd, int offset)
1885
return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1888
static char **mysql_sys_var_ptr_str(Session* a_thd, int offset)
1890
return (char **)intern_sys_var_ptr(a_thd, offset, true);
1893
static uint64_t *mysql_sys_var_ptr_set(Session* a_thd, int offset)
1895
return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1898
static unsigned long *mysql_sys_var_ptr_enum(Session* a_thd, int offset)
1900
return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
1904
void plugin_thdvar_init(Session *thd)
1906
plugin_ref old_table_plugin= thd->variables.table_plugin;
1908
thd->variables.table_plugin= NULL;
1909
cleanup_variables(thd, &thd->variables);
1911
thd->variables= global_system_variables;
1912
thd->variables.table_plugin= NULL;
1865
return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
1868
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
1870
return (bool *)intern_sys_var_ptr(a_session, offset, true);
1873
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
1875
return (int *)intern_sys_var_ptr(a_session, offset, true);
1878
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
1880
return (long *)intern_sys_var_ptr(a_session, offset, true);
1883
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
1885
return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
1888
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
1890
return (char **)intern_sys_var_ptr(a_session, offset, true);
1893
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
1895
return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
1898
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
1900
return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
1904
void plugin_sessionvar_init(Session *session)
1906
plugin_ref old_table_plugin= session->variables.table_plugin;
1908
session->variables.table_plugin= NULL;
1909
cleanup_variables(session, &session->variables);
1911
session->variables= global_system_variables;
1912
session->variables.table_plugin= NULL;
1914
1914
/* we are going to allocate these lazily */
1915
thd->variables.dynamic_variables_version= 0;
1916
thd->variables.dynamic_variables_size= 0;
1917
thd->variables.dynamic_variables_ptr= 0;
1915
session->variables.dynamic_variables_version= 0;
1916
session->variables.dynamic_variables_size= 0;
1917
session->variables.dynamic_variables_ptr= 0;
1919
thd->variables.table_plugin=
1919
session->variables.table_plugin=
1920
1920
my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1921
1921
intern_plugin_unlock(NULL, old_table_plugin);
1982
void plugin_thdvar_cleanup(Session *thd)
1982
void plugin_sessionvar_cleanup(Session *session)
1985
1985
plugin_ref *list;
1987
unlock_variables(thd, &thd->variables);
1988
cleanup_variables(thd, &thd->variables);
1987
unlock_variables(session, &session->variables);
1988
cleanup_variables(session, &session->variables);
1990
if ((idx= thd->lex->plugins.elements))
1990
if ((idx= session->lex->plugins.elements))
1992
list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
1993
while ((unsigned char*) list >= thd->lex->plugins.buffer)
1992
list= ((plugin_ref*) session->lex->plugins.buffer) + idx - 1;
1993
while ((unsigned char*) list >= session->lex->plugins.buffer)
1994
1994
intern_plugin_unlock(NULL, *list--);
1997
reset_dynamic(&thd->lex->plugins);
1997
reset_dynamic(&session->lex->plugins);
2166
2166
pthread_mutex_lock(&LOCK_global_system_variables);
2167
tgt= real_value_ptr(thd, type);
2167
tgt= real_value_ptr(session, type);
2168
2168
src= ((void **) (plugin_var + 1) + 1);
2170
2170
if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2172
2172
if (type != OPT_GLOBAL)
2173
src= real_value_ptr(thd, OPT_GLOBAL);
2173
src= real_value_ptr(session, OPT_GLOBAL);
2175
2175
switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2176
2176
case PLUGIN_VAR_INT:
2177
src= &((thdvar_uint_t*) plugin_var)->def_val;
2177
src= &((sessionvar_uint_t*) plugin_var)->def_val;
2179
2179
case PLUGIN_VAR_LONG:
2180
src= &((thdvar_ulong_t*) plugin_var)->def_val;
2180
src= &((sessionvar_ulong_t*) plugin_var)->def_val;
2182
2182
case PLUGIN_VAR_LONGLONG:
2183
src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
2183
src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
2185
2185
case PLUGIN_VAR_ENUM:
2186
src= &((thdvar_enum_t*) plugin_var)->def_val;
2186
src= &((sessionvar_enum_t*) plugin_var)->def_val;
2188
2188
case PLUGIN_VAR_SET:
2189
src= &((thdvar_set_t*) plugin_var)->def_val;
2189
src= &((sessionvar_set_t*) plugin_var)->def_val;
2191
2191
case PLUGIN_VAR_BOOL:
2192
src= &((thdvar_bool_t*) plugin_var)->def_val;
2192
src= &((sessionvar_bool_t*) plugin_var)->def_val;
2194
2194
case PLUGIN_VAR_STR:
2195
src= &((thdvar_str_t*) plugin_var)->def_val;
2195
src= &((sessionvar_str_t*) plugin_var)->def_val;
2202
/* thd must equal current_thd if PLUGIN_VAR_SessionLOCAL flag is set */
2202
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2203
2203
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2204
thd == current_thd);
2204
session == current_session);
2206
2206
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
2208
plugin_var->update(thd, plugin_var, tgt, src);
2208
plugin_var->update(session, plugin_var, tgt, src);
2209
2209
pthread_mutex_unlock(&LOCK_global_system_variables);
2213
2213
pthread_mutex_unlock(&LOCK_global_system_variables);
2214
plugin_var->update(thd, plugin_var, tgt, src);
2214
plugin_var->update(session, plugin_var, tgt, src);
2219
bool sys_var_pluginvar::update(Session *thd, set_var *var)
2219
bool sys_var_pluginvar::update(Session *session, set_var *var)
2223
2223
assert(is_readonly() || plugin_var->update);
2225
/* thd must equal current_thd if PLUGIN_VAR_SessionLOCAL flag is set */
2225
/* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
2226
2226
assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
2227
thd == current_thd);
2227
session == current_session);
2229
2229
if (is_readonly())
2232
2232
pthread_mutex_lock(&LOCK_global_system_variables);
2233
tgt= real_value_ptr(thd, var->type);
2233
tgt= real_value_ptr(session, var->type);
2235
2235
if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
2237
2237
/* variable we are updating has global scope, so we unlock after updating */
2238
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2238
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2239
2239
pthread_mutex_unlock(&LOCK_global_system_variables);
2243
2243
pthread_mutex_unlock(&LOCK_global_system_variables);
2244
plugin_var->update(thd, plugin_var, tgt, &var->save_result);
2244
plugin_var->update(session, plugin_var, tgt, &var->save_result);
2307
2307
/* threadlocal variables */
2308
2308
case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
2309
OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
2309
OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
2311
2311
case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2312
OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
2312
OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
2314
2314
case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
2315
OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
2315
OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
2317
2317
case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2318
OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
2318
OPTION_SET_LIMITS(GET_ULONG, options, (sessionvar_ulong_t*) opt);
2320
2320
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
2321
OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
2321
OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
2323
2323
case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
2324
OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
2324
OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
2326
2326
case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2327
2327
options->var_type= GET_ENUM;
2328
options->typelib= ((thdvar_enum_t*) opt)->typelib;
2329
options->def_value= ((thdvar_enum_t*) opt)->def_val;
2328
options->typelib= ((sessionvar_enum_t*) opt)->typelib;
2329
options->def_value= ((sessionvar_enum_t*) opt)->def_val;
2330
2330
options->min_value= options->block_size= 0;
2331
2331
options->max_value= options->typelib->count - 1;
2333
2333
case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2334
2334
options->var_type= GET_SET;
2335
options->typelib= ((thdvar_set_t*) opt)->typelib;
2336
options->def_value= ((thdvar_set_t*) opt)->def_val;
2335
options->typelib= ((sessionvar_set_t*) opt)->typelib;
2336
options->def_value= ((sessionvar_set_t*) opt)->def_val;
2337
2337
options->min_value= options->block_size= 0;
2338
2338
options->max_value= (1UL << options->typelib->count) - 1;
2340
2340
case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
2341
2341
options->var_type= GET_BOOL;
2342
options->def_value= ((thdvar_bool_t*) opt)->def_val;
2342
options->def_value= ((sessionvar_bool_t*) opt)->def_val;
2344
2344
case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
2345
2345
options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2346
2346
GET_STR_ALLOC : GET_STR);
2347
options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
2347
options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
2426
2426
switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2427
2427
case PLUGIN_VAR_BOOL:
2428
(((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2428
(((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2430
2430
case PLUGIN_VAR_INT:
2431
(((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2431
(((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2433
2433
case PLUGIN_VAR_LONG:
2434
(((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2434
(((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2436
2436
case PLUGIN_VAR_LONGLONG:
2437
(((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2437
(((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2439
2439
case PLUGIN_VAR_STR:
2440
(((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2440
(((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2442
2442
case PLUGIN_VAR_ENUM:
2443
(((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2443
(((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2445
2445
case PLUGIN_VAR_SET:
2446
(((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2446
(((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2449
2449
sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),