56
65
#include <drizzled/item/uint.h>
57
66
#include <drizzled/item/null.h>
58
67
#include <drizzled/item/float.h>
59
#include <drizzled/plugin.h>
60
#include "drizzled/version.h"
61
#include "drizzled/strfunc.h"
62
#include "drizzled/internal/m_string.h"
63
#include "drizzled/pthread_globals.h"
64
#include "drizzled/charset.h"
65
#include "drizzled/transaction_services.h"
68
70
#include <algorithm>
70
72
using namespace std;
77
extern bool timed_mutexes;
80
extern plugin::StorageEngine *myisam_engine;
81
extern bool timed_mutexes;
83
extern struct option my_long_options[];
84
74
extern const CHARSET_INFO *character_set_filesystem;
75
extern I_List<NAMED_LIST> key_caches;
85
76
extern size_t my_thread_stack_size;
87
class sys_var_pluginvar;
88
78
static DYNAMIC_ARRAY fixed_show_vars;
89
typedef map<string, sys_var *> SystemVariableMap;
90
static SystemVariableMap system_variable_map;
79
static map<const string, sys_var *> system_variable_hash;
91
80
extern char *opt_drizzle_tmpdir;
93
extern TYPELIB tx_isolation_typelib;
95
82
const char *bool_type_names[]= { "OFF", "ON", NULL };
96
83
TYPELIB bool_typelib=
98
85
array_elements(bool_type_names)-1, "", bool_type_names, NULL
88
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
89
TYPELIB delay_key_write_typelib=
91
array_elements(delay_key_write_type_names)-1, "",
92
delay_key_write_type_names, NULL
101
95
static bool set_option_bit(Session *session, set_var *var);
102
96
static bool set_option_autocommit(Session *session, set_var *var);
103
97
static int check_pseudo_thread_id(Session *session, set_var *var);
104
98
static int check_tx_isolation(Session *session, set_var *var);
105
static void fix_tx_isolation(Session *session, sql_var_t type);
99
static void fix_tx_isolation(Session *session, enum_var_type type);
106
100
static int check_completion_type(Session *session, set_var *var);
107
static void fix_completion_type(Session *session, sql_var_t type);
108
static void fix_max_join_size(Session *session, sql_var_t type);
109
static void fix_session_mem_root(Session *session, sql_var_t type);
110
static void fix_server_id(Session *session, sql_var_t type);
101
static void fix_completion_type(Session *session, enum_var_type type);
102
static void fix_net_read_timeout(Session *session, enum_var_type type);
103
static void fix_net_write_timeout(Session *session, enum_var_type type);
104
static void fix_net_retry_count(Session *session, enum_var_type type);
105
static void fix_max_join_size(Session *session, enum_var_type type);
106
static void fix_session_mem_root(Session *session, enum_var_type type);
107
static void fix_trans_mem_root(Session *session, enum_var_type type);
108
static void fix_server_id(Session *session, enum_var_type type);
109
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
111
110
static bool get_unsigned32(Session *session, set_var *var);
112
111
static bool get_unsigned64(Session *session, set_var *var);
113
112
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
114
const std::string &name, int64_t val);
113
const char *name, int64_t val);
114
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
115
static unsigned char *get_error_count(Session *session);
116
116
static unsigned char *get_warning_count(Session *session);
117
117
static unsigned char *get_tmpdir(Session *session);
125
125
The variables are linked into the list. A variable is added to
126
126
it in the constructor (see sys_var class for details).
128
129
static sys_var_chain vars = { NULL, NULL };
130
131
static sys_var_session_uint64_t
131
132
sys_auto_increment_increment(&vars, "auto_increment_increment",
132
&system_variables::auto_increment_increment);
133
&SV::auto_increment_increment, NULL, NULL,
134
sys_var::SESSION_VARIABLE_IN_BINLOG);
133
135
static sys_var_session_uint64_t
134
136
sys_auto_increment_offset(&vars, "auto_increment_offset",
135
&system_variables::auto_increment_offset);
137
&SV::auto_increment_offset, NULL, NULL,
138
sys_var::SESSION_VARIABLE_IN_BINLOG);
137
140
static sys_var_const_str sys_basedir(&vars, "basedir", drizzle_home);
138
141
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
139
&system_variables::bulk_insert_buff_size);
142
&SV::bulk_insert_buff_size);
140
143
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
141
&system_variables::completion_type,
144
&SV::completion_type,
142
145
check_completion_type,
143
146
fix_completion_type);
144
147
static sys_var_collation_sv
145
sys_collation_server(&vars, "collation_server", &system_variables::collation_server, &default_charset_info);
148
sys_collation_database(&vars, "collation_database", &SV::collation_database,
149
&default_charset_info,
150
sys_var::SESSION_VARIABLE_IN_BINLOG);
151
static sys_var_collation_sv
152
sys_collation_server(&vars, "collation_server", &SV::collation_server,
153
&default_charset_info,
154
sys_var::SESSION_VARIABLE_IN_BINLOG);
155
static sys_var_uint32_t_ptr sys_connect_timeout(&vars, "connect_timeout",
146
157
static sys_var_const_str sys_datadir(&vars, "datadir", drizzle_real_data_home);
158
static sys_var_enum sys_delay_key_write(&vars, "delay_key_write",
159
&delay_key_write_options,
160
&delay_key_write_typelib,
161
fix_delay_key_write);
163
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
148
164
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
149
&system_variables::join_buff_size);
165
&SV::join_buff_size);
166
static sys_var_key_buffer_size sys_key_buffer_size(&vars, "key_buffer_size");
167
static sys_var_key_cache_uint32_t sys_key_cache_block_size(&vars, "key_cache_block_size",
170
static sys_var_key_cache_uint32_t sys_key_cache_division_limit(&vars, "key_cache_division_limit",
172
param_division_limit));
173
static sys_var_key_cache_uint32_t sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
175
param_age_threshold));
150
176
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
151
&system_variables::max_allowed_packet);
177
&SV::max_allowed_packet);
152
178
static sys_var_uint64_t_ptr sys_max_connect_errors(&vars, "max_connect_errors",
153
179
&max_connect_errors);
154
180
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
155
&system_variables::max_error_count);
181
&SV::max_error_count);
156
182
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
157
&system_variables::max_heap_table_size);
183
&SV::max_heap_table_size);
158
184
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
159
&system_variables::pseudo_thread_id,
160
0, check_pseudo_thread_id);
185
&SV::pseudo_thread_id,
186
0, check_pseudo_thread_id,
187
sys_var::SESSION_VARIABLE_IN_BINLOG);
161
188
static sys_var_session_ha_rows sys_max_join_size(&vars, "max_join_size",
162
&system_variables::max_join_size,
163
190
fix_max_join_size);
164
191
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
165
&system_variables::max_seeks_for_key);
192
&SV::max_seeks_for_key);
166
193
static sys_var_session_uint64_t sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
167
&system_variables::max_length_for_sort_data);
194
&SV::max_length_for_sort_data);
168
195
static sys_var_session_size_t sys_max_sort_length(&vars, "max_sort_length",
169
&system_variables::max_sort_length);
196
&SV::max_sort_length);
197
static sys_var_session_uint64_t sys_max_tmp_tables(&vars, "max_tmp_tables",
198
&SV::max_tmp_tables);
170
199
static sys_var_uint64_t_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
171
200
&max_write_lock_count);
172
201
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
173
&system_variables::min_examined_row_limit);
202
&SV::min_examined_row_limit);
204
static sys_var_session_enum sys_myisam_stats_method(&vars, "myisam_stats_method",
205
&SV::myisam_stats_method,
206
&myisam_stats_method_typelib,
208
static sys_var_session_uint32_t sys_net_buffer_length(&vars, "net_buffer_length",
209
&SV::net_buffer_length);
210
static sys_var_session_uint32_t sys_net_read_timeout(&vars, "net_read_timeout",
211
&SV::net_read_timeout,
212
0, fix_net_read_timeout);
213
static sys_var_session_uint32_t sys_net_write_timeout(&vars, "net_write_timeout",
214
&SV::net_write_timeout,
215
0, fix_net_write_timeout);
216
static sys_var_session_uint32_t sys_net_retry_count(&vars, "net_retry_count",
217
&SV::net_retry_count,
218
0, fix_net_retry_count);
175
219
/* these two cannot be static */
220
sys_var_session_bool sys_old_alter_table(&vars, "old_alter_table",
221
&SV::old_alter_table);
176
222
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
177
&system_variables::optimizer_prune_level);
223
&SV::optimizer_prune_level);
178
224
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
179
&system_variables::optimizer_search_depth);
225
&SV::optimizer_search_depth);
227
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
228
TYPELIB optimizer_use_mrr_typelib= {
229
array_elements(optimizer_use_mrr_names) - 1, "",
230
optimizer_use_mrr_names, NULL
233
static sys_var_session_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
234
&SV::optimizer_use_mrr,
235
&optimizer_use_mrr_typelib,
181
238
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
182
&system_variables::preload_buff_size);
239
&SV::preload_buff_size);
183
240
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
184
&system_variables::read_buff_size);
241
&SV::read_buff_size);
185
242
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
186
&system_variables::read_rnd_buff_size);
243
&SV::read_rnd_buff_size);
187
244
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
188
&system_variables::div_precincrement);
245
&SV::div_precincrement);
190
247
static sys_var_session_size_t sys_range_alloc_block_size(&vars, "range_alloc_block_size",
191
&system_variables::range_alloc_block_size);
248
&SV::range_alloc_block_size);
192
249
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
193
&system_variables::query_alloc_block_size,
250
&SV::query_alloc_block_size,
194
251
false, fix_session_mem_root);
195
252
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
196
&system_variables::query_prealloc_size,
253
&SV::query_prealloc_size,
197
254
false, fix_session_mem_root);
198
255
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
256
static sys_var_session_uint32_t sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
257
&SV::trans_alloc_block_size,
258
false, fix_trans_mem_root);
259
static sys_var_session_uint32_t sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
260
&SV::trans_prealloc_size,
261
false, fix_trans_mem_root);
200
263
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
201
264
&opt_secure_file_priv);
205
268
static sys_var_session_size_t sys_sort_buffer(&vars, "sort_buffer_size",
206
&system_variables::sortbuff_size);
271
sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
272
even though it is written to the binlog, the slave ignores the
273
MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
274
master's (see log_event.cc: Query_log_event::do_apply_event()).
276
static sys_var_session_optimizer_switch sys_optimizer_switch(&vars, "optimizer_switch",
277
&SV::optimizer_switch);
208
279
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
209
&system_variables::storage_engine);
280
&SV::storage_engine);
210
281
static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone",
211
282
system_time_zone);
212
static sys_var_size_t_ptr sys_table_def_size(&vars, "table_definition_cache",
283
static sys_var_uint64_t_ptr sys_table_def_size(&vars, "table_definition_cache",
214
285
static sys_var_uint64_t_ptr sys_table_cache_size(&vars, "table_open_cache",
215
286
&table_cache_size);
216
287
static sys_var_uint64_t_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
217
288
&table_lock_wait_timeout);
218
289
static sys_var_session_enum sys_tx_isolation(&vars, "tx_isolation",
219
&system_variables::tx_isolation,
220
291
&tx_isolation_typelib,
221
292
fix_tx_isolation,
222
293
check_tx_isolation);
223
294
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
224
&system_variables::tmp_table_size);
225
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &internal::timed_mutexes);
226
static sys_var_const_str sys_version(&vars, "version", version().c_str());
295
&SV::tmp_table_size);
296
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
297
static sys_var_const_str sys_version(&vars, "version", server_version);
228
298
static sys_var_const_str sys_version_comment(&vars, "version_comment",
229
299
COMPILATION_COMMENT);
230
300
static sys_var_const_str sys_version_compile_machine(&vars, "version_compile_machine",
232
302
static sys_var_const_str sys_version_compile_os(&vars, "version_compile_os",
234
static sys_var_const_str sys_version_compile_vendor(&vars, "version_compile_vendor",
304
static sys_var_session_uint32_t sys_net_wait_timeout(&vars, "wait_timeout",
305
&SV::net_wait_timeout);
307
/* Condition pushdown to storage engine */
308
static sys_var_session_bool
309
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
310
&SV::engine_condition_pushdown);
237
312
/* Variables that are bits in Session */
249
324
static sys_var_session_bit sys_sql_notes(&vars, "sql_notes", 0,
251
326
OPTION_SQL_NOTES);
327
static sys_var_session_bit sys_safe_updates(&vars, "sql_safe_updates", 0,
329
OPTION_SAFE_UPDATES);
252
330
static sys_var_session_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
254
332
OPTION_BUFFER_RESULT);
255
333
static sys_var_session_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
257
OPTION_NO_FOREIGN_KEY_CHECKS, 1);
335
OPTION_NO_FOREIGN_KEY_CHECKS,
336
1, sys_var::SESSION_VARIABLE_IN_BINLOG);
258
337
static sys_var_session_bit sys_unique_checks(&vars, "unique_checks", 0,
260
OPTION_RELAXED_UNIQUE_CHECKS, 1);
339
OPTION_RELAXED_UNIQUE_CHECKS,
341
sys_var::SESSION_VARIABLE_IN_BINLOG);
261
342
/* Local state variables */
263
344
static sys_var_session_ha_rows sys_select_limit(&vars, "sql_select_limit",
264
&system_variables::select_limit);
265
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
346
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
347
sys_var::SESSION_VARIABLE_IN_BINLOG);
266
348
static sys_var_last_insert_id
267
sys_last_insert_id(&vars, "last_insert_id");
349
sys_last_insert_id(&vars, "last_insert_id",
350
sys_var::SESSION_VARIABLE_IN_BINLOG);
269
352
identity is an alias for last_insert_id(), so that we are compatible
272
static sys_var_last_insert_id sys_identity(&vars, "identity");
355
static sys_var_last_insert_id
356
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
274
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
358
static sys_var_session_lc_time_names
359
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
362
insert_id should *not* be marked as written to the binlog (i.e., it
363
should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
364
because we want any statement that refers to insert_id explicitly to
365
be unsafe. (By "explicitly", we mean using @@session.insert_id,
366
whereas insert_id is used "implicitly" when NULL value is inserted
367
into an auto_increment column).
277
369
We want statements referring explicitly to @@session.insert_id to be
278
370
unsafe, because insert_id is modified internally by the slave sql
279
371
thread when NULL values are inserted in an AUTO_INCREMENT column.
309
407
TODO: remove this list completely
312
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(drizzle_show_var))
313
static drizzle_show_var fixed_vars[]= {
314
{"back_log", (char*) &back_log, SHOW_INT},
315
{"language", language, SHOW_CHAR},
316
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
317
{"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR},
318
{"thread_stack", (char*) &my_thread_stack_size, SHOW_INT},
410
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
411
static SHOW_VAR fixed_vars[]= {
412
{"back_log", (char*) &back_log, SHOW_INT},
413
{"language", language, SHOW_CHAR},
415
{"locked_in_memory", (char*) &locked_in_memory, SHOW_MY_BOOL},
417
{"myisam_recover_options", (char*) &myisam_recover_options_str, SHOW_CHAR_PTR},
418
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
419
{"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR},
420
{"port", (char*) &drizzled_port, SHOW_INT},
421
{"protocol_version", (char*) &protocol_version, SHOW_INT},
422
{"thread_stack", (char*) &my_thread_stack_size, SHOW_INT},
321
425
bool sys_var::check(Session *, set_var *var)
1116
1352
return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1356
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1358
static KEY_CACHE zero_key_cache;
1360
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
1362
safe_mutex_assert_owner(&LOCK_global_system_variables);
1363
if (!cache_name || ! cache_name->length)
1364
cache_name= &default_key_cache_base;
1365
return ((KEY_CACHE*) find_named(&key_caches,
1366
cache_name->str, cache_name->length, 0));
1370
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
1371
const LEX_STRING *base)
1373
KEY_CACHE *key_cache= get_key_cache(base);
1375
key_cache= &zero_key_cache;
1376
return (unsigned char*) key_cache + offset ;
1380
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1382
uint64_t tmp= var->save_result.uint64_t_value;
1383
LEX_STRING *base_name= &var->base;
1384
KEY_CACHE *key_cache;
1387
/* If no basename, assume it's for the key cache named 'default' */
1388
if (!base_name->length)
1389
base_name= &default_key_cache_base;
1391
pthread_mutex_lock(&LOCK_global_system_variables);
1392
key_cache= get_key_cache(base_name);
1396
/* Key cache didn't exists */
1397
if (!tmp) // Tried to delete cache
1398
goto end; // Ok, nothing to do
1399
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
1407
Abort if some other thread is changing the key cache
1408
TODO: This should be changed so that we wait until the previous
1409
assignment is done and then do the new assign
1411
if (key_cache->in_init)
1414
if (!tmp) // Zero size means delete
1416
if (key_cache == dflt_key_cache)
1418
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1419
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1420
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1421
goto end; // Ignore default key cache
1424
if (key_cache->key_cache_inited) // If initied
1427
Move tables using this key cache to the default key cache
1428
and clear the old key cache.
1431
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
1432
base_name->length, &list);
1433
key_cache->in_init= 1;
1434
pthread_mutex_unlock(&LOCK_global_system_variables);
1435
error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1436
pthread_mutex_lock(&LOCK_global_system_variables);
1437
key_cache->in_init= 0;
1440
We don't delete the key cache as some running threads my still be
1441
in the key cache code with a pointer to the deleted (empty) key cache
1446
key_cache->param_buff_size=
1447
(uint64_t) fix_unsigned(session, tmp, option_limits);
1449
/* If key cache didn't existed initialize it, else resize it */
1450
key_cache->in_init= 1;
1451
pthread_mutex_unlock(&LOCK_global_system_variables);
1453
if (!key_cache->key_cache_inited)
1454
error= (bool) (ha_init_key_cache("", key_cache));
1456
error= (bool)(ha_resize_key_cache(key_cache));
1458
pthread_mutex_lock(&LOCK_global_system_variables);
1459
key_cache->in_init= 0;
1462
pthread_mutex_unlock(&LOCK_global_system_variables);
1469
Abort if some other thread is changing the key cache.
1470
This should be changed so that we wait until the previous
1471
assignment is done and then do the new assign
1473
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
1475
uint64_t tmp= (uint64_t) var->value->val_int();
1476
LEX_STRING *base_name= &var->base;
1479
if (!base_name->length)
1480
base_name= &default_key_cache_base;
1482
pthread_mutex_lock(&LOCK_global_system_variables);
1483
KEY_CACHE *key_cache= get_key_cache(base_name);
1485
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
1486
base_name->length)))
1493
Abort if some other thread is changing the key cache
1494
TODO: This should be changed so that we wait until the previous
1495
assignment is done and then do the new assign
1497
if (key_cache->in_init)
1500
*((uint32_t*) (((char*) key_cache) + offset))=
1501
(uint32_t) fix_unsigned(session, tmp, option_limits);
1504
Don't create a new key cache if it didn't exist
1505
(key_caches are created only when the user sets block_size)
1507
key_cache->in_init= 1;
1509
pthread_mutex_unlock(&LOCK_global_system_variables);
1511
error= (bool) (ha_resize_key_cache(key_cache));
1513
pthread_mutex_lock(&LOCK_global_system_variables);
1514
key_cache->in_init= 0;
1517
pthread_mutex_unlock(&LOCK_global_system_variables);
1119
1522
/****************************************************************************/
1121
1524
bool sys_var_timestamp::update(Session *session, set_var *var)
1491
int mysql_add_sys_var_chain(sys_var *first, struct option *long_options)
1907
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
1494
1910
/* A write lock should be held on LOCK_system_variables_hash */
1496
for (var= first; var; var= var->getNext())
1912
for (var= first; var; var= var->next)
1499
string lower_name(var->getName());
1500
transform(lower_name.begin(), lower_name.end(),
1501
lower_name.begin(), ::tolower);
1914
/* Make a temp string to hold this and then make it lower so that matching
1915
* happens case-insensitive.
1917
string var_name(var->name);
1918
transform(var_name.begin(), var_name.end(), var_name.begin(), ::tolower);
1919
var->name_length= var_name.length();
1503
1921
/* this fails if there is a conflicting variable name. */
1504
if (system_variable_map.find(lower_name) != system_variable_map.end())
1922
if (system_variable_hash.count(var_name) == 0)
1506
errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1507
var->getName().c_str());
1924
system_variable_hash[var_name]= var;
1511
pair<SystemVariableMap::iterator, bool> ret=
1512
system_variable_map.insert(make_pair(lower_name, var));
1513
if (ret.second == false)
1515
errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
1516
var->getName().c_str());
1928
for (; first != var; first= first->next)
1931
* This is slightly expensive, since we have to do the transform
1932
* _again_ but should rarely happen unless there is a pretty
1933
* major problem in the code
1935
var_name= first->name;
1936
transform(var_name.begin(), var_name.end(),
1937
var_name.begin(), ::tolower);
1938
system_variable_hash.erase(var_name);
1520
1942
if (long_options)
1521
var->setOptionLimits(find_option(long_options, var->getName().c_str()));
1943
var->option_limits= find_option(long_options, var->name);
1562
1987
sorted If TRUE, the system variables should be sorted
1565
pointer Array of drizzle_show_var elements for display
1990
pointer Array of SHOW_VAR elements for display
1569
drizzle_show_var* enumerate_sys_vars(Session *session, bool)
1994
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
1571
1996
int fixed_count= fixed_show_vars.elements;
1572
int size= sizeof(drizzle_show_var) * (system_variable_map.size() + fixed_count + 1);
1573
drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
1997
int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
1998
SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
1577
drizzle_show_var *show= result + fixed_count;
1578
memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(drizzle_show_var));
2002
SHOW_VAR *show= result + fixed_count;
2003
memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
1580
SystemVariableMap::const_iterator iter= system_variable_map.begin();
1581
while (iter != system_variable_map.end())
2005
map<string, sys_var *>::iterator iter;
2006
for(iter= system_variable_hash.begin();
2007
iter != system_variable_hash.end();
1583
2010
sys_var *var= (*iter).second;
1584
show->name= var->getName().c_str();
2011
show->name= var->name;
1585
2012
show->value= (char*) var;
1586
2013
show->type= SHOW_SYS;
1591
2017
/* make last element empty */
1592
memset(show, 0, sizeof(drizzle_show_var));
2018
memset(show, 0, sizeof(SHOW_VAR));
2024
NAMED_LIST::NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
2025
uint32_t name_length_arg, unsigned char* data_arg)
2028
name.assign(name_arg, name_length_arg);
2029
links->push_back(this);
2033
bool NAMED_LIST::cmp(const char *name_cmp, uint32_t length)
2035
return length == name.length() && !name.compare(name_cmp);
1599
2040
Initialize the system variables
1912
} /* namespace drizzled */
2362
sys_var_session_optimizer_switch::
2363
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
2365
char buff[STRING_BUFFER_USUAL_SIZE*8];
2366
String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
2370
for (uint32_t i= 0; val; val>>= 1, i++)
2374
tmp.append(optimizer_switch_typelib.type_names[i],
2375
optimizer_switch_typelib.type_lengths[i]);
2381
tmp.length(tmp.length() - 1); /* trim the trailing comma */
2383
rep->str= session->strmake(tmp.ptr(), tmp.length());
2385
rep->length= rep->str ? tmp.length() : 0;
2387
return rep->length != tmp.length();
2391
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
2396
uint32_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
2397
session->variables.*offset);
2398
(void) symbolic_mode_representation(session, val, &opts);
2399
return (unsigned char *) opts.str;
2403
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
2405
if (type == OPT_GLOBAL)
2406
global_system_variables.*offset= 0;
2408
session->variables.*offset= global_system_variables.*offset;
2412
/****************************************************************************
2414
****************************************************************************/
2416
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
2419
I_List_iterator<NAMED_LIST> it(*list);
2420
NAMED_LIST *element;
2421
while ((element= it++))
2423
if (element->cmp(name, length))
2427
return element->data;
2434
void delete_elements(I_List<NAMED_LIST> *list,
2435
void (*free_element)(const char *name, unsigned char*))
2437
NAMED_LIST *element;
2438
while ((element= list->get()))
2440
(*free_element)(element->name.c_str(), element->data);
2447
/* Key cache functions */
2449
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
2451
KEY_CACHE *key_cache;
2453
if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
2455
memset(key_cache, 0, sizeof(KEY_CACHE));
2456
if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
2458
free((char*) key_cache);
2464
Set default values for a key cache
2465
The values in dflt_key_cache_var is set by my_getopt() at startup
2467
We don't set 'buff_size' as this is used to enable the key cache
2469
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
2470
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
2471
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
2478
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
2480
LEX_STRING key_cache_name;
2481
KEY_CACHE *key_cache;
2483
key_cache_name.str= (char *) name;
2484
key_cache_name.length= length;
2485
pthread_mutex_lock(&LOCK_global_system_variables);
2486
if (!(key_cache= get_key_cache(&key_cache_name)))
2487
key_cache= create_key_cache(name, length);
2488
pthread_mutex_unlock(&LOCK_global_system_variables);
2493
void free_key_cache(const char *, KEY_CACHE *key_cache)
2495
ha_end_key_cache(key_cache);
2496
free((char*) key_cache);
2500
bool process_key_caches(process_key_cache_t func)
2502
I_List_iterator<NAMED_LIST> it(key_caches);
2503
NAMED_LIST *element;
2505
while ((element= it++))
2507
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
2508
func(element->name.c_str(), key_cache);
2513
/****************************************************************************
2515
****************************************************************************/
2517
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
2518
template class List<set_var_base>;
2519
template class List_iterator_fast<set_var_base>;
2520
template class I_List_iterator<NAMED_LIST>;