~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Monty Taylor
  • Date: 2008-10-23 23:53:49 UTC
  • mto: This revision was merged to the branch mainline in revision 557.
  • Revision ID: monty@inaugust.com-20081023235349-317wgwqwgccuacmq
SplitĀ outĀ nested_join.h.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
#include <drizzled/server_includes.h>
17
17
#include <mysys/my_getopt.h>
18
 
#include <authentication.h>
19
 
#include <logging.h>
20
 
#include <drizzled/drizzled_error_messages.h>
 
18
 
 
19
#include <drizzled/authentication.h>
 
20
#include <drizzled/logging.h>
 
21
#include <drizzled/errmsg.h>
 
22
#include <drizzled/configvar.h>
 
23
#include <drizzled/qcache.h>
 
24
#include <drizzled/parser.h>
 
25
#include <drizzled/scheduling.h>
 
26
 
 
27
#include <string>
 
28
 
 
29
#include <drizzled/error.h>
 
30
#include <drizzled/gettext.h>
 
31
 
21
32
#define REPORT_TO_LOG  1
22
33
#define REPORT_TO_USER 2
23
34
 
24
35
#define plugin_ref_to_int(A) (A ? A[0] : NULL)
25
36
#define plugin_int_to_ref(A) &(A)
26
37
 
 
38
using namespace std;
 
39
 
27
40
extern struct st_mysql_plugin *mysqld_builtins[];
28
41
 
29
42
char *opt_plugin_load= NULL;
42
55
  { C_STRING_WITH_LEN("UDA") },
43
56
  { C_STRING_WITH_LEN("AUDIT") },
44
57
  { C_STRING_WITH_LEN("LOGGER") },
45
 
  { C_STRING_WITH_LEN("AUTH") }
 
58
  { C_STRING_WITH_LEN("ERRMSG") },
 
59
  { C_STRING_WITH_LEN("AUTH") },
 
60
  { C_STRING_WITH_LEN("CONFIGVAR") },
 
61
  { C_STRING_WITH_LEN("QCACHE") },
 
62
  { C_STRING_WITH_LEN("PARSER") },
 
63
  { C_STRING_WITH_LEN("SCHEDULING") }
46
64
};
47
65
 
48
66
extern int initialize_schema_table(st_plugin_int *plugin);
65
83
  0,  /* UDA */
66
84
  0,  /* Audit */
67
85
  logging_initializer,  /* Logger */
68
 
  authentication_initializer  /* Auth */
 
86
  errmsg_initializer,  /* Error Messages */
 
87
  authentication_initializer,  /* Auth */
 
88
  configvar_initializer,
 
89
  qcache_initializer,
 
90
  parser_initializer,
 
91
  scheduling_initializer
69
92
};
70
93
 
71
94
plugin_type_init plugin_type_deinitialize[DRIZZLE_MAX_PLUGIN_TYPE_NUM]=
77
100
  0,  /* UDA */
78
101
  0,  /* Audit */
79
102
  logging_finalizer,  /* Logger */
80
 
  authentication_finalizer  /* Auth */
 
103
  errmsg_finalizer,  /* Logger */
 
104
  authentication_finalizer,  /* Auth */
 
105
  configvar_finalizer,
 
106
  qcache_finalizer,
 
107
  parser_finalizer,
 
108
  scheduling_finalizer
81
109
};
82
110
 
83
111
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
115
143
 
116
144
/*
117
145
  stored in bookmark_hash, this structure is never removed from the
118
 
  hash and is used to mark a single offset for a thd local variable
 
146
  hash and is used to mark a single offset for a session local variable
119
147
  even if plugins have been uninstalled and reinstalled, repeatedly.
120
148
  This structure is allocated from plugin_mem_root.
121
149
 
163
191
  sys_var_pluginvar *cast_pluginvar() { return this; }
164
192
  bool is_readonly() const { return plugin_var->flags & PLUGIN_VAR_READONLY; }
165
193
  bool check_type(enum_var_type type)
166
 
  { return !(plugin_var->flags & PLUGIN_VAR_THDLOCAL) && type != OPT_GLOBAL; }
 
194
  { return !(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) && type != OPT_GLOBAL; }
167
195
  bool check_update_type(Item_result type);
168
196
  SHOW_TYPE show_type();
169
 
  unsigned char* real_value_ptr(THD *thd, enum_var_type type);
 
197
  unsigned char* real_value_ptr(Session *session, enum_var_type type);
170
198
  TYPELIB* plugin_var_typelib(void);
171
 
  unsigned char* value_ptr(THD *thd, enum_var_type type, LEX_STRING *base);
172
 
  bool check(THD *thd, set_var *var);
 
199
  unsigned char* value_ptr(Session *session, enum_var_type type, LEX_STRING *base);
 
200
  bool check(Session *session, set_var *var);
173
201
  bool check_default(enum_var_type type __attribute__((unused)))
174
202
    { return is_readonly(); }
175
 
  void set_default(THD *thd,
 
203
  void set_default(Session *session,
176
204
                   enum_var_type type __attribute__((unused)));
177
 
  bool update(THD *thd, set_var *var);
 
205
  bool update(Session *session, set_var *var);
178
206
};
179
207
 
180
208
 
185
213
                               int *, char **);
186
214
static bool register_builtin(struct st_mysql_plugin *, struct st_plugin_int *,
187
215
                             struct st_plugin_int **);
188
 
static void unlock_variables(THD *thd, struct system_variables *vars);
189
 
static void cleanup_variables(THD *thd, struct system_variables *vars);
 
216
static void unlock_variables(Session *session, struct system_variables *vars);
 
217
static void cleanup_variables(Session *session, struct system_variables *vars);
190
218
static void plugin_vars_free_values(sys_var *vars);
191
219
static void plugin_opt_set_limits(struct my_option *options,
192
220
                                  const struct st_mysql_sys_var *opt);
200
228
 
201
229
/* declared in set_var.cc */
202
230
extern sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error);
203
 
extern bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
 
231
extern bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
204
232
                                 const char *name, int64_t val);
205
233
 
206
234
/****************************************************************************
233
261
    Lets be nice and create a temporary string since the
234
262
    buffer was too small
235
263
  */
236
 
  return current_thd->strmake(res->c_ptr_quick(), res->length());
 
264
  return current_session->strmake(res->c_ptr_quick(), res->length());
237
265
}
238
266
 
239
267
 
309
337
 
310
338
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
311
339
{
312
 
  char dlpath[FN_REFLEN];
313
 
  uint32_t plugin_dir_len, dummy_errors, dlpathlen;
 
340
  string dlpath;
 
341
  uint32_t plugin_dir_len, dummy_errors;
314
342
  struct st_plugin_dl *tmp, plugin_dl;
315
343
  void *sym;
316
344
  plugin_dir_len= strlen(opt_plugin_dir);
 
345
  dlpath.reserve(FN_REFLEN);
317
346
  /*
318
347
    Ensure that the dll doesn't have a path.
319
348
    This is done to ensure that only approved libraries from the
327
356
    if (report & REPORT_TO_USER)
328
357
      my_error(ER_UDF_NO_PATHS, MYF(0));
329
358
    if (report & REPORT_TO_LOG)
330
 
      sql_print_error(ER(ER_UDF_NO_PATHS));
 
359
      sql_print_error("%s",ER(ER_UDF_NO_PATHS));
331
360
    return(0);
332
361
  }
333
362
  /* If this dll is already loaded just increase ref_count. */
338
367
  }
339
368
  memset(&plugin_dl, 0, sizeof(plugin_dl));
340
369
  /* Compile dll path */
341
 
  dlpathlen=
342
 
    strxnmov(dlpath, sizeof(dlpath) - 1, opt_plugin_dir, "/", dl->str, NULL) -
343
 
    dlpath;
 
370
  dlpath.append(opt_plugin_dir);
 
371
  dlpath.append("/");
 
372
  dlpath.append(dl->str);
344
373
  plugin_dl.ref_count= 1;
345
374
  /* Open new dll handle */
346
 
  if (!(plugin_dl.handle= dlopen(dlpath, RTLD_LAZY|RTLD_GLOBAL)))
 
375
  if (!(plugin_dl.handle= dlopen(dlpath.c_str(), RTLD_LAZY|RTLD_GLOBAL)))
347
376
  {
348
377
    const char *errmsg=dlerror();
349
 
    if (!strncmp(dlpath, errmsg, dlpathlen))
 
378
    uint32_t dlpathlen= dlpath.length();
 
379
    if (!dlpath.compare(0, dlpathlen, errmsg))
350
380
    { // if errmsg starts from dlpath, trim this prefix.
351
381
      errmsg+=dlpathlen;
352
382
      if (*errmsg == ':') errmsg++;
353
383
      if (*errmsg == ' ') errmsg++;
354
384
    }
355
385
    if (report & REPORT_TO_USER)
356
 
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath, errno, errmsg);
 
386
      my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dlpath.c_str(), errno, errmsg);
357
387
    if (report & REPORT_TO_LOG)
358
 
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath, errno, errmsg);
 
388
      sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dlpath.c_str(), errno, errmsg);
359
389
    return(0);
360
390
  }
361
391
 
506
536
}
507
537
 
508
538
 
509
 
plugin_ref plugin_lock(THD *thd, plugin_ref *ptr CALLER_INFO_PROTO)
 
539
plugin_ref plugin_lock(Session *session, plugin_ref *ptr CALLER_INFO_PROTO)
510
540
{
511
 
  LEX *lex= thd ? thd->lex : 0;
 
541
  LEX *lex= session ? session->lex : 0;
512
542
  plugin_ref rc;
513
543
  rc= my_intern_plugin_lock_ci(lex, *ptr);
514
544
  return(rc);
515
545
}
516
546
 
517
547
 
518
 
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type
 
548
plugin_ref plugin_lock_by_name(Session *session, const LEX_STRING *name, int type
519
549
                               CALLER_INFO_PROTO)
520
550
{
521
 
  LEX *lex= thd ? thd->lex : 0;
 
551
  LEX *lex= session ? session->lex : 0;
522
552
  plugin_ref rc= NULL;
523
553
  st_plugin_int *plugin;
524
554
  if ((plugin= plugin_find_internal(name, type)))
576
606
  for (plugin= tmp.plugin_dl->plugins; plugin->name; plugin++)
577
607
  {
578
608
    uint32_t name_len= strlen(plugin->name);
579
 
    if (plugin->type >= 0 && plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
 
609
    if (plugin->type < DRIZZLE_MAX_PLUGIN_TYPE_NUM &&
580
610
        ! my_strnncoll(system_charset_info,
581
611
                       (const unsigned char *)name->str, name->length,
582
612
                       (const unsigned char *)plugin->name,
655
685
  plugin->state= PLUGIN_IS_UNINITIALIZED;
656
686
 
657
687
  /*
658
 
    We do the check here because NDB has a worker THD which doesn't
 
688
    We do the check here because NDB has a worker Session which doesn't
659
689
    exit until NDB is shut down.
660
690
  */
661
691
  if (ref_check && plugin->ref_count)
752
782
}
753
783
 
754
784
 
755
 
void plugin_unlock(THD *thd, plugin_ref plugin)
 
785
void plugin_unlock(Session *session, plugin_ref plugin)
756
786
{
757
 
  LEX *lex= thd ? thd->lex : 0;
 
787
  LEX *lex= session ? session->lex : 0;
758
788
  if (!plugin)
759
789
    return;
760
790
  intern_plugin_unlock(lex, plugin);
762
792
}
763
793
 
764
794
 
765
 
void plugin_unlock_list(THD *thd, plugin_ref *list, uint32_t count)
 
795
void plugin_unlock_list(Session *session, plugin_ref *list, uint32_t count)
766
796
{
767
 
  LEX *lex= thd ? thd->lex : 0;
 
797
  LEX *lex= session ? session->lex : 0;
768
798
  assert(list);
769
799
  while (count--)
770
800
    intern_plugin_unlock(lex, *list++);
1224
1254
}
1225
1255
 
1226
1256
 
1227
 
bool plugin_foreach_with_mask(THD *thd, plugin_foreach_func *func,
 
1257
bool plugin_foreach_with_mask(Session *session, plugin_foreach_func *func,
1228
1258
                       int type, uint32_t state_mask, void *arg)
1229
1259
{
1230
1260
  uint32_t idx, total;
1270
1300
    }
1271
1301
    plugin= plugins[idx];
1272
1302
    /* It will stop iterating on first engine error when "func" returns true */
1273
 
    if (plugin && func(thd, plugin_int_to_ref(plugin), arg))
 
1303
    if (plugin && func(session, plugin_int_to_ref(plugin), arg))
1274
1304
        goto err;
1275
1305
  }
1276
1306
 
1293
1323
#define EXTRA_OPTIONS 3 /* options for: 'foo', 'plugin-foo' and NULL */
1294
1324
 
1295
1325
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_bool_t, bool);
1296
 
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_bool_t, bool);
 
1326
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_bool_t, bool);
1297
1327
typedef DECLARE_DRIZZLE_SYSVAR_BASIC(sysvar_str_t, char *);
1298
 
typedef DECLARE_DRIZZLE_THDVAR_BASIC(thdvar_str_t, char *);
 
1328
typedef DECLARE_DRIZZLE_SessionVAR_BASIC(sessionvar_str_t, char *);
1299
1329
 
1300
1330
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_enum_t, unsigned long);
1301
 
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_enum_t, unsigned long);
 
1331
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_enum_t, unsigned long);
1302
1332
typedef DECLARE_DRIZZLE_SYSVAR_TYPELIB(sysvar_set_t, uint64_t);
1303
 
typedef DECLARE_DRIZZLE_THDVAR_TYPELIB(thdvar_set_t, uint64_t);
 
1333
typedef DECLARE_DRIZZLE_SessionVAR_TYPELIB(sessionvar_set_t, uint64_t);
1304
1334
 
1305
1335
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_int_t, int);
1306
1336
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_long_t, long);
1309
1339
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_ulong_t, ulong);
1310
1340
typedef DECLARE_DRIZZLE_SYSVAR_SIMPLE(sysvar_uint64_t_t, uint64_t);
1311
1341
 
1312
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int_t, int);
1313
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_long_t, long);
1314
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_int64_t_t, int64_t);
1315
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint_t, uint);
1316
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_ulong_t, ulong);
1317
 
typedef DECLARE_DRIZZLE_THDVAR_SIMPLE(thdvar_uint64_t_t, uint64_t);
 
1342
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int_t, int);
 
1343
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_long_t, long);
 
1344
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_int64_t_t, int64_t);
 
1345
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint_t, uint);
 
1346
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_ulong_t, ulong);
 
1347
typedef DECLARE_DRIZZLE_SessionVAR_SIMPLE(sessionvar_uint64_t_t, uint64_t);
1318
1348
 
1319
 
typedef bool *(*mysql_sys_var_ptr_p)(THD* a_thd, int offset);
 
1349
typedef bool *(*mysql_sys_var_ptr_p)(Session* a_session, int offset);
1320
1350
 
1321
1351
 
1322
1352
/****************************************************************************
1323
1353
  default variable data check and update functions
1324
1354
****************************************************************************/
1325
1355
 
1326
 
static int check_func_bool(THD *thd __attribute__((unused)),
 
1356
static int check_func_bool(Session *session __attribute__((unused)),
1327
1357
                           struct st_mysql_sys_var *var,
1328
1358
                           void *save, st_mysql_value *value)
1329
1359
{
1363
1393
}
1364
1394
 
1365
1395
 
1366
 
static int check_func_int(THD *thd, struct st_mysql_sys_var *var,
 
1396
static int check_func_int(Session *session, struct st_mysql_sys_var *var,
1367
1397
                          void *save, st_mysql_value *value)
1368
1398
{
1369
1399
  bool fixed;
1378
1408
  else
1379
1409
    *(int *)save= (int) getopt_ll_limit_value(tmp, &options, &fixed);
1380
1410
 
1381
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1411
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1382
1412
                              var->name, (int64_t) tmp);
1383
1413
}
1384
1414
 
1385
1415
 
1386
 
static int check_func_long(THD *thd, struct st_mysql_sys_var *var,
 
1416
static int check_func_long(Session *session, struct st_mysql_sys_var *var,
1387
1417
                          void *save, st_mysql_value *value)
1388
1418
{
1389
1419
  bool fixed;
1398
1428
  else
1399
1429
    *(long *)save= (long) getopt_ll_limit_value(tmp, &options, &fixed);
1400
1430
 
1401
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1431
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1402
1432
                              var->name, (int64_t) tmp);
1403
1433
}
1404
1434
 
1405
1435
 
1406
 
static int check_func_int64_t(THD *thd, struct st_mysql_sys_var *var,
 
1436
static int check_func_int64_t(Session *session, struct st_mysql_sys_var *var,
1407
1437
                               void *save, st_mysql_value *value)
1408
1438
{
1409
1439
  bool fixed;
1418
1448
  else
1419
1449
    *(int64_t *)save= getopt_ll_limit_value(tmp, &options, &fixed);
1420
1450
 
1421
 
  return throw_bounds_warning(thd, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
 
1451
  return throw_bounds_warning(session, fixed, var->flags & PLUGIN_VAR_UNSIGNED,
1422
1452
                              var->name, (int64_t) tmp);
1423
1453
}
1424
1454
 
1425
 
static int check_func_str(THD *thd,
 
1455
static int check_func_str(Session *session,
1426
1456
                          struct st_mysql_sys_var *var __attribute__((unused)),
1427
1457
                          void *save, st_mysql_value *value)
1428
1458
{
1432
1462
 
1433
1463
  length= sizeof(buff);
1434
1464
  if ((str= value->val_str(value, buff, &length)))
1435
 
    str= thd->strmake(str, length);
 
1465
    str= session->strmake(str, length);
1436
1466
  *(const char**)save= str;
1437
1467
  return 0;
1438
1468
}
1439
1469
 
1440
1470
 
1441
 
static int check_func_enum(THD *thd __attribute__((unused)),
 
1471
static int check_func_enum(Session *session __attribute__((unused)),
1442
1472
                           struct st_mysql_sys_var *var,
1443
1473
                           void *save, st_mysql_value *value)
1444
1474
{
1449
1479
  long result;
1450
1480
  int length;
1451
1481
 
1452
 
  if (var->flags & PLUGIN_VAR_THDLOCAL)
1453
 
    typelib= ((thdvar_enum_t*) var)->typelib;
 
1482
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
 
1483
    typelib= ((sessionvar_enum_t*) var)->typelib;
1454
1484
  else
1455
1485
    typelib= ((sysvar_enum_t*) var)->typelib;
1456
1486
 
1485
1515
}
1486
1516
 
1487
1517
 
1488
 
static int check_func_set(THD *thd __attribute__((unused)),
 
1518
static int check_func_set(Session *session __attribute__((unused)),
1489
1519
                          struct st_mysql_sys_var *var,
1490
1520
                          void *save, st_mysql_value *value)
1491
1521
{
1497
1527
  bool not_used;
1498
1528
  int length;
1499
1529
 
1500
 
  if (var->flags & PLUGIN_VAR_THDLOCAL)
1501
 
    typelib= ((thdvar_set_t*) var)->typelib;
 
1530
  if (var->flags & PLUGIN_VAR_SessionLOCAL)
 
1531
    typelib= ((sessionvar_set_t*) var)->typelib;
1502
1532
  else
1503
1533
    typelib= ((sysvar_set_t*)var)->typelib;
1504
1534
 
1536
1566
}
1537
1567
 
1538
1568
 
1539
 
static void update_func_bool(THD *thd __attribute__((unused)),
 
1569
static void update_func_bool(Session *session __attribute__((unused)),
1540
1570
                             struct st_mysql_sys_var *var __attribute__((unused)),
1541
1571
                             void *tgt, const void *save)
1542
1572
{
1544
1574
}
1545
1575
 
1546
1576
 
1547
 
static void update_func_int(THD *thd __attribute__((unused)),
 
1577
static void update_func_int(Session *session __attribute__((unused)),
1548
1578
                            struct st_mysql_sys_var *var __attribute__((unused)),
1549
1579
                             void *tgt, const void *save)
1550
1580
{
1552
1582
}
1553
1583
 
1554
1584
 
1555
 
static void update_func_long(THD *thd __attribute__((unused)),
 
1585
static void update_func_long(Session *session __attribute__((unused)),
1556
1586
                             struct st_mysql_sys_var *var __attribute__((unused)),
1557
1587
                             void *tgt, const void *save)
1558
1588
{
1560
1590
}
1561
1591
 
1562
1592
 
1563
 
static void update_func_int64_t(THD *thd __attribute__((unused)),
 
1593
static void update_func_int64_t(Session *session __attribute__((unused)),
1564
1594
                                 struct st_mysql_sys_var *var __attribute__((unused)),
1565
1595
                                 void *tgt, const void *save)
1566
1596
{
1568
1598
}
1569
1599
 
1570
1600
 
1571
 
static void update_func_str(THD *thd __attribute__((unused)), struct st_mysql_sys_var *var,
 
1601
static void update_func_str(Session *session __attribute__((unused)), struct st_mysql_sys_var *var,
1572
1602
                             void *tgt, const void *save)
1573
1603
{
1574
1604
  char *old= *(char **) tgt;
1586
1616
****************************************************************************/
1587
1617
 
1588
1618
 
1589
 
sys_var *find_sys_var(THD *thd, const char *str, uint32_t length)
 
1619
sys_var *find_sys_var(Session *session, const char *str, uint32_t length)
1590
1620
{
1591
1621
  sys_var *var;
1592
1622
  sys_var_pluginvar *pi= NULL;
1597
1627
      (pi= var->cast_pluginvar()))
1598
1628
  {
1599
1629
    rw_unlock(&LOCK_system_variables_hash);
1600
 
    LEX *lex= thd ? thd->lex : 0;
 
1630
    LEX *lex= session ? session->lex : 0;
1601
1631
    if (!(plugin= my_intern_plugin_lock(lex, plugin_int_to_ref(pi->plugin))))
1602
1632
      var= NULL; /* failed to lock it, it must be uninstalling */
1603
1633
    else
1632
1662
  uint32_t namelen, length, pluginlen= 0;
1633
1663
  char *varname, *p;
1634
1664
 
1635
 
  if (!(flags & PLUGIN_VAR_THDLOCAL))
 
1665
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
1636
1666
    return NULL;
1637
1667
 
1638
1668
  namelen= strlen(name);
1662
1692
 
1663
1693
 
1664
1694
/*
1665
 
  returns a bookmark for thd-local variables, creating if neccessary.
1666
 
  returns null for non thd-local variables.
 
1695
  returns a bookmark for session-local variables, creating if neccessary.
 
1696
  returns null for non session-local variables.
1667
1697
  Requires that a write lock is obtained on LOCK_system_variables_hash
1668
1698
*/
1669
1699
static st_bookmark *register_var(const char *plugin, const char *name,
1673
1703
  st_bookmark *result;
1674
1704
  char *varname, *p;
1675
1705
 
1676
 
  if (!(flags & PLUGIN_VAR_THDLOCAL))
 
1706
  if (!(flags & PLUGIN_VAR_SessionLOCAL))
1677
1707
    return NULL;
1678
1708
 
1679
1709
  switch (flags & PLUGIN_VAR_TYPEMASK) {
1766
1796
 
1767
1797
 
1768
1798
/*
1769
 
  returns a pointer to the memory which holds the thd-local variable or
1770
 
  a pointer to the global variable if thd==null.
 
1799
  returns a pointer to the memory which holds the session-local variable or
 
1800
  a pointer to the global variable if session==null.
1771
1801
  If required, will sync with global variables if the requested variable
1772
1802
  has not yet been allocated in the current thread.
1773
1803
*/
1774
 
static unsigned char *intern_sys_var_ptr(THD* thd, int offset, bool global_lock)
 
1804
static unsigned char *intern_sys_var_ptr(Session* session, int offset, bool global_lock)
1775
1805
{
1776
1806
  assert(offset >= 0);
1777
1807
  assert((uint)offset <= global_system_variables.dynamic_variables_head);
1778
1808
 
1779
 
  if (!thd)
 
1809
  if (!session)
1780
1810
    return (unsigned char*) global_system_variables.dynamic_variables_ptr + offset;
1781
1811
 
1782
1812
  /*
1783
1813
    dynamic_variables_head points to the largest valid offset
1784
1814
  */
1785
 
  if (!thd->variables.dynamic_variables_ptr ||
1786
 
      (uint)offset > thd->variables.dynamic_variables_head)
 
1815
  if (!session->variables.dynamic_variables_ptr ||
 
1816
      (uint)offset > session->variables.dynamic_variables_head)
1787
1817
  {
1788
1818
    uint32_t idx;
1789
1819
 
1790
1820
    rw_rdlock(&LOCK_system_variables_hash);
1791
1821
 
1792
 
    thd->variables.dynamic_variables_ptr= (char*)
1793
 
      my_realloc(thd->variables.dynamic_variables_ptr,
 
1822
    session->variables.dynamic_variables_ptr= (char*)
 
1823
      my_realloc(session->variables.dynamic_variables_ptr,
1794
1824
                 global_variables_dynamic_size,
1795
1825
                 MYF(MY_WME | MY_FAE | MY_ALLOW_ZERO_PTR));
1796
1826
 
1799
1829
 
1800
1830
    safe_mutex_assert_owner(&LOCK_global_system_variables);
1801
1831
 
1802
 
    memcpy(thd->variables.dynamic_variables_ptr +
1803
 
             thd->variables.dynamic_variables_size,
 
1832
    memcpy(session->variables.dynamic_variables_ptr +
 
1833
             session->variables.dynamic_variables_size,
1804
1834
           global_system_variables.dynamic_variables_ptr +
1805
 
             thd->variables.dynamic_variables_size,
 
1835
             session->variables.dynamic_variables_size,
1806
1836
           global_system_variables.dynamic_variables_size -
1807
 
             thd->variables.dynamic_variables_size);
 
1837
             session->variables.dynamic_variables_size);
1808
1838
 
1809
1839
    /*
1810
1840
      now we need to iterate through any newly copied 'defaults'
1816
1846
      sys_var *var;
1817
1847
      st_bookmark *v= (st_bookmark*) hash_element(&bookmark_hash,idx);
1818
1848
 
1819
 
      if (v->version <= thd->variables.dynamic_variables_version ||
 
1849
      if (v->version <= session->variables.dynamic_variables_version ||
1820
1850
          !(var= intern_find_sys_var(v->key + 1, v->name_len, true)) ||
1821
1851
          !(pi= var->cast_pluginvar()) ||
1822
1852
          v->key[0] != (pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK))
1827
1857
      if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1828
1858
          pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
1829
1859
      {
1830
 
         char **pp= (char**) (thd->variables.dynamic_variables_ptr +
 
1860
         char **pp= (char**) (session->variables.dynamic_variables_ptr +
1831
1861
                             *(int*)(pi->plugin_var + 1));
1832
1862
         if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
1833
1863
                             *(int*)(pi->plugin_var + 1))))
1838
1868
    if (global_lock)
1839
1869
      pthread_mutex_unlock(&LOCK_global_system_variables);
1840
1870
 
1841
 
    thd->variables.dynamic_variables_version=
 
1871
    session->variables.dynamic_variables_version=
1842
1872
           global_system_variables.dynamic_variables_version;
1843
 
    thd->variables.dynamic_variables_head=
 
1873
    session->variables.dynamic_variables_head=
1844
1874
           global_system_variables.dynamic_variables_head;
1845
 
    thd->variables.dynamic_variables_size=
 
1875
    session->variables.dynamic_variables_size=
1846
1876
           global_system_variables.dynamic_variables_size;
1847
1877
 
1848
1878
    rw_unlock(&LOCK_system_variables_hash);
1849
1879
  }
1850
 
  return (unsigned char*)thd->variables.dynamic_variables_ptr + offset;
1851
 
}
1852
 
 
1853
 
static bool *mysql_sys_var_ptr_bool(THD* a_thd, int offset)
1854
 
{
1855
 
  return (bool *)intern_sys_var_ptr(a_thd, offset, true);
1856
 
}
1857
 
 
1858
 
static int *mysql_sys_var_ptr_int(THD* a_thd, int offset)
1859
 
{
1860
 
  return (int *)intern_sys_var_ptr(a_thd, offset, true);
1861
 
}
1862
 
 
1863
 
static long *mysql_sys_var_ptr_long(THD* a_thd, int offset)
1864
 
{
1865
 
  return (long *)intern_sys_var_ptr(a_thd, offset, true);
1866
 
}
1867
 
 
1868
 
static int64_t *mysql_sys_var_ptr_int64_t(THD* a_thd, int offset)
1869
 
{
1870
 
  return (int64_t *)intern_sys_var_ptr(a_thd, offset, true);
1871
 
}
1872
 
 
1873
 
static char **mysql_sys_var_ptr_str(THD* a_thd, int offset)
1874
 
{
1875
 
  return (char **)intern_sys_var_ptr(a_thd, offset, true);
1876
 
}
1877
 
 
1878
 
static uint64_t *mysql_sys_var_ptr_set(THD* a_thd, int offset)
1879
 
{
1880
 
  return (uint64_t *)intern_sys_var_ptr(a_thd, offset, true);
1881
 
}
1882
 
 
1883
 
static unsigned long *mysql_sys_var_ptr_enum(THD* a_thd, int offset)
1884
 
{
1885
 
  return (unsigned long *)intern_sys_var_ptr(a_thd, offset, true);
1886
 
}
1887
 
 
1888
 
 
1889
 
void plugin_thdvar_init(THD *thd)
1890
 
{
1891
 
  plugin_ref old_table_plugin= thd->variables.table_plugin;
1892
 
  
1893
 
  thd->variables.table_plugin= NULL;
1894
 
  cleanup_variables(thd, &thd->variables);
1895
 
  
1896
 
  thd->variables= global_system_variables;
1897
 
  thd->variables.table_plugin= NULL;
 
1880
  return (unsigned char*)session->variables.dynamic_variables_ptr + offset;
 
1881
}
 
1882
 
 
1883
static bool *mysql_sys_var_ptr_bool(Session* a_session, int offset)
 
1884
{
 
1885
  return (bool *)intern_sys_var_ptr(a_session, offset, true);
 
1886
}
 
1887
 
 
1888
static int *mysql_sys_var_ptr_int(Session* a_session, int offset)
 
1889
{
 
1890
  return (int *)intern_sys_var_ptr(a_session, offset, true);
 
1891
}
 
1892
 
 
1893
static long *mysql_sys_var_ptr_long(Session* a_session, int offset)
 
1894
{
 
1895
  return (long *)intern_sys_var_ptr(a_session, offset, true);
 
1896
}
 
1897
 
 
1898
static int64_t *mysql_sys_var_ptr_int64_t(Session* a_session, int offset)
 
1899
{
 
1900
  return (int64_t *)intern_sys_var_ptr(a_session, offset, true);
 
1901
}
 
1902
 
 
1903
static char **mysql_sys_var_ptr_str(Session* a_session, int offset)
 
1904
{
 
1905
  return (char **)intern_sys_var_ptr(a_session, offset, true);
 
1906
}
 
1907
 
 
1908
static uint64_t *mysql_sys_var_ptr_set(Session* a_session, int offset)
 
1909
{
 
1910
  return (uint64_t *)intern_sys_var_ptr(a_session, offset, true);
 
1911
}
 
1912
 
 
1913
static unsigned long *mysql_sys_var_ptr_enum(Session* a_session, int offset)
 
1914
{
 
1915
  return (unsigned long *)intern_sys_var_ptr(a_session, offset, true);
 
1916
}
 
1917
 
 
1918
 
 
1919
void plugin_sessionvar_init(Session *session)
 
1920
{
 
1921
  plugin_ref old_table_plugin= session->variables.table_plugin;
 
1922
  
 
1923
  session->variables.table_plugin= NULL;
 
1924
  cleanup_variables(session, &session->variables);
 
1925
  
 
1926
  session->variables= global_system_variables;
 
1927
  session->variables.table_plugin= NULL;
1898
1928
 
1899
1929
  /* we are going to allocate these lazily */
1900
 
  thd->variables.dynamic_variables_version= 0;
1901
 
  thd->variables.dynamic_variables_size= 0;
1902
 
  thd->variables.dynamic_variables_ptr= 0;
 
1930
  session->variables.dynamic_variables_version= 0;
 
1931
  session->variables.dynamic_variables_size= 0;
 
1932
  session->variables.dynamic_variables_ptr= 0;
1903
1933
 
1904
 
  thd->variables.table_plugin=
 
1934
  session->variables.table_plugin=
1905
1935
        my_intern_plugin_lock(NULL, global_system_variables.table_plugin);
1906
1936
  intern_plugin_unlock(NULL, old_table_plugin);
1907
1937
  return;
1911
1941
/*
1912
1942
  Unlocks all system variables which hold a reference
1913
1943
*/
1914
 
static void unlock_variables(THD *thd __attribute__((unused)),
 
1944
static void unlock_variables(Session *session __attribute__((unused)),
1915
1945
                             struct system_variables *vars)
1916
1946
{
1917
1947
  intern_plugin_unlock(NULL, vars->table_plugin);
1925
1955
  Unlike plugin_vars_free_values() it frees all variables of all plugins,
1926
1956
  it's used on shutdown.
1927
1957
*/
1928
 
static void cleanup_variables(THD *thd, struct system_variables *vars)
 
1958
static void cleanup_variables(Session *session, struct system_variables *vars)
1929
1959
{
1930
1960
  st_bookmark *v;
1931
1961
  sys_var_pluginvar *pivar;
1946
1976
    flags= pivar->plugin_var->flags;
1947
1977
 
1948
1978
    if ((flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
1949
 
        flags & PLUGIN_VAR_THDLOCAL && flags & PLUGIN_VAR_MEMALLOC)
 
1979
        flags & PLUGIN_VAR_SessionLOCAL && flags & PLUGIN_VAR_MEMALLOC)
1950
1980
    {
1951
 
      char **ptr= (char**) pivar->real_value_ptr(thd, OPT_SESSION);
 
1981
      char **ptr= (char**) pivar->real_value_ptr(session, OPT_SESSION);
1952
1982
      free(*ptr);
1953
1983
      *ptr= NULL;
1954
1984
    }
1964
1994
}
1965
1995
 
1966
1996
 
1967
 
void plugin_thdvar_cleanup(THD *thd)
 
1997
void plugin_sessionvar_cleanup(Session *session)
1968
1998
{
1969
1999
  uint32_t idx;
1970
2000
  plugin_ref *list;
1971
2001
 
1972
 
  unlock_variables(thd, &thd->variables);
1973
 
  cleanup_variables(thd, &thd->variables);
 
2002
  unlock_variables(session, &session->variables);
 
2003
  cleanup_variables(session, &session->variables);
1974
2004
 
1975
 
  if ((idx= thd->lex->plugins.elements))
 
2005
  if ((idx= session->lex->plugins.elements))
1976
2006
  {
1977
 
    list= ((plugin_ref*) thd->lex->plugins.buffer) + idx - 1;
1978
 
    while ((unsigned char*) list >= thd->lex->plugins.buffer)
 
2007
    list= ((plugin_ref*) session->lex->plugins.buffer) + idx - 1;
 
2008
    while ((unsigned char*) list >= session->lex->plugins.buffer)
1979
2009
      intern_plugin_unlock(NULL, *list--);
1980
2010
  }
1981
2011
 
1982
 
  reset_dynamic(&thd->lex->plugins);
 
2012
  reset_dynamic(&session->lex->plugins);
1983
2013
 
1984
2014
  return;
1985
2015
}
2056
2086
}
2057
2087
 
2058
2088
 
2059
 
unsigned char* sys_var_pluginvar::real_value_ptr(THD *thd, enum_var_type type)
 
2089
unsigned char* sys_var_pluginvar::real_value_ptr(Session *session, enum_var_type type)
2060
2090
{
2061
 
  assert(thd || (type == OPT_GLOBAL));
2062
 
  if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
 
2091
  assert(session || (type == OPT_GLOBAL));
 
2092
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2063
2093
  {
2064
2094
    if (type == OPT_GLOBAL)
2065
 
      thd= NULL;
 
2095
      session= NULL;
2066
2096
 
2067
 
    return intern_sys_var_ptr(thd, *(int*) (plugin_var+1), false);
 
2097
    return intern_sys_var_ptr(session, *(int*) (plugin_var+1), false);
2068
2098
  }
2069
2099
  return *(unsigned char**) (plugin_var+1);
2070
2100
}
2072
2102
 
2073
2103
TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
2074
2104
{
2075
 
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_THDLOCAL)) {
 
2105
  switch (plugin_var->flags & (PLUGIN_VAR_TYPEMASK | PLUGIN_VAR_SessionLOCAL)) {
2076
2106
  case PLUGIN_VAR_ENUM:
2077
2107
    return ((sysvar_enum_t *)plugin_var)->typelib;
2078
2108
  case PLUGIN_VAR_SET:
2079
2109
    return ((sysvar_set_t *)plugin_var)->typelib;
2080
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
2081
 
    return ((thdvar_enum_t *)plugin_var)->typelib;
2082
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
2083
 
    return ((thdvar_set_t *)plugin_var)->typelib;
 
2110
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
 
2111
    return ((sessionvar_enum_t *)plugin_var)->typelib;
 
2112
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
 
2113
    return ((sessionvar_set_t *)plugin_var)->typelib;
2084
2114
  default:
2085
2115
    return NULL;
2086
2116
  }
2088
2118
}
2089
2119
 
2090
2120
 
2091
 
unsigned char* sys_var_pluginvar::value_ptr(THD *thd, enum_var_type type,
 
2121
unsigned char* sys_var_pluginvar::value_ptr(Session *session, enum_var_type type,
2092
2122
                                    LEX_STRING *base __attribute__((unused)))
2093
2123
{
2094
2124
  unsigned char* result;
2095
2125
 
2096
 
  result= real_value_ptr(thd, type);
 
2126
  result= real_value_ptr(session, type);
2097
2127
 
2098
2128
  if ((plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_ENUM)
2099
2129
    result= (unsigned char*) get_type(plugin_var_typelib(), *(ulong*)result);
2116
2146
 
2117
2147
    result= (unsigned char*) "";
2118
2148
    if (str.length())
2119
 
      result= (unsigned char*) thd->strmake(str.ptr(), str.length()-1);
 
2149
      result= (unsigned char*) session->strmake(str.ptr(), str.length()-1);
2120
2150
  }
2121
2151
  return result;
2122
2152
}
2123
2153
 
2124
2154
 
2125
 
bool sys_var_pluginvar::check(THD *thd, set_var *var)
 
2155
bool sys_var_pluginvar::check(Session *session, set_var *var)
2126
2156
{
2127
2157
  st_item_value_holder value;
2128
2158
  assert(is_readonly() || plugin_var->check);
2134
2164
  value.item= var->value;
2135
2165
 
2136
2166
  return is_readonly() ||
2137
 
         plugin_var->check(thd, plugin_var, &var->save_result, &value);
 
2167
         plugin_var->check(session, plugin_var, &var->save_result, &value);
2138
2168
}
2139
2169
 
2140
2170
 
2141
 
void sys_var_pluginvar::set_default(THD *thd, enum_var_type type)
 
2171
void sys_var_pluginvar::set_default(Session *session, enum_var_type type)
2142
2172
{
2143
2173
  const void *src;
2144
2174
  void *tgt;
2149
2179
    return;
2150
2180
 
2151
2181
  pthread_mutex_lock(&LOCK_global_system_variables);
2152
 
  tgt= real_value_ptr(thd, type);
 
2182
  tgt= real_value_ptr(session, type);
2153
2183
  src= ((void **) (plugin_var + 1) + 1);
2154
2184
 
2155
 
  if (plugin_var->flags & PLUGIN_VAR_THDLOCAL)
 
2185
  if (plugin_var->flags & PLUGIN_VAR_SessionLOCAL)
2156
2186
  {
2157
2187
    if (type != OPT_GLOBAL)
2158
 
      src= real_value_ptr(thd, OPT_GLOBAL);
 
2188
      src= real_value_ptr(session, OPT_GLOBAL);
2159
2189
    else
2160
2190
    switch (plugin_var->flags & PLUGIN_VAR_TYPEMASK) {
2161
2191
        case PLUGIN_VAR_INT:
2162
 
          src= &((thdvar_uint_t*) plugin_var)->def_val;
 
2192
          src= &((sessionvar_uint_t*) plugin_var)->def_val;
2163
2193
          break;
2164
2194
        case PLUGIN_VAR_LONG:
2165
 
          src= &((thdvar_ulong_t*) plugin_var)->def_val;
 
2195
          src= &((sessionvar_ulong_t*) plugin_var)->def_val;
2166
2196
          break;
2167
2197
        case PLUGIN_VAR_LONGLONG:
2168
 
          src= &((thdvar_uint64_t_t*) plugin_var)->def_val;
 
2198
          src= &((sessionvar_uint64_t_t*) plugin_var)->def_val;
2169
2199
          break;
2170
2200
        case PLUGIN_VAR_ENUM:
2171
 
          src= &((thdvar_enum_t*) plugin_var)->def_val;
 
2201
          src= &((sessionvar_enum_t*) plugin_var)->def_val;
2172
2202
          break;
2173
2203
        case PLUGIN_VAR_SET:
2174
 
          src= &((thdvar_set_t*) plugin_var)->def_val;
 
2204
          src= &((sessionvar_set_t*) plugin_var)->def_val;
2175
2205
          break;
2176
2206
        case PLUGIN_VAR_BOOL:
2177
 
          src= &((thdvar_bool_t*) plugin_var)->def_val;
 
2207
          src= &((sessionvar_bool_t*) plugin_var)->def_val;
2178
2208
          break;
2179
2209
        case PLUGIN_VAR_STR:
2180
 
          src= &((thdvar_str_t*) plugin_var)->def_val;
 
2210
          src= &((sessionvar_str_t*) plugin_var)->def_val;
2181
2211
          break;
2182
2212
        default:
2183
2213
          assert(0);
2184
2214
        }
2185
2215
  }
2186
2216
 
2187
 
  /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2188
 
  assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2189
 
              thd == current_thd);
 
2217
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
 
2218
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
 
2219
              session == current_session);
2190
2220
 
2191
 
  if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || type == OPT_GLOBAL)
 
2221
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || type == OPT_GLOBAL)
2192
2222
  {
2193
 
    plugin_var->update(thd, plugin_var, tgt, src);
 
2223
    plugin_var->update(session, plugin_var, tgt, src);
2194
2224
    pthread_mutex_unlock(&LOCK_global_system_variables);
2195
2225
  }
2196
2226
  else
2197
2227
  {
2198
2228
    pthread_mutex_unlock(&LOCK_global_system_variables);
2199
 
    plugin_var->update(thd, plugin_var, tgt, src);
 
2229
    plugin_var->update(session, plugin_var, tgt, src);
2200
2230
  }
2201
2231
}
2202
2232
 
2203
2233
 
2204
 
bool sys_var_pluginvar::update(THD *thd, set_var *var)
 
2234
bool sys_var_pluginvar::update(Session *session, set_var *var)
2205
2235
{
2206
2236
  void *tgt;
2207
2237
 
2208
2238
  assert(is_readonly() || plugin_var->update);
2209
2239
 
2210
 
  /* thd must equal current_thd if PLUGIN_VAR_THDLOCAL flag is set */
2211
 
  assert(!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) ||
2212
 
              thd == current_thd);
 
2240
  /* session must equal current_session if PLUGIN_VAR_SessionLOCAL flag is set */
 
2241
  assert(!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) ||
 
2242
              session == current_session);
2213
2243
 
2214
2244
  if (is_readonly())
2215
2245
    return 1;
2216
2246
 
2217
2247
  pthread_mutex_lock(&LOCK_global_system_variables);
2218
 
  tgt= real_value_ptr(thd, var->type);
 
2248
  tgt= real_value_ptr(session, var->type);
2219
2249
 
2220
 
  if (!(plugin_var->flags & PLUGIN_VAR_THDLOCAL) || var->type == OPT_GLOBAL)
 
2250
  if (!(plugin_var->flags & PLUGIN_VAR_SessionLOCAL) || var->type == OPT_GLOBAL)
2221
2251
  {
2222
2252
    /* variable we are updating has global scope, so we unlock after updating */
2223
 
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
 
2253
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
2224
2254
    pthread_mutex_unlock(&LOCK_global_system_variables);
2225
2255
  }
2226
2256
  else
2227
2257
  {
2228
2258
    pthread_mutex_unlock(&LOCK_global_system_variables);
2229
 
    plugin_var->update(thd, plugin_var, tgt, &var->save_result);
 
2259
    plugin_var->update(session, plugin_var, tgt, &var->save_result);
2230
2260
  }
2231
2261
 return 0;
2232
2262
}
2246
2276
  options->sub_size= 0;
2247
2277
 
2248
2278
  switch (opt->flags & (PLUGIN_VAR_TYPEMASK |
2249
 
                        PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL)) {
 
2279
                        PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL)) {
2250
2280
  /* global system variables */
2251
2281
  case PLUGIN_VAR_INT:
2252
2282
    OPTION_SET_LIMITS(GET_INT, options, (sysvar_int_t*) opt);
2290
2320
    options->def_value= (intptr_t) ((sysvar_str_t*) opt)->def_val;
2291
2321
    break;
2292
2322
  /* threadlocal variables */
2293
 
  case PLUGIN_VAR_INT | PLUGIN_VAR_THDLOCAL:
2294
 
    OPTION_SET_LIMITS(GET_INT, options, (thdvar_int_t*) opt);
2295
 
    break;
2296
 
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2297
 
    OPTION_SET_LIMITS(GET_UINT, options, (thdvar_uint_t*) opt);
2298
 
    break;
2299
 
  case PLUGIN_VAR_LONG | PLUGIN_VAR_THDLOCAL:
2300
 
    OPTION_SET_LIMITS(GET_LONG, options, (thdvar_long_t*) opt);
2301
 
    break;
2302
 
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2303
 
    OPTION_SET_LIMITS(GET_ULONG, options, (thdvar_ulong_t*) opt);
2304
 
    break;
2305
 
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_THDLOCAL:
2306
 
    OPTION_SET_LIMITS(GET_LL, options, (thdvar_int64_t_t*) opt);
2307
 
    break;
2308
 
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_THDLOCAL:
2309
 
    OPTION_SET_LIMITS(GET_ULL, options, (thdvar_uint64_t_t*) opt);
2310
 
    break;
2311
 
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_THDLOCAL:
 
2323
  case PLUGIN_VAR_INT | PLUGIN_VAR_SessionLOCAL:
 
2324
    OPTION_SET_LIMITS(GET_INT, options, (sessionvar_int_t*) opt);
 
2325
    break;
 
2326
  case PLUGIN_VAR_INT | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
 
2327
    OPTION_SET_LIMITS(GET_UINT, options, (sessionvar_uint_t*) opt);
 
2328
    break;
 
2329
  case PLUGIN_VAR_LONG | PLUGIN_VAR_SessionLOCAL:
 
2330
    OPTION_SET_LIMITS(GET_LONG, options, (sessionvar_long_t*) opt);
 
2331
    break;
 
2332
  case PLUGIN_VAR_LONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
 
2333
    OPTION_SET_LIMITS(GET_ULONG, options, (sessionvar_ulong_t*) opt);
 
2334
    break;
 
2335
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_SessionLOCAL:
 
2336
    OPTION_SET_LIMITS(GET_LL, options, (sessionvar_int64_t_t*) opt);
 
2337
    break;
 
2338
  case PLUGIN_VAR_LONGLONG | PLUGIN_VAR_UNSIGNED | PLUGIN_VAR_SessionLOCAL:
 
2339
    OPTION_SET_LIMITS(GET_ULL, options, (sessionvar_uint64_t_t*) opt);
 
2340
    break;
 
2341
  case PLUGIN_VAR_ENUM | PLUGIN_VAR_SessionLOCAL:
2312
2342
    options->var_type= GET_ENUM;
2313
 
    options->typelib= ((thdvar_enum_t*) opt)->typelib;
2314
 
    options->def_value= ((thdvar_enum_t*) opt)->def_val;
 
2343
    options->typelib= ((sessionvar_enum_t*) opt)->typelib;
 
2344
    options->def_value= ((sessionvar_enum_t*) opt)->def_val;
2315
2345
    options->min_value= options->block_size= 0;
2316
2346
    options->max_value= options->typelib->count - 1;
2317
2347
    break;
2318
 
  case PLUGIN_VAR_SET | PLUGIN_VAR_THDLOCAL:
 
2348
  case PLUGIN_VAR_SET | PLUGIN_VAR_SessionLOCAL:
2319
2349
    options->var_type= GET_SET;
2320
 
    options->typelib= ((thdvar_set_t*) opt)->typelib;
2321
 
    options->def_value= ((thdvar_set_t*) opt)->def_val;
 
2350
    options->typelib= ((sessionvar_set_t*) opt)->typelib;
 
2351
    options->def_value= ((sessionvar_set_t*) opt)->def_val;
2322
2352
    options->min_value= options->block_size= 0;
2323
2353
    options->max_value= (1UL << options->typelib->count) - 1;
2324
2354
    break;
2325
 
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_THDLOCAL:
 
2355
  case PLUGIN_VAR_BOOL | PLUGIN_VAR_SessionLOCAL:
2326
2356
    options->var_type= GET_BOOL;
2327
 
    options->def_value= ((thdvar_bool_t*) opt)->def_val;
 
2357
    options->def_value= ((sessionvar_bool_t*) opt)->def_val;
2328
2358
    break;
2329
 
  case PLUGIN_VAR_STR | PLUGIN_VAR_THDLOCAL:
 
2359
  case PLUGIN_VAR_STR | PLUGIN_VAR_SessionLOCAL:
2330
2360
    options->var_type= ((opt->flags & PLUGIN_VAR_MEMALLOC) ?
2331
2361
                        GET_STR_ALLOC : GET_STR);
2332
 
    options->def_value= (intptr_t) ((thdvar_str_t*) opt)->def_val;
 
2362
    options->def_value= (intptr_t) ((sessionvar_str_t*) opt)->def_val;
2333
2363
    break;
2334
2364
  default:
2335
2365
    assert(0);
2404
2434
       plugin_option && *plugin_option; plugin_option++, index++)
2405
2435
  {
2406
2436
    opt= *plugin_option;
2407
 
    if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
 
2437
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2408
2438
      continue;
2409
2439
    if (!(register_var(name, opt->name, opt->flags)))
2410
2440
      continue;
2411
2441
    switch (opt->flags & PLUGIN_VAR_TYPEMASK) {
2412
2442
    case PLUGIN_VAR_BOOL:
2413
 
      (((thdvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
 
2443
      (((sessionvar_bool_t *)opt)->resolve)= mysql_sys_var_ptr_bool;
2414
2444
      break;
2415
2445
    case PLUGIN_VAR_INT:
2416
 
      (((thdvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
 
2446
      (((sessionvar_int_t *)opt)->resolve)= mysql_sys_var_ptr_int;
2417
2447
      break;
2418
2448
    case PLUGIN_VAR_LONG:
2419
 
      (((thdvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
 
2449
      (((sessionvar_long_t *)opt)->resolve)= mysql_sys_var_ptr_long;
2420
2450
      break;
2421
2451
    case PLUGIN_VAR_LONGLONG:
2422
 
      (((thdvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
 
2452
      (((sessionvar_int64_t_t *)opt)->resolve)= mysql_sys_var_ptr_int64_t;
2423
2453
      break;
2424
2454
    case PLUGIN_VAR_STR:
2425
 
      (((thdvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
 
2455
      (((sessionvar_str_t *)opt)->resolve)= mysql_sys_var_ptr_str;
2426
2456
      break;
2427
2457
    case PLUGIN_VAR_ENUM:
2428
 
      (((thdvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
 
2458
      (((sessionvar_enum_t *)opt)->resolve)= mysql_sys_var_ptr_enum;
2429
2459
      break;
2430
2460
    case PLUGIN_VAR_SET:
2431
 
      (((thdvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
 
2461
      (((sessionvar_set_t *)opt)->resolve)= mysql_sys_var_ptr_set;
2432
2462
      break;
2433
2463
    default:
2434
2464
      sql_print_error(_("Unknown variable type code 0x%x in plugin '%s'."),
2499
2529
      return(-1);
2500
2530
    }
2501
2531
 
2502
 
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_THDLOCAL))
 
2532
    if ((opt->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_SessionLOCAL))
2503
2533
                    == PLUGIN_VAR_NOCMDOPT)
2504
2534
      continue;
2505
2535
 
2510
2540
      return(-1);
2511
2541
    }
2512
2542
 
2513
 
    if (!(opt->flags & PLUGIN_VAR_THDLOCAL))
 
2543
    if (!(opt->flags & PLUGIN_VAR_SessionLOCAL))
2514
2544
    {
2515
2545
      optnamelen= strlen(opt->name);
2516
2546
      optname= (char*) alloc_root(mem_root, namelen + optnamelen + 2);
2548
2578
 
2549
2579
    plugin_opt_set_limits(options, opt);
2550
2580
 
2551
 
    if (opt->flags & PLUGIN_VAR_THDLOCAL)
 
2581
    if (opt->flags & PLUGIN_VAR_SessionLOCAL)
2552
2582
      options->value= options->u_max_value= (char**)
2553
2583
        (global_system_variables.dynamic_variables_ptr + offset);
2554
2584
    else