36
37
Add full support for the variable character_set (for 4.1)
39
When updating myisam_delay_key_write, we should do a 'flush tables'
40
of all MyISAM tables to ensure that they are reopen with the
44
40
Be careful with var->save_result: sys_var::check() only updates
45
41
uint64_t_value; so other members of the union are garbage then; to use
46
42
them you must first assign a value to them (in specific ::check() for
49
#include <drizzled/server_includes.h>
51
#include <mysys/my_getopt.h>
52
#include <mysys/thr_alarm.h>
53
#include <storage/myisam/myisam.h>
54
#include <drizzled/drizzled_error_messages.h>
47
#include "drizzled/my_getopt.h"
48
#include <drizzled/error.h>
49
#include <drizzled/gettext.h>
50
#include <drizzled/tztime.h>
51
#include <drizzled/data_home.h>
52
#include <drizzled/set_var.h>
53
#include <drizzled/session.h>
54
#include <drizzled/sql_base.h>
55
#include <drizzled/lock.h>
56
#include <drizzled/item/uint.h>
57
#include <drizzled/item/null.h>
58
#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"
77
extern bool timed_mutexes;
80
extern plugin::StorageEngine *myisam_engine;
81
extern bool timed_mutexes;
83
extern struct my_option my_long_options[];
56
84
extern const CHARSET_INFO *character_set_filesystem;
85
extern size_t my_thread_stack_size;
87
class sys_var_pluginvar;
59
88
static DYNAMIC_ARRAY fixed_show_vars;
60
static HASH system_variable_hash;
62
const char *bool_type_names[]= { "OFF", "ON", NullS };
89
typedef map<string, sys_var *> SystemVariableMap;
90
static SystemVariableMap system_variable_map;
91
extern char *opt_drizzle_tmpdir;
93
extern TYPELIB tx_isolation_typelib;
95
const char *bool_type_names[]= { "OFF", "ON", NULL };
63
96
TYPELIB bool_typelib=
65
98
array_elements(bool_type_names)-1, "", bool_type_names, NULL
68
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
69
TYPELIB delay_key_write_typelib=
71
array_elements(delay_key_write_type_names)-1, "",
72
delay_key_write_type_names, NULL
75
const char *slave_exec_mode_names[]=
76
{ "STRICT", "IDEMPOTENT", NullS };
77
static const unsigned int slave_exec_mode_names_len[]=
78
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
79
TYPELIB slave_exec_mode_typelib=
81
array_elements(slave_exec_mode_names)-1, "",
82
slave_exec_mode_names, (unsigned int *) slave_exec_mode_names_len
85
static bool sys_update_init_connect(THD*, set_var*);
86
static void sys_default_init_connect(THD*, enum_var_type type);
87
static bool sys_update_init_slave(THD*, set_var*);
88
static void sys_default_init_slave(THD*, enum_var_type type);
89
static bool set_option_bit(THD *thd, set_var *var);
90
static bool set_option_autocommit(THD *thd, set_var *var);
91
static int check_log_update(THD *thd, set_var *var);
92
static bool set_log_update(THD *thd, set_var *var);
93
static int check_pseudo_thread_id(THD *thd, set_var *var);
94
static void fix_low_priority_updates(THD *thd, enum_var_type type);
95
static int check_tx_isolation(THD *thd, set_var *var);
96
static void fix_tx_isolation(THD *thd, enum_var_type type);
97
static int check_completion_type(THD *thd, set_var *var);
98
static void fix_completion_type(THD *thd, enum_var_type type);
99
static void fix_net_read_timeout(THD *thd, enum_var_type type);
100
static void fix_net_write_timeout(THD *thd, enum_var_type type);
101
static void fix_net_retry_count(THD *thd, enum_var_type type);
102
static void fix_max_join_size(THD *thd, enum_var_type type);
103
static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type);
104
static void fix_max_binlog_size(THD *thd, enum_var_type type);
105
static void fix_max_relay_log_size(THD *thd, enum_var_type type);
106
static void fix_max_connections(THD *thd, enum_var_type type);
107
static void fix_thd_mem_root(THD *thd, enum_var_type type);
108
static void fix_trans_mem_root(THD *thd, enum_var_type type);
109
static void fix_server_id(THD *thd, enum_var_type type);
110
static uint64_t fix_unsigned(THD *, uint64_t, const struct my_option *);
111
static bool get_unsigned(THD *thd, set_var *var);
112
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
113
const char *name, int64_t val);
114
static KEY_CACHE *create_key_cache(const char *name, uint length);
115
static uchar *get_error_count(THD *thd);
116
static uchar *get_warning_count(THD *thd);
117
static uchar *get_tmpdir(THD *thd);
118
static int sys_check_log_path(THD *thd, set_var *var);
119
static bool sys_update_general_log_path(THD *thd, set_var * var);
120
static void sys_default_general_log_path(THD *thd, enum_var_type type);
121
static bool sys_update_slow_log_path(THD *thd, set_var * var);
122
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
101
static bool set_option_bit(Session *session, set_var *var);
102
static bool set_option_autocommit(Session *session, set_var *var);
103
static int check_pseudo_thread_id(Session *session, set_var *var);
104
static int check_tx_isolation(Session *session, set_var *var);
105
static void fix_tx_isolation(Session *session, enum_var_type type);
106
static int check_completion_type(Session *session, set_var *var);
107
static void fix_completion_type(Session *session, enum_var_type type);
108
static void fix_max_join_size(Session *session, enum_var_type type);
109
static void fix_session_mem_root(Session *session, enum_var_type type);
110
static void fix_server_id(Session *session, enum_var_type type);
111
static bool get_unsigned32(Session *session, set_var *var);
112
static bool get_unsigned64(Session *session, set_var *var);
113
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
114
const std::string &name, int64_t val);
115
static unsigned char *get_error_count(Session *session);
116
static unsigned char *get_warning_count(Session *session);
117
static unsigned char *get_tmpdir(Session *session);
125
120
Variable definition list
130
125
The variables are linked into the list. A variable is added to
131
126
it in the constructor (see sys_var class for details).
134
128
static sys_var_chain vars = { NULL, NULL };
136
static sys_var_thd_ulong
130
static sys_var_session_uint64_t
137
131
sys_auto_increment_increment(&vars, "auto_increment_increment",
138
&SV::auto_increment_increment, NULL, NULL,
139
sys_var::SESSION_VARIABLE_IN_BINLOG);
140
static sys_var_thd_ulong
132
&SV::auto_increment_increment);
133
static sys_var_session_uint64_t
141
134
sys_auto_increment_offset(&vars, "auto_increment_offset",
142
&SV::auto_increment_offset, NULL, NULL,
143
sys_var::SESSION_VARIABLE_IN_BINLOG);
145
static sys_var_const_str sys_basedir(&vars, "basedir", mysql_home);
146
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
148
static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
150
static sys_var_thd_ulong sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
151
&SV::bulk_insert_buff_size);
152
static sys_var_character_set_sv
153
sys_character_set_server(&vars, "character_set_server",
154
&SV::collation_server, &default_charset_info, 0,
155
sys_var::SESSION_VARIABLE_IN_BINLOG);
156
sys_var_const_str sys_charset_system(&vars, "character_set_system",
157
(char *)my_charset_utf8_general_ci.name);
158
static sys_var_character_set_database
159
sys_character_set_database(&vars, "character_set_database",
160
sys_var::SESSION_VARIABLE_IN_BINLOG);
161
static sys_var_character_set_client
162
sys_character_set_client(&vars, "character_set_client",
163
&SV::character_set_client,
164
&default_charset_info,
165
sys_var::SESSION_VARIABLE_IN_BINLOG);
166
static sys_var_character_set_sv
167
sys_character_set_connection(&vars, "character_set_connection",
168
&SV::collation_connection,
169
&default_charset_info, 0,
170
sys_var::SESSION_VARIABLE_IN_BINLOG);
171
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
172
&SV::character_set_results,
173
&default_charset_info, true);
174
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
175
&SV::character_set_filesystem,
176
&character_set_filesystem);
177
static sys_var_thd_ulong sys_completion_type(&vars, "completion_type",
178
&SV::completion_type,
179
check_completion_type,
180
fix_completion_type);
181
static sys_var_collation_sv
182
sys_collation_connection(&vars, "collation_connection",
183
&SV::collation_connection, &default_charset_info,
184
sys_var::SESSION_VARIABLE_IN_BINLOG);
185
static sys_var_collation_sv
186
sys_collation_database(&vars, "collation_database", &SV::collation_database,
187
&default_charset_info,
188
sys_var::SESSION_VARIABLE_IN_BINLOG);
189
static sys_var_collation_sv
190
sys_collation_server(&vars, "collation_server", &SV::collation_server,
191
&default_charset_info,
192
sys_var::SESSION_VARIABLE_IN_BINLOG);
193
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
195
static sys_var_const_str sys_datadir(&vars, "datadir", mysql_real_data_home);
196
static sys_var_enum sys_delay_key_write(&vars, "delay_key_write",
197
&delay_key_write_options,
198
&delay_key_write_typelib,
199
fix_delay_key_write);
201
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
203
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
204
sys_var_str sys_init_connect(&vars, "init_connect", 0,
205
sys_update_init_connect,
206
sys_default_init_connect,0);
207
sys_var_str sys_init_slave(&vars, "init_slave", 0,
208
sys_update_init_slave,
209
sys_default_init_slave,0);
210
static sys_var_thd_ulong sys_interactive_timeout(&vars, "interactive_timeout",
211
&SV::net_interactive_timeout);
212
static sys_var_thd_ulong sys_join_buffer_size(&vars, "join_buffer_size",
213
&SV::join_buff_size);
214
static sys_var_key_buffer_size sys_key_buffer_size(&vars, "key_buffer_size");
215
static sys_var_key_cache_long sys_key_cache_block_size(&vars, "key_cache_block_size",
218
static sys_var_key_cache_long sys_key_cache_division_limit(&vars, "key_cache_division_limit",
220
param_division_limit));
221
static sys_var_key_cache_long sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
223
param_age_threshold));
224
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
226
static sys_var_bool_ptr
227
sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
228
&opt_log_queries_not_using_indexes);
229
static sys_var_thd_ulong sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
230
static sys_var_microseconds sys_var_long_query_time(&vars, "long_query_time",
231
&SV::long_query_time);
232
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
233
&SV::low_priority_updates,
234
fix_low_priority_updates);
235
#ifndef TO_BE_DELETED /* Alias for the low_priority_updates */
236
static sys_var_thd_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
237
&SV::low_priority_updates,
238
fix_low_priority_updates);
240
static sys_var_thd_ulong sys_max_allowed_packet(&vars, "max_allowed_packet",
241
&SV::max_allowed_packet);
242
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
243
&max_binlog_cache_size);
244
static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
246
fix_max_binlog_size);
247
static sys_var_long_ptr sys_max_connections(&vars, "max_connections",
249
fix_max_connections);
250
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
251
&max_connect_errors);
252
static sys_var_thd_ulong sys_max_error_count(&vars, "max_error_count",
253
&SV::max_error_count);
254
static sys_var_thd_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
255
&SV::max_heap_table_size);
256
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
135
&SV::auto_increment_offset);
137
static sys_var_const_str sys_basedir(&vars, "basedir", drizzle_home);
138
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
139
&SV::bulk_insert_buff_size);
140
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
141
&SV::completion_type,
142
check_completion_type,
143
fix_completion_type);
144
static sys_var_collation_sv
145
sys_collation_server(&vars, "collation_server", &SV::collation_server, &default_charset_info);
146
static sys_var_const_str sys_datadir(&vars, "datadir", drizzle_real_data_home);
148
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
149
&SV::join_buff_size);
150
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
151
&SV::max_allowed_packet);
152
static sys_var_uint64_t_ptr sys_max_connect_errors(&vars, "max_connect_errors",
153
&max_connect_errors);
154
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
155
&SV::max_error_count);
156
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
157
&SV::max_heap_table_size);
158
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
257
159
&SV::pseudo_thread_id,
258
check_pseudo_thread_id, 0,
259
sys_var::SESSION_VARIABLE_IN_BINLOG);
260
static sys_var_thd_ha_rows sys_max_join_size(&vars, "max_join_size",
263
static sys_var_thd_ulong sys_max_seeks_for_key(&vars, "max_seeks_for_key",
264
&SV::max_seeks_for_key);
265
static sys_var_thd_ulong sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
266
&SV::max_length_for_sort_data);
267
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
269
fix_max_relay_log_size);
270
static sys_var_thd_ulong sys_max_sort_length(&vars, "max_sort_length",
271
&SV::max_sort_length);
272
static sys_var_max_user_conn sys_max_user_connections(&vars, "max_user_connections");
273
static sys_var_thd_ulong sys_max_tmp_tables(&vars, "max_tmp_tables",
274
&SV::max_tmp_tables);
275
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
276
&max_write_lock_count);
277
static sys_var_thd_ulong sys_min_examined_row_limit(&vars, "min_examined_row_limit",
278
&SV::min_examined_row_limit);
279
static sys_var_thd_uint64_t sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
280
static sys_var_thd_ulong sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
281
static sys_var_thd_ulong sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
160
0, check_pseudo_thread_id);
161
static sys_var_session_ha_rows sys_max_join_size(&vars, "max_join_size",
164
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
165
&SV::max_seeks_for_key);
166
static sys_var_session_uint64_t sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
167
&SV::max_length_for_sort_data);
168
static sys_var_session_size_t sys_max_sort_length(&vars, "max_sort_length",
169
&SV::max_sort_length);
170
static sys_var_uint64_t_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
171
&max_write_lock_count);
172
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
173
&SV::min_examined_row_limit);
283
static sys_var_thd_enum sys_myisam_stats_method(&vars, "myisam_stats_method",
284
&SV::myisam_stats_method,
285
&myisam_stats_method_typelib,
287
static sys_var_thd_ulong sys_net_buffer_length(&vars, "net_buffer_length",
288
&SV::net_buffer_length);
289
static sys_var_thd_ulong sys_net_read_timeout(&vars, "net_read_timeout",
290
&SV::net_read_timeout,
291
0, fix_net_read_timeout);
292
static sys_var_thd_ulong sys_net_write_timeout(&vars, "net_write_timeout",
293
&SV::net_write_timeout,
294
0, fix_net_write_timeout);
295
static sys_var_thd_ulong sys_net_retry_count(&vars, "net_retry_count",
296
&SV::net_retry_count,
297
0, fix_net_retry_count);
298
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
299
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
300
&global_system_variables.old_mode);
301
175
/* these two cannot be static */
302
sys_var_thd_bool sys_old_alter_table(&vars, "old_alter_table",
303
&SV::old_alter_table);
304
static sys_var_thd_ulong sys_optimizer_prune_level(&vars, "optimizer_prune_level",
305
&SV::optimizer_prune_level);
306
static sys_var_thd_ulong sys_optimizer_search_depth(&vars, "optimizer_search_depth",
307
&SV::optimizer_search_depth);
309
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
310
TYPELIB optimizer_use_mrr_typelib= {
311
array_elements(optimizer_use_mrr_names) - 1, "",
312
optimizer_use_mrr_names, NULL
315
static sys_var_thd_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
316
&SV::optimizer_use_mrr,
317
&optimizer_use_mrr_typelib,
320
static sys_var_thd_ulong sys_preload_buff_size(&vars, "preload_buffer_size",
321
&SV::preload_buff_size);
322
static sys_var_thd_ulong sys_read_buff_size(&vars, "read_buffer_size",
323
&SV::read_buff_size);
324
static sys_var_opt_readonly sys_readonly(&vars, "read_only", &opt_readonly);
325
static sys_var_thd_ulong sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
326
&SV::read_rnd_buff_size);
327
static sys_var_thd_ulong sys_div_precincrement(&vars, "div_precision_increment",
328
&SV::div_precincrement);
329
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
332
static sys_var_thd_ulong sys_range_alloc_block_size(&vars, "range_alloc_block_size",
333
&SV::range_alloc_block_size);
334
static sys_var_thd_ulong sys_query_alloc_block_size(&vars, "query_alloc_block_size",
335
&SV::query_alloc_block_size,
336
0, fix_thd_mem_root);
337
static sys_var_thd_ulong sys_query_prealloc_size(&vars, "query_prealloc_size",
338
&SV::query_prealloc_size,
339
0, fix_thd_mem_root);
340
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
341
static sys_var_thd_ulong sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
342
&SV::trans_alloc_block_size,
343
0, fix_trans_mem_root);
344
static sys_var_thd_ulong sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
345
&SV::trans_prealloc_size,
346
0, fix_trans_mem_root);
348
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
176
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
177
&SV::optimizer_prune_level);
178
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
179
&SV::optimizer_search_depth);
181
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
182
&SV::preload_buff_size);
183
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
184
&SV::read_buff_size);
185
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
186
&SV::read_rnd_buff_size);
187
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
188
&SV::div_precincrement);
190
static sys_var_session_size_t sys_range_alloc_block_size(&vars, "range_alloc_block_size",
191
&SV::range_alloc_block_size);
192
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
193
&SV::query_alloc_block_size,
194
false, fix_session_mem_root);
195
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
196
&SV::query_prealloc_size,
197
false, fix_session_mem_root);
198
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
349
200
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
350
201
&opt_secure_file_priv);
351
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
352
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
353
&opt_slave_compressed_protocol);
354
#ifdef HAVE_REPLICATION
355
static sys_var_bool_ptr sys_slave_allow_batching(&vars, "slave_allow_batching",
356
&slave_allow_batching);
357
static sys_var_set_slave_mode slave_exec_mode(&vars,
359
&slave_exec_mode_options,
360
&slave_exec_mode_typelib,
363
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
365
static sys_var_thd_ulong sys_sort_buffer(&vars, "sort_buffer_size",
368
sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
369
even though it is written to the binlog, the slave ignores the
370
MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
371
master's (see log_event.cc: Query_log_event::do_apply_event()).
373
static sys_var_thd_optimizer_switch sys_optimizer_switch(&vars, "optimizer_switch",
374
&SV::optimizer_switch);
375
static sys_var_const_str sys_ssl_ca(&vars, "ssl_ca", NULL);
376
static sys_var_const_str sys_ssl_capath(&vars, "ssl_capath", NULL);
377
static sys_var_const_str sys_ssl_cert(&vars, "ssl_cert", NULL);
378
static sys_var_const_str sys_ssl_cipher(&vars, "ssl_cipher", NULL);
379
static sys_var_const_str sys_ssl_key(&vars, "ssl_key", NULL);
381
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
383
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
202
static sys_var_uint32_t_ptr sys_server_id(&vars, "server_id", &server_id,
205
static sys_var_session_size_t sys_sort_buffer(&vars, "sort_buffer_size",
208
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
209
&SV::storage_engine);
384
210
static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone",
385
211
system_time_zone);
386
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
388
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
212
static sys_var_size_t_ptr sys_table_def_size(&vars, "table_definition_cache",
214
static sys_var_uint64_t_ptr sys_table_cache_size(&vars, "table_open_cache",
389
215
&table_cache_size);
390
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
216
static sys_var_uint64_t_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
391
217
&table_lock_wait_timeout);
392
static sys_var_long_ptr sys_thread_cache_size(&vars, "thread_cache_size",
394
sys_var_long_ptr sys_thread_pool_size(&vars, "thread_pool_size",
396
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
398
&tx_isolation_typelib,
401
static sys_var_thd_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
218
static sys_var_session_enum sys_tx_isolation(&vars, "tx_isolation",
220
&tx_isolation_typelib,
223
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
402
224
&SV::tmp_table_size);
403
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
404
static sys_var_const_str sys_version(&vars, "version", server_version);
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());
405
228
static sys_var_const_str sys_version_comment(&vars, "version_comment",
406
DRIZZLE_COMPILATION_COMMENT);
229
COMPILATION_COMMENT);
407
230
static sys_var_const_str sys_version_compile_machine(&vars, "version_compile_machine",
409
232
static sys_var_const_str sys_version_compile_os(&vars, "version_compile_os",
411
static sys_var_thd_ulong sys_net_wait_timeout(&vars, "wait_timeout",
412
&SV::net_wait_timeout);
414
/* Condition pushdown to storage engine */
415
static sys_var_thd_bool
416
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
417
&SV::engine_condition_pushdown);
419
/* Time/date/datetime formats */
421
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
423
DRIZZLE_TIMESTAMP_TIME);
424
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
426
DRIZZLE_TIMESTAMP_DATE);
427
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
428
&SV::datetime_format,
429
DRIZZLE_TIMESTAMP_DATETIME);
431
/* Variables that are bits in THD */
433
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
234
static sys_var_const_str sys_version_compile_vendor(&vars, "version_compile_vendor",
237
/* Variables that are bits in Session */
239
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
434
240
set_option_autocommit,
435
241
OPTION_NOT_AUTOCOMMIT,
437
static sys_var_thd_bit sys_big_tables(&vars, "big_tables", 0,
440
#ifndef TO_BE_DELETED /* Alias for big_tables */
441
static sys_var_thd_bit sys_sql_big_tables(&vars, "sql_big_tables", 0,
445
static sys_var_thd_bit sys_big_selects(&vars, "sql_big_selects", 0,
243
static sys_var_session_bit sys_big_selects(&vars, "sql_big_selects", 0,
447
245
OPTION_BIG_SELECTS);
448
static sys_var_thd_bit sys_log_off(&vars, "sql_log_off",
452
static sys_var_thd_bit sys_log_update(&vars, "sql_log_update",
456
static sys_var_thd_bit sys_log_binlog(&vars, "sql_log_bin",
460
static sys_var_thd_bit sys_sql_warnings(&vars, "sql_warnings", 0,
246
static sys_var_session_bit sys_sql_warnings(&vars, "sql_warnings", 0,
462
248
OPTION_WARNINGS);
463
static sys_var_thd_bit sys_sql_notes(&vars, "sql_notes", 0,
249
static sys_var_session_bit sys_sql_notes(&vars, "sql_notes", 0,
465
251
OPTION_SQL_NOTES);
466
static sys_var_thd_bit sys_auto_is_null(&vars, "sql_auto_is_null", 0,
468
OPTION_AUTO_IS_NULL, 0,
469
sys_var::SESSION_VARIABLE_IN_BINLOG);
470
static sys_var_thd_bit sys_safe_updates(&vars, "sql_safe_updates", 0,
472
OPTION_SAFE_UPDATES);
473
static sys_var_thd_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
252
static sys_var_session_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
475
254
OPTION_BUFFER_RESULT);
476
static sys_var_thd_bit sys_quote_show_create(&vars, "sql_quote_show_create", 0,
478
OPTION_QUOTE_SHOW_CREATE);
479
static sys_var_thd_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
255
static sys_var_session_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
481
OPTION_NO_FOREIGN_KEY_CHECKS,
482
1, sys_var::SESSION_VARIABLE_IN_BINLOG);
483
static sys_var_thd_bit sys_unique_checks(&vars, "unique_checks", 0,
257
OPTION_NO_FOREIGN_KEY_CHECKS, 1);
258
static sys_var_session_bit sys_unique_checks(&vars, "unique_checks", 0,
485
OPTION_RELAXED_UNIQUE_CHECKS,
487
sys_var::SESSION_VARIABLE_IN_BINLOG);
260
OPTION_RELAXED_UNIQUE_CHECKS, 1);
488
261
/* Local state variables */
490
static sys_var_thd_ha_rows sys_select_limit(&vars, "sql_select_limit",
263
static sys_var_session_ha_rows sys_select_limit(&vars, "sql_select_limit",
491
264
&SV::select_limit);
492
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
493
sys_var::SESSION_VARIABLE_IN_BINLOG);
265
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
494
266
static sys_var_last_insert_id
495
sys_last_insert_id(&vars, "last_insert_id",
496
sys_var::SESSION_VARIABLE_IN_BINLOG);
267
sys_last_insert_id(&vars, "last_insert_id");
498
269
identity is an alias for last_insert_id(), so that we are compatible
501
static sys_var_last_insert_id
502
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
272
static sys_var_last_insert_id sys_identity(&vars, "identity");
504
static sys_var_thd_lc_time_names
505
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
274
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
508
insert_id should *not* be marked as written to the binlog (i.e., it
509
should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
510
because we want any statement that refers to insert_id explicitly to
511
be unsafe. (By "explicitly", we mean using @@session.insert_id,
512
whereas insert_id is used "implicitly" when NULL value is inserted
513
into an auto_increment column).
515
277
We want statements referring explicitly to @@session.insert_id to be
516
278
unsafe, because insert_id is modified internally by the slave sql
517
279
thread when NULL values are inserted in an AUTO_INCREMENT column.
758
374
If one doesn't use the SESSION modifier, the isolation level
759
375
is only active for the next command.
761
static void fix_tx_isolation(THD *thd, enum_var_type type)
377
static void fix_tx_isolation(Session *session, enum_var_type type)
763
379
if (type == OPT_SESSION)
764
thd->session_tx_isolation= ((enum_tx_isolation)
765
thd->variables.tx_isolation);
380
session->session_tx_isolation= ((enum_tx_isolation)
381
session->variables.tx_isolation);
768
static void fix_completion_type(THD *thd __attribute__((unused)),
769
enum_var_type type __attribute__((unused))) {}
384
static void fix_completion_type(Session *, enum_var_type) {}
771
static int check_completion_type(THD *thd __attribute__((unused)),
386
static int check_completion_type(Session *, set_var *var)
774
388
int64_t val= var->value->val_int();
775
389
if (val < 0 || val > 2)
778
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
786
If we are changing the thread variable, we have to copy it to NET too
789
#ifdef HAVE_REPLICATION
790
static void fix_net_read_timeout(THD *thd, enum_var_type type)
792
if (type != OPT_GLOBAL)
793
my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
797
static void fix_net_write_timeout(THD *thd, enum_var_type type)
799
if (type != OPT_GLOBAL)
800
my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
803
static void fix_net_retry_count(THD *thd, enum_var_type type)
805
if (type != OPT_GLOBAL)
806
thd->net.retry_count=thd->variables.net_retry_count;
808
#else /* HAVE_REPLICATION */
809
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
810
enum_var_type type __attribute__((unused)))
812
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
813
enum_var_type type __attribute__((unused)))
815
static void fix_net_retry_count(THD *thd __attribute__((unused)),
816
enum_var_type type __attribute__((unused)))
818
#endif /* HAVE_REPLICATION */
821
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
822
enum_var_type type __attribute__((unused)))
824
switch ((enum_delay_key_write) delay_key_write_options) {
825
case DELAY_KEY_WRITE_NONE:
826
myisam_delay_key_write=0;
828
case DELAY_KEY_WRITE_ON:
829
myisam_delay_key_write=1;
831
case DELAY_KEY_WRITE_ALL:
832
myisam_delay_key_write=1;
833
ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
838
bool sys_var_set::update(THD *thd __attribute__((unused)),
841
*value= var->save_result.ulong_value;
845
uchar *sys_var_set::value_ptr(THD *thd,
846
enum_var_type type __attribute__((unused)),
847
LEX_STRING *base __attribute__((unused)))
850
String tmp(buff, sizeof(buff), &my_charset_latin1);
855
for (uint i= 0; val; val>>= 1, i++)
859
tmp.append(enum_names->type_names[i],
860
enum_names->type_lengths[i]);
865
if ((length= tmp.length()))
867
return (uchar*) thd->strmake(tmp.ptr(), length);
870
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
871
enum_var_type type __attribute__((unused)))
873
slave_exec_mode_options= 0;
874
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
877
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
879
bool rc= sys_var_set::check(thd, var);
881
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
882
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
885
my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
890
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
893
pthread_mutex_lock(&LOCK_global_system_variables);
894
rc= sys_var_set::update(thd, var);
895
pthread_mutex_unlock(&LOCK_global_system_variables);
899
void fix_slave_exec_mode(enum_var_type type __attribute__((unused)))
901
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
902
bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
904
sql_print_error("Ambiguous slave modes combination."
905
" STRICT will be used");
906
bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
908
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
909
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
912
bool sys_var_thd_binlog_format::is_readonly() const
915
Under certain circumstances, the variable is read-only (unchangeable):
917
THD *thd= current_thd;
919
If RBR and open temporary tables, their CREATE TABLE may not be in the
920
binlog, so we can't toggle to SBR in this connection.
921
The test below will also prevent SET GLOBAL, well it was not easy to test
922
if global or not here.
923
And this test will also prevent switching from RBR to RBR (a no-op which
924
should not happen too often).
926
If we don't have row-based replication compiled in, the variable
929
if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
930
thd->temporary_tables)
932
my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
936
if in a stored function/trigger, it's too late to change mode
938
if (thd->in_sub_stmt)
940
my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
943
return sys_var_thd_enum::is_readonly();
947
void fix_binlog_format_after_update(THD *thd,
948
enum_var_type type __attribute__((unused)))
950
thd->reset_current_stmt_binlog_row_based();
954
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
955
enum_var_type type __attribute__((unused)))
957
mysql_bin_log.set_max_size(max_binlog_size);
958
#ifdef HAVE_REPLICATION
959
if (!max_relay_log_size)
960
active_mi->rli.relay_log.set_max_size(max_binlog_size);
965
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
966
enum_var_type type __attribute__((unused)))
968
#ifdef HAVE_REPLICATION
969
active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
970
max_relay_log_size: max_binlog_size);
975
static void fix_max_connections(THD *thd __attribute__((unused)),
976
enum_var_type type __attribute__((unused)))
978
resize_thr_alarm(max_connections + 10);
982
static void fix_thd_mem_root(THD *thd, enum_var_type type)
984
if (type != OPT_GLOBAL)
985
reset_root_defaults(thd->mem_root,
986
thd->variables.query_alloc_block_size,
987
thd->variables.query_prealloc_size);
991
static void fix_trans_mem_root(THD *thd, enum_var_type type)
993
if (type != OPT_GLOBAL)
994
reset_root_defaults(&thd->transaction.mem_root,
995
thd->variables.trans_alloc_block_size,
996
thd->variables.trans_prealloc_size);
1000
static void fix_server_id(THD *thd __attribute__((unused)),
1001
enum_var_type type __attribute__((unused)))
1003
server_id_supplied = 1;
1004
thd->server_id= server_id;
1008
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
1009
const char *name, int64_t val)
392
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
399
static void fix_session_mem_root(Session *session, enum_var_type type)
401
if (type != OPT_GLOBAL)
402
reset_root_defaults(session->mem_root,
403
session->variables.query_alloc_block_size,
404
session->variables.query_prealloc_size);
407
static void fix_server_id(Session *, enum_var_type)
412
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
413
const std::string &name, int64_t val)
1016
ullstr((uint64_t) val, buf);
420
internal::ullstr((uint64_t) val, buf);
422
internal::llstr(val, buf);
1020
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
424
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1021
425
ER_TRUNCATED_WRONG_VALUE,
1022
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
426
ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
1027
static uint64_t fix_unsigned(THD *thd, uint64_t num,
431
uint64_t fix_unsigned(Session *session, uint64_t num,
1028
432
const struct my_option *option_limits)
1030
434
bool fixed= false;
1031
435
uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
1033
throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
1037
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
1039
if (var->value->unsigned_flag)
1040
var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
1043
int64_t v= var->value->val_int();
1044
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
1051
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
1052
sys_after_update_func after_update_arg)
1053
:sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
1054
&LOCK_global_system_variables, after_update_arg)
1058
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
1060
return get_unsigned(thd, var);
1063
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
1065
uint64_t tmp= var->save_result.uint64_t_value;
1066
pthread_mutex_lock(guard);
437
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
442
static size_t fix_size_t(Session *session, size_t num,
443
const struct my_option *option_limits)
446
size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
448
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
452
static bool get_unsigned32(Session *session, set_var *var)
454
if (var->value->unsigned_flag)
455
var->save_result.uint32_t_value=
456
static_cast<uint32_t>(var->value->val_int());
459
int64_t v= var->value->val_int();
461
throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
463
var->save_result.uint32_t_value=
464
static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
469
static bool get_unsigned64(Session *, set_var *var)
471
if (var->value->unsigned_flag)
472
var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
475
int64_t v= var->value->val_int();
476
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
481
static bool get_size_t(Session *, set_var *var)
483
if (var->value->unsigned_flag)
484
var->save_result.size_t_value= (size_t) var->value->val_int();
487
ssize_t v= (ssize_t)var->value->val_int();
488
var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
493
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
495
var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
499
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
501
uint32_t tmp= var->save_result.uint32_t_value;
502
pthread_mutex_lock(&LOCK_global_system_variables);
1067
503
if (option_limits)
1068
*value= (ulong) fix_unsigned(thd, tmp, option_limits);
1071
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1072
/* Avoid overflows on 32 bit systems */
1073
if (tmp > ULONG_MAX)
1076
throw_bounds_warning(thd, true, true, name,
1077
(int64_t) var->save_result.uint64_t_value);
1080
*value= (ulong) tmp;
505
uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
1083
pthread_mutex_unlock(guard);
510
*value= (uint32_t) tmp;
511
pthread_mutex_unlock(&LOCK_global_system_variables);
1088
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
516
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
1091
pthread_mutex_lock(guard);
1092
*value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
1093
option_limits, ¬_used);
1094
pthread_mutex_unlock(guard);
519
pthread_mutex_lock(&LOCK_global_system_variables);
520
*value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
521
option_limits, ¬_used);
522
pthread_mutex_unlock(&LOCK_global_system_variables);
1098
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
526
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1100
528
uint64_t tmp= var->save_result.uint64_t_value;
1101
529
pthread_mutex_lock(&LOCK_global_system_variables);
1102
530
if (option_limits)
1103
*value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
532
uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
1105
537
*value= (uint64_t) tmp;
1106
538
pthread_mutex_unlock(&LOCK_global_system_variables);
1556
my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
984
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
1562
bool sys_var_thd_enum::update(THD *thd, set_var *var)
990
bool sys_var_session_enum::update(Session *session, set_var *var)
1564
992
if (var->type == OPT_GLOBAL)
1565
global_system_variables.*offset= var->save_result.ulong_value;
993
global_system_variables.*offset= var->save_result.uint32_t_value;
1567
thd->variables.*offset= var->save_result.ulong_value;
995
session->variables.*offset= var->save_result.uint32_t_value;
1572
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
1000
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1574
1002
if (type == OPT_GLOBAL)
1575
global_system_variables.*offset= (ulong) option_limits->def_value;
1003
global_system_variables.*offset= (uint32_t) option_limits->def_value;
1577
thd->variables.*offset= global_system_variables.*offset;
1005
session->variables.*offset= global_system_variables.*offset;
1581
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1582
LEX_STRING *base __attribute__((unused)))
1009
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1584
ulong tmp= ((type == OPT_GLOBAL) ?
1013
uint32_t tmp= ((type == OPT_GLOBAL) ?
1585
1014
global_system_variables.*offset :
1586
thd->variables.*offset);
1587
return (uchar*) enum_names->type_names[tmp];
1590
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1592
return (check_enum(thd, var, &bool_typelib) ||
1593
(check_func && (*check_func)(thd, var)));
1596
bool sys_var_thd_bit::update(THD *thd, set_var *var)
1598
int res= (*update_func)(thd, var);
1015
session->variables.*offset);
1016
return (unsigned char*) enum_names->type_names[tmp];
1019
bool sys_var_session_bit::check(Session *session, set_var *var)
1021
return (check_enum(session, var, &bool_typelib) ||
1022
(check_func && (*check_func)(session, var)));
1025
bool sys_var_session_bit::update(Session *session, set_var *var)
1027
int res= (*update_func)(session, var);
1603
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1604
enum_var_type type __attribute__((unused)),
1605
LEX_STRING *base __attribute__((unused)))
1032
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
1608
1036
If reverse is 0 (default) return 1 if bit is set.
1609
1037
If reverse is 1, return 0 if bit is set
1611
thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
1039
session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1612
1040
!reverse : reverse);
1613
return (uchar*) &thd->sys_var_tmp.bool_value;
1617
/** Update a date_time format variable based on given value. */
1619
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
1620
DATE_TIME_FORMAT *new_value)
1622
DATE_TIME_FORMAT *old;
1624
if (type == OPT_GLOBAL)
1626
pthread_mutex_lock(&LOCK_global_system_variables);
1627
old= (global_system_variables.*offset);
1628
(global_system_variables.*offset)= new_value;
1629
pthread_mutex_unlock(&LOCK_global_system_variables);
1633
old= (thd->variables.*offset);
1634
(thd->variables.*offset)= new_value;
1636
my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1641
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
1643
DATE_TIME_FORMAT *new_value;
1644
/* We must make a copy of the last value to get it into normal memory */
1645
new_value= date_time_format_copy((THD*) 0,
1646
var->save_result.date_time_format);
1648
return 1; // Out of memory
1649
update2(thd, var->type, new_value); // Can't fail
1654
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
1656
char buff[STRING_BUFFER_USUAL_SIZE];
1657
String str(buff,sizeof(buff), system_charset_info), *res;
1658
DATE_TIME_FORMAT *format;
1660
if (!(res=var->value->val_str(&str)))
1661
res= &my_empty_string;
1663
if (!(format= date_time_format_make(date_time_type,
1664
res->ptr(), res->length())))
1666
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1671
We must copy result to thread space to not get a memory leak if
1674
var->save_result.date_time_format= date_time_format_copy(thd, format);
1675
my_free((char*) format, MYF(0));
1676
return var->save_result.date_time_format == 0;
1680
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
1682
DATE_TIME_FORMAT *res= 0;
1684
if (type == OPT_GLOBAL)
1687
if ((format= opt_date_time_formats[date_time_type]))
1688
res= date_time_format_make(date_time_type, format, strlen(format));
1692
/* Make copy with malloc */
1693
res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
1696
if (res) // Should always be true
1697
update2(thd, type, res);
1701
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1702
LEX_STRING *base __attribute__((unused)))
1704
if (type == OPT_GLOBAL)
1708
We do a copy here just to be sure things will work even if someone
1709
is modifying the original string while the copy is accessed
1710
(Can't happen now in SQL SHOW, but this is a good safety for the future)
1712
res= thd->strmake((global_system_variables.*offset)->format.str,
1713
(global_system_variables.*offset)->format.length);
1714
return (uchar*) res;
1716
return (uchar*) (thd->variables.*offset)->format.str;
1041
return (unsigned char*) &session->sys_var_tmp.bool_value;
1789
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
1792
const CHARSET_INFO *tmp;
1794
if (var->value->result_type() == STRING_RESULT)
1796
char buff[STRING_BUFFER_USUAL_SIZE];
1797
String str(buff,sizeof(buff), system_charset_info), *res;
1798
if (!(res=var->value->val_str(&str)))
1802
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1807
else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
1808
!(tmp=get_old_charset_by_name(res->c_ptr())))
1810
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1816
if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1819
int10_to_str((int) var->value->val_int(), buf, -10);
1820
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf);
1824
var->save_result.charset= tmp; // Save for update
1829
bool sys_var_character_set::update(THD *thd, set_var *var)
1831
ci_ptr(thd,var->type)[0]= var->save_result.charset;
1832
thd->update_charset();
1837
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1838
LEX_STRING *base __attribute__((unused)))
1840
const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
1841
return cs ? (uchar*) cs->csname : (uchar*) NULL;
1845
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
1847
if (type == OPT_GLOBAL)
1848
global_system_variables.*offset= *global_default;
1851
thd->variables.*offset= global_system_variables.*offset;
1852
thd->update_charset();
1855
const CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1857
if (type == OPT_GLOBAL)
1858
return &(global_system_variables.*offset);
1860
return &(thd->variables.*offset);
1864
bool sys_var_character_set_client::check(THD *thd, set_var *var)
1866
if (sys_var_character_set_sv::check(thd, var))
1868
/* Currently, UCS-2 cannot be used as a client character set */
1869
if (var->save_result.charset->mbminlen > 1)
1871
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name,
1872
var->save_result.charset->csname);
1879
const CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1882
if (type == OPT_GLOBAL)
1883
return &global_system_variables.collation_database;
1885
return &thd->variables.collation_database;
1889
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
1891
if (type == OPT_GLOBAL)
1892
global_system_variables.collation_database= default_charset_info;
1895
thd->variables.collation_database= thd->db_charset;
1896
thd->update_charset();
1901
bool sys_var_collation_sv::update(THD *thd, set_var *var)
1085
bool sys_var_collation_sv::update(Session *session, set_var *var)
1903
1087
if (var->type == OPT_GLOBAL)
1904
1088
global_system_variables.*offset= var->save_result.charset;
1907
thd->variables.*offset= var->save_result.charset;
1908
thd->update_charset();
1091
session->variables.*offset= var->save_result.charset;
1914
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
1097
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1916
1099
if (type == OPT_GLOBAL)
1917
1100
global_system_variables.*offset= *global_default;
1920
thd->variables.*offset= global_system_variables.*offset;
1921
thd->update_charset();
1103
session->variables.*offset= global_system_variables.*offset;
1926
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1927
LEX_STRING *base __attribute__((unused)))
1108
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1929
1112
const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1930
global_system_variables.*offset : thd->variables.*offset);
1931
return cs ? (uchar*) cs->name : (uchar*) "NULL";
1935
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1937
static KEY_CACHE zero_key_cache;
1939
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
1941
safe_mutex_assert_owner(&LOCK_global_system_variables);
1942
if (!cache_name || ! cache_name->length)
1943
cache_name= &default_key_cache_base;
1944
return ((KEY_CACHE*) find_named(&key_caches,
1945
cache_name->str, cache_name->length, 0));
1949
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
1950
enum_var_type type __attribute__((unused)),
1951
LEX_STRING *base __attribute__((unused)))
1953
KEY_CACHE *key_cache= get_key_cache(base);
1955
key_cache= &zero_key_cache;
1956
return (uchar*) key_cache + offset ;
1960
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1962
uint64_t tmp= var->save_result.uint64_t_value;
1963
LEX_STRING *base_name= &var->base;
1964
KEY_CACHE *key_cache;
1967
/* If no basename, assume it's for the key cache named 'default' */
1968
if (!base_name->length)
1969
base_name= &default_key_cache_base;
1971
pthread_mutex_lock(&LOCK_global_system_variables);
1972
key_cache= get_key_cache(base_name);
1976
/* Key cache didn't exists */
1977
if (!tmp) // Tried to delete cache
1978
goto end; // Ok, nothing to do
1979
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
1987
Abort if some other thread is changing the key cache
1988
TODO: This should be changed so that we wait until the previous
1989
assignment is done and then do the new assign
1991
if (key_cache->in_init)
1994
if (!tmp) // Zero size means delete
1996
if (key_cache == dflt_key_cache)
1998
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1999
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
2000
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
2001
goto end; // Ignore default key cache
2004
if (key_cache->key_cache_inited) // If initied
2007
Move tables using this key cache to the default key cache
2008
and clear the old key cache.
2011
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
2012
base_name->length, &list);
2013
key_cache->in_init= 1;
2014
pthread_mutex_unlock(&LOCK_global_system_variables);
2015
error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
2016
pthread_mutex_lock(&LOCK_global_system_variables);
2017
key_cache->in_init= 0;
2020
We don't delete the key cache as some running threads my still be
2021
in the key cache code with a pointer to the deleted (empty) key cache
2026
key_cache->param_buff_size=
2027
(uint64_t) fix_unsigned(thd, tmp, option_limits);
2029
/* If key cache didn't existed initialize it, else resize it */
2030
key_cache->in_init= 1;
2031
pthread_mutex_unlock(&LOCK_global_system_variables);
2033
if (!key_cache->key_cache_inited)
2034
error= (bool) (ha_init_key_cache("", key_cache));
2036
error= (bool)(ha_resize_key_cache(key_cache));
2038
pthread_mutex_lock(&LOCK_global_system_variables);
2039
key_cache->in_init= 0;
2042
pthread_mutex_unlock(&LOCK_global_system_variables);
2049
Abort if some other thread is changing the key cache.
2050
This should be changed so that we wait until the previous
2051
assignment is done and then do the new assign
2053
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
2055
ulong tmp= (ulong) var->value->val_int();
2056
LEX_STRING *base_name= &var->base;
2059
if (!base_name->length)
2060
base_name= &default_key_cache_base;
2062
pthread_mutex_lock(&LOCK_global_system_variables);
2063
KEY_CACHE *key_cache= get_key_cache(base_name);
2065
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
2066
base_name->length)))
2073
Abort if some other thread is changing the key cache
2074
TODO: This should be changed so that we wait until the previous
2075
assignment is done and then do the new assign
2077
if (key_cache->in_init)
2080
*((ulong*) (((char*) key_cache) + offset))=
2081
(ulong) fix_unsigned(thd, tmp, option_limits);
2084
Don't create a new key cache if it didn't exist
2085
(key_caches are created only when the user sets block_size)
2087
key_cache->in_init= 1;
2089
pthread_mutex_unlock(&LOCK_global_system_variables);
2091
error= (bool) (ha_resize_key_cache(key_cache));
2093
pthread_mutex_lock(&LOCK_global_system_variables);
2094
key_cache->in_init= 0;
2097
pthread_mutex_unlock(&LOCK_global_system_variables);
2102
bool sys_var_log_state::update(THD *thd, set_var *var)
2105
pthread_mutex_lock(&LOCK_global_system_variables);
2106
if (!var->save_result.ulong_value)
2108
logger.deactivate_log_handler(thd, log_type);
2112
res= logger.activate_log_handler(thd, log_type);
2113
pthread_mutex_unlock(&LOCK_global_system_variables);
2117
void sys_var_log_state::set_default(THD *thd,
2118
enum_var_type type __attribute__((unused)))
2120
pthread_mutex_lock(&LOCK_global_system_variables);
2121
logger.deactivate_log_handler(thd, log_type);
2122
pthread_mutex_unlock(&LOCK_global_system_variables);
2126
static int sys_check_log_path(THD *thd __attribute__((unused)),
2129
char path[FN_REFLEN], buff[FN_REFLEN];
2131
String str(buff, sizeof(buff), system_charset_info), *res;
2132
const char *log_file_str;
2135
if (!(res= var->value->val_str(&str)))
2138
log_file_str= res->c_ptr();
2139
memset(&f_stat, 0, sizeof(struct stat));
2141
path_length= unpack_filename(path, log_file_str);
2145
/* File name is empty. */
2150
if (!stat(path, &f_stat))
2153
A file system object exists. Check if argument is a file and we have
2157
if (!S_ISREG(f_stat.st_mode) ||
2158
!(f_stat.st_mode & S_IWRITE))
2164
/* Get dirname of the file path. */
2165
(void) dirname_part(path, log_file_str, &path_length);
2167
/* Dirname is empty if file path is relative. */
2172
Check if directory exists and we have permission to create file and
2175
if (my_access(path, (F_OK|W_OK)))
2181
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name,
2182
res ? log_file_str : "NULL");
2187
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
2188
sys_var_str *var_str,
2189
set_var *var, const char *log_ext,
2190
bool log_state, uint log_type)
2192
DRIZZLE_QUERY_LOG *file_log;
2193
char buff[FN_REFLEN];
2194
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2196
uint str_length= (var ? var->value->str_value.length() : 0);
2199
case QUERY_LOG_SLOW:
2200
file_log= logger.get_slow_log_file_handler();
2202
case QUERY_LOG_GENERAL:
2203
file_log= logger.get_log_file_handler();
2206
assert(0); // Impossible
2211
old_value= make_default_log_name(buff, log_ext);
2212
str_length= strlen(old_value);
2214
if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
2220
pthread_mutex_lock(&LOCK_global_system_variables);
2221
logger.lock_exclusive();
2223
if (file_log && log_state)
2225
old_value= var_str->value;
2226
var_str->value= res;
2227
var_str->value_length= str_length;
2228
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
2229
if (file_log && log_state)
2232
case QUERY_LOG_SLOW:
2233
file_log->open_slow_log(sys_var_slow_log_path.value);
2235
case QUERY_LOG_GENERAL:
2236
file_log->open_query_log(sys_var_general_log_path.value);
2244
pthread_mutex_unlock(&LOCK_global_system_variables);
2251
static bool sys_update_general_log_path(THD *thd, set_var * var)
2253
return update_sys_var_str_path(thd, &sys_var_general_log_path,
2254
var, ".log", opt_log, QUERY_LOG_GENERAL);
2258
static void sys_default_general_log_path(THD *thd,
2259
enum_var_type type __attribute__((unused)))
2261
(void) update_sys_var_str_path(thd, &sys_var_general_log_path,
2262
0, ".log", opt_log, QUERY_LOG_GENERAL);
2266
static bool sys_update_slow_log_path(THD *thd, set_var * var)
2268
return update_sys_var_str_path(thd, &sys_var_slow_log_path,
2269
var, "-slow.log", opt_slow_log,
2274
static void sys_default_slow_log_path(THD *thd,
2275
enum_var_type type __attribute__((unused)))
2277
(void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
2278
0, "-slow.log", opt_slow_log,
2283
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
2286
pthread_mutex_lock(&LOCK_global_system_variables);
2287
logger.lock_exclusive();
2288
logger.init_slow_log(var->save_result.ulong_value);
2289
logger.init_general_log(var->save_result.ulong_value);
2290
*value= var->save_result.ulong_value;
2292
pthread_mutex_unlock(&LOCK_global_system_variables);
2297
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
2298
enum_var_type type __attribute__((unused)))
2300
pthread_mutex_lock(&LOCK_global_system_variables);
2301
logger.lock_exclusive();
2302
logger.init_slow_log(LOG_FILE);
2303
logger.init_general_log(LOG_FILE);
2306
pthread_mutex_unlock(&LOCK_global_system_variables);
2310
uchar *sys_var_log_output::value_ptr(THD *thd,
2311
enum_var_type type __attribute__((unused)),
2312
LEX_STRING *base __attribute__((unused)))
2315
String tmp(buff, sizeof(buff), &my_charset_latin1);
2320
for (uint i= 0; val; val>>= 1, i++)
2324
tmp.append(log_output_typelib.type_names[i],
2325
log_output_typelib.type_lengths[i]);
2330
if ((length= tmp.length()))
2332
return (uchar*) thd->strmake(tmp.ptr(), length);
2336
/*****************************************************************************
2337
Functions to handle SET NAMES and SET CHARACTER SET
2338
*****************************************************************************/
2340
int set_var_collation_client::check(THD *thd __attribute__((unused)))
2342
/* Currently, UCS-2 cannot be used as a client character set */
2343
if (character_set_client->mbminlen > 1)
2345
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
2346
character_set_client->csname);
2352
int set_var_collation_client::update(THD *thd)
2354
thd->variables.character_set_client= character_set_client;
2355
thd->variables.character_set_results= character_set_results;
2356
thd->variables.collation_connection= collation_connection;
2357
thd->update_charset();
2358
thd->protocol_text.init(thd);
1113
global_system_variables.*offset :
1114
session->variables.*offset);
1115
return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
2362
1118
/****************************************************************************/
2364
bool sys_var_timestamp::update(THD *thd, set_var *var)
1120
bool sys_var_timestamp::update(Session *session, set_var *var)
2366
thd->set_time((time_t) var->save_result.uint64_t_value);
1122
session->set_time((time_t) var->save_result.uint64_t_value);
2371
void sys_var_timestamp::set_default(THD *thd,
2372
enum_var_type type __attribute__((unused)))
2378
uchar *sys_var_timestamp::value_ptr(THD *thd,
2379
enum_var_type type __attribute__((unused)),
2380
LEX_STRING *base __attribute__((unused)))
2382
thd->sys_var_tmp.long_value= (long) thd->start_time;
2383
return (uchar*) &thd->sys_var_tmp.long_value;
2387
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2389
thd->first_successful_insert_id_in_prev_stmt=
1127
void sys_var_timestamp::set_default(Session *session, enum_var_type)
1129
session->user_time=0;
1133
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
1136
session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
1137
return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1141
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1143
session->first_successful_insert_id_in_prev_stmt=
2390
1144
var->save_result.uint64_t_value;
2395
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2396
enum_var_type type __attribute__((unused)),
2397
LEX_STRING *base __attribute__((unused)))
1149
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
2400
1154
this tmp var makes it robust againt change of type of
2401
1155
read_first_successful_insert_id_in_prev_stmt().
2403
thd->sys_var_tmp.uint64_t_value=
2404
thd->read_first_successful_insert_id_in_prev_stmt();
2405
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2409
bool sys_var_insert_id::update(THD *thd, set_var *var)
2411
thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2416
uchar *sys_var_insert_id::value_ptr(THD *thd,
2417
enum_var_type type __attribute__((unused)),
2418
LEX_STRING *base __attribute__((unused)))
2420
thd->sys_var_tmp.uint64_t_value=
2421
thd->auto_inc_intervals_forced.minimum();
2422
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2426
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2428
thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2432
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2434
thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2439
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
1157
session->sys_var_tmp.uint64_t_value=
1158
session->read_first_successful_insert_id_in_prev_stmt();
1159
return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1163
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2441
1165
char buff[MAX_TIME_ZONE_NAME_LENGTH];
2442
String str(buff, sizeof(buff), &my_charset_latin1);
1166
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2443
1167
String *res= var->value->val_str(&str);
2445
if (!(var->save_result.time_zone= my_tz_find(thd, res)))
1169
if (!(var->save_result.time_zone= my_tz_find(session, res)))
2447
1171
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
3268
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3269
LEX_STRING *base __attribute__((unused)))
1886
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
3273
LEX_STRING *engine_name;
3274
plugin_ref plugin= thd->variables.*offset;
3275
if (type == OPT_GLOBAL)
3276
plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
3277
hton= plugin_data(plugin, handlerton*);
3278
engine_name= &hton2plugin[hton->slot]->name;
3279
result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
3280
if (type == OPT_GLOBAL)
3281
plugin_unlock(thd, plugin);
1890
unsigned char* result;
1892
plugin::StorageEngine *engine= session->variables.*offset;
1893
if (type == OPT_GLOBAL)
1894
engine= global_system_variables.*offset;
1895
engine_name= engine->getName();
1896
result= (unsigned char *) session->strmake(engine_name.c_str(),
1897
engine_name.size());
3286
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
1902
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
3288
plugin_ref old_value, new_value, *value;
1904
plugin::StorageEngine *old_value, *new_value, **value;
3289
1905
if (type == OPT_GLOBAL)
3291
1907
value= &(global_system_variables.*offset);
3292
new_value= ha_lock_engine(NULL, myisam_hton);
1908
new_value= myisam_engine;
3296
value= &(thd->variables.*offset);
3297
new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
1912
value= &(session->variables.*offset);
1913
new_value= global_system_variables.*offset;
3299
1915
assert(new_value);
3300
1916
old_value= *value;
3301
1917
*value= new_value;
3302
plugin_unlock(NULL, old_value);
3306
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
1921
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3308
plugin_ref *value= &(global_system_variables.*offset), old_value;
1923
plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
3309
1924
if (var->type != OPT_GLOBAL)
3310
value= &(thd->variables.*offset);
1925
value= &(session->variables.*offset);
3311
1926
old_value= *value;
3312
if (old_value != var->save_result.plugin)
3314
*value= my_plugin_lock(NULL, &var->save_result.plugin);
3315
plugin_unlock(NULL, old_value);
3321
sys_var_thd_optimizer_switch::
3322
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
3324
char buff[STRING_BUFFER_USUAL_SIZE*8];
3325
String tmp(buff, sizeof(buff), &my_charset_latin1);
3329
for (uint i= 0; val; val>>= 1, i++)
3333
tmp.append(optimizer_switch_typelib.type_names[i],
3334
optimizer_switch_typelib.type_lengths[i]);
3340
tmp.length(tmp.length() - 1); /* trim the trailing comma */
3342
rep->str= thd->strmake(tmp.ptr(), tmp.length());
3344
rep->length= rep->str ? tmp.length() : 0;
3346
return rep->length != tmp.length();
3350
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3351
LEX_STRING *base __attribute__((unused)))
3354
uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3355
thd->variables.*offset);
3356
(void) symbolic_mode_representation(thd, val, &opts);
3357
return (uchar *) opts.str;
3361
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
3363
if (type == OPT_GLOBAL)
3364
global_system_variables.*offset= 0;
3366
thd->variables.*offset= global_system_variables.*offset;
3370
/****************************************************************************
3372
****************************************************************************/
3374
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3377
I_List_iterator<NAMED_LIST> it(*list);
3378
NAMED_LIST *element;
3379
while ((element= it++))
3381
if (element->cmp(name, length))
3385
return element->data;
3392
void delete_elements(I_List<NAMED_LIST> *list,
3393
void (*free_element)(const char *name, uchar*))
3395
NAMED_LIST *element;
3396
while ((element= list->get()))
3398
(*free_element)(element->name, element->data);
3405
/* Key cache functions */
3407
static KEY_CACHE *create_key_cache(const char *name, uint length)
3409
KEY_CACHE *key_cache;
3411
if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3412
MYF(MY_ZEROFILL | MY_WME))))
3414
if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3416
my_free((char*) key_cache, MYF(0));
3422
Set default values for a key cache
3423
The values in dflt_key_cache_var is set by my_getopt() at startup
3425
We don't set 'buff_size' as this is used to enable the key cache
3427
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
3428
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
3429
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
3436
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3438
LEX_STRING key_cache_name;
3439
KEY_CACHE *key_cache;
3441
key_cache_name.str= (char *) name;
3442
key_cache_name.length= length;
3443
pthread_mutex_lock(&LOCK_global_system_variables);
3444
if (!(key_cache= get_key_cache(&key_cache_name)))
3445
key_cache= create_key_cache(name, length);
3446
pthread_mutex_unlock(&LOCK_global_system_variables);
3451
void free_key_cache(const char *name __attribute__((unused)),
3452
KEY_CACHE *key_cache)
3454
ha_end_key_cache(key_cache);
3455
my_free((char*) key_cache, MYF(0));
3459
bool process_key_caches(process_key_cache_t func)
3461
I_List_iterator<NAMED_LIST> it(key_caches);
3462
NAMED_LIST *element;
3464
while ((element= it++))
3466
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3467
func(element->name, key_cache);
3473
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
3477
/* Prevent self dead-lock */
3478
if (thd->locked_tables || thd->active_transaction())
3480
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3484
if (thd->global_read_lock)
3487
This connection already holds the global read lock.
3488
This can be the case with:
3489
- FLUSH TABLES WITH READ LOCK
3490
- SET GLOBAL READ_ONLY = 1
3492
result= sys_var_bool_ptr::update(thd, var);
3497
Perform a 'FLUSH TABLES WITH READ LOCK'.
3498
This is a 3 step process:
3499
- [1] lock_global_read_lock()
3500
- [2] close_cached_tables()
3501
- [3] make_global_read_lock_block_commit()
3502
[1] prevents new connections from obtaining tables locked for write.
3503
[2] waits until all existing connections close their tables.
3504
[3] prevents transactions from being committed.
3507
if (lock_global_read_lock(thd))
3511
This call will be blocked by any connection holding a READ or WRITE lock.
3512
Ideally, we want to wait only for pending WRITE locks, but since:
3513
con 1> LOCK TABLE T FOR READ;
3514
con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3515
con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3516
can cause to wait on a read lock, it's required for the client application
3517
to unlock everything, and acceptable for the server to wait on all locks.
3519
if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
3520
goto end_with_read_lock;
3522
if ((result= make_global_read_lock_block_commit(thd)) == true)
3523
goto end_with_read_lock;
3525
/* Change the opt_readonly system variable, safe because the lock is held */
3526
result= sys_var_bool_ptr::update(thd, var);
3529
/* Release the lock */
3530
unlock_global_read_lock(thd);
3534
/****************************************************************************
3536
****************************************************************************/
3538
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3539
template class List<set_var_base>;
3540
template class List_iterator_fast<set_var_base>;
3541
template class I_List_iterator<NAMED_LIST>;
1927
if (old_value != var->save_result.storage_engine)
1929
*value= var->save_result.storage_engine;
1934
} /* namespace drizzled */