47
#include "drizzled/option.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"
78
extern bool timed_mutexes;
81
extern plugin::StorageEngine *myisam_engine;
82
extern bool timed_mutexes;
84
extern struct option my_long_options[];
85
extern const CHARSET_INFO *character_set_filesystem;
86
extern size_t my_thread_stack_size;
88
class sys_var_pluginvar;
50
#ifdef USE_PRAGMA_IMPLEMENTATION
51
#pragma implementation // gcc: Class implementation
54
#include "mysql_priv.h"
57
#include <my_getopt.h>
58
#include <thr_alarm.h>
62
extern CHARSET_INFO *character_set_filesystem;
89
65
static DYNAMIC_ARRAY fixed_show_vars;
90
typedef map<string, sys_var *> SystemVariableMap;
91
static SystemVariableMap system_variable_map;
92
extern char *opt_drizzle_tmpdir;
94
extern TYPELIB tx_isolation_typelib;
96
const char *bool_type_names[]= { "OFF", "ON", NULL };
66
static HASH system_variable_hash;
68
const char *bool_type_names[]= { "OFF", "ON", NullS };
97
69
TYPELIB bool_typelib=
99
71
array_elements(bool_type_names)-1, "", bool_type_names, NULL
102
static bool set_option_bit(Session *session, set_var *var);
103
static bool set_option_autocommit(Session *session, set_var *var);
104
static int check_pseudo_thread_id(Session *session, set_var *var);
105
static int check_tx_isolation(Session *session, set_var *var);
106
static void fix_tx_isolation(Session *session, sql_var_t type);
107
static int check_completion_type(Session *session, set_var *var);
108
static void fix_completion_type(Session *session, sql_var_t type);
109
static void fix_max_join_size(Session *session, sql_var_t type);
110
static void fix_session_mem_root(Session *session, sql_var_t type);
111
static void fix_server_id(Session *session, sql_var_t type);
112
static bool get_unsigned32(Session *session, set_var *var);
113
static bool get_unsigned64(Session *session, set_var *var);
114
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
115
const std::string &name, int64_t val);
116
static unsigned char *get_error_count(Session *session);
117
static unsigned char *get_warning_count(Session *session);
118
static unsigned char *get_tmpdir(Session *session);
74
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
75
TYPELIB delay_key_write_typelib=
77
array_elements(delay_key_write_type_names)-1, "",
78
delay_key_write_type_names, NULL
81
const char *slave_exec_mode_names[]=
82
{ "STRICT", "IDEMPOTENT", NullS };
83
static const unsigned int slave_exec_mode_names_len[]=
84
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
85
TYPELIB slave_exec_mode_typelib=
87
array_elements(slave_exec_mode_names)-1, "",
88
slave_exec_mode_names, (unsigned int *) slave_exec_mode_names_len
91
static bool sys_update_init_connect(THD*, set_var*);
92
static void sys_default_init_connect(THD*, enum_var_type type);
93
static bool sys_update_init_slave(THD*, set_var*);
94
static void sys_default_init_slave(THD*, enum_var_type type);
95
static bool set_option_bit(THD *thd, set_var *var);
96
static bool set_option_autocommit(THD *thd, set_var *var);
97
static int check_log_update(THD *thd, set_var *var);
98
static bool set_log_update(THD *thd, set_var *var);
99
static int check_pseudo_thread_id(THD *thd, set_var *var);
100
static void fix_low_priority_updates(THD *thd, enum_var_type type);
101
static int check_tx_isolation(THD *thd, set_var *var);
102
static void fix_tx_isolation(THD *thd, enum_var_type type);
103
static int check_completion_type(THD *thd, set_var *var);
104
static void fix_completion_type(THD *thd, enum_var_type type);
105
static void fix_net_read_timeout(THD *thd, enum_var_type type);
106
static void fix_net_write_timeout(THD *thd, enum_var_type type);
107
static void fix_net_retry_count(THD *thd, enum_var_type type);
108
static void fix_max_join_size(THD *thd, enum_var_type type);
109
static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type);
110
static void fix_max_binlog_size(THD *thd, enum_var_type type);
111
static void fix_max_relay_log_size(THD *thd, enum_var_type type);
112
static void fix_max_connections(THD *thd, enum_var_type type);
113
static void fix_thd_mem_root(THD *thd, enum_var_type type);
114
static void fix_trans_mem_root(THD *thd, enum_var_type type);
115
static void fix_server_id(THD *thd, enum_var_type type);
116
static uint64_t fix_unsigned(THD *, uint64_t, const struct my_option *);
117
static bool get_unsigned(THD *thd, set_var *var);
118
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
119
const char *name, int64_t val);
120
static KEY_CACHE *create_key_cache(const char *name, uint length);
121
static uchar *get_error_count(THD *thd);
122
static uchar *get_warning_count(THD *thd);
123
static uchar *get_tmpdir(THD *thd);
124
static int sys_check_log_path(THD *thd, set_var *var);
125
static bool sys_update_general_log_path(THD *thd, set_var * var);
126
static void sys_default_general_log_path(THD *thd, enum_var_type type);
127
static bool sys_update_slow_log_path(THD *thd, set_var * var);
128
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
121
131
Variable definition list
126
136
The variables are linked into the list. A variable is added to
127
137
it in the constructor (see sys_var class for details).
129
140
static sys_var_chain vars = { NULL, NULL };
131
static sys_var_session_uint64_t
142
static sys_var_thd_ulong
132
143
sys_auto_increment_increment(&vars, "auto_increment_increment",
133
&system_variables::auto_increment_increment);
134
static sys_var_session_uint64_t
144
&SV::auto_increment_increment, NULL, NULL,
145
sys_var::SESSION_VARIABLE_IN_BINLOG);
146
static sys_var_thd_ulong
135
147
sys_auto_increment_offset(&vars, "auto_increment_offset",
136
&system_variables::auto_increment_offset);
138
static sys_var_const_str sys_basedir(&vars, "basedir", drizzle_home);
139
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
140
&system_variables::bulk_insert_buff_size);
141
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
142
&system_variables::completion_type,
143
check_completion_type,
144
fix_completion_type);
145
static sys_var_collation_sv
146
sys_collation_server(&vars, "collation_server", &system_variables::collation_server, &default_charset_info);
147
static sys_var_const_str_ptr sys_datadir(&vars, "datadir", getDatadirPtr());
149
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
150
&system_variables::join_buff_size);
151
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
152
&system_variables::max_allowed_packet);
153
static sys_var_uint64_t_ptr sys_max_connect_errors(&vars, "max_connect_errors",
154
&max_connect_errors);
155
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
156
&system_variables::max_error_count);
157
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
158
&system_variables::max_heap_table_size);
159
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
160
&system_variables::pseudo_thread_id,
161
0, check_pseudo_thread_id);
162
static sys_var_session_ha_rows sys_max_join_size(&vars, "max_join_size",
163
&system_variables::max_join_size,
165
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
166
&system_variables::max_seeks_for_key);
167
static sys_var_session_uint64_t sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
168
&system_variables::max_length_for_sort_data);
169
static sys_var_session_size_t sys_max_sort_length(&vars, "max_sort_length",
170
&system_variables::max_sort_length);
171
static sys_var_uint64_t_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
172
&max_write_lock_count);
173
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
174
&system_variables::min_examined_row_limit);
148
&SV::auto_increment_offset, NULL, NULL,
149
sys_var::SESSION_VARIABLE_IN_BINLOG);
151
static sys_var_const_str sys_basedir(&vars, "basedir", mysql_home);
152
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
154
static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
156
static sys_var_thd_ulong sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
157
&SV::bulk_insert_buff_size);
158
static sys_var_character_set_sv
159
sys_character_set_server(&vars, "character_set_server",
160
&SV::collation_server, &default_charset_info, 0,
161
sys_var::SESSION_VARIABLE_IN_BINLOG);
162
sys_var_const_str sys_charset_system(&vars, "character_set_system",
163
(char *)my_charset_utf8_general_ci.name);
164
static sys_var_character_set_database
165
sys_character_set_database(&vars, "character_set_database",
166
sys_var::SESSION_VARIABLE_IN_BINLOG);
167
static sys_var_character_set_client
168
sys_character_set_client(&vars, "character_set_client",
169
&SV::character_set_client,
170
&default_charset_info,
171
sys_var::SESSION_VARIABLE_IN_BINLOG);
172
static sys_var_character_set_sv
173
sys_character_set_connection(&vars, "character_set_connection",
174
&SV::collation_connection,
175
&default_charset_info, 0,
176
sys_var::SESSION_VARIABLE_IN_BINLOG);
177
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
178
&SV::character_set_results,
179
&default_charset_info, true);
180
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
181
&SV::character_set_filesystem,
182
&character_set_filesystem);
183
static sys_var_thd_ulong sys_completion_type(&vars, "completion_type",
184
&SV::completion_type,
185
check_completion_type,
186
fix_completion_type);
187
static sys_var_collation_sv
188
sys_collation_connection(&vars, "collation_connection",
189
&SV::collation_connection, &default_charset_info,
190
sys_var::SESSION_VARIABLE_IN_BINLOG);
191
static sys_var_collation_sv
192
sys_collation_database(&vars, "collation_database", &SV::collation_database,
193
&default_charset_info,
194
sys_var::SESSION_VARIABLE_IN_BINLOG);
195
static sys_var_collation_sv
196
sys_collation_server(&vars, "collation_server", &SV::collation_server,
197
&default_charset_info,
198
sys_var::SESSION_VARIABLE_IN_BINLOG);
199
static sys_var_long_ptr sys_concurrent_insert(&vars, "concurrent_insert",
200
&myisam_concurrent_insert);
201
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
203
static sys_var_const_str sys_datadir(&vars, "datadir", mysql_real_data_home);
204
static sys_var_enum sys_delay_key_write(&vars, "delay_key_write",
205
&delay_key_write_options,
206
&delay_key_write_typelib,
207
fix_delay_key_write);
209
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
211
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
212
sys_var_str sys_init_connect(&vars, "init_connect", 0,
213
sys_update_init_connect,
214
sys_default_init_connect,0);
215
sys_var_str sys_init_slave(&vars, "init_slave", 0,
216
sys_update_init_slave,
217
sys_default_init_slave,0);
218
static sys_var_thd_ulong sys_interactive_timeout(&vars, "interactive_timeout",
219
&SV::net_interactive_timeout);
220
static sys_var_thd_ulong sys_join_buffer_size(&vars, "join_buffer_size",
221
&SV::join_buff_size);
222
static sys_var_key_buffer_size sys_key_buffer_size(&vars, "key_buffer_size");
223
static sys_var_key_cache_long sys_key_cache_block_size(&vars, "key_cache_block_size",
226
static sys_var_key_cache_long sys_key_cache_division_limit(&vars, "key_cache_division_limit",
228
param_division_limit));
229
static sys_var_key_cache_long sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
231
param_age_threshold));
232
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
234
static sys_var_bool_ptr
235
sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
236
&opt_log_queries_not_using_indexes);
237
static sys_var_thd_ulong sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
238
static sys_var_microseconds sys_var_long_query_time(&vars, "long_query_time",
239
&SV::long_query_time);
240
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
241
&SV::low_priority_updates,
242
fix_low_priority_updates);
243
#ifndef TO_BE_DELETED /* Alias for the low_priority_updates */
244
static sys_var_thd_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
245
&SV::low_priority_updates,
246
fix_low_priority_updates);
248
static sys_var_thd_ulong sys_max_allowed_packet(&vars, "max_allowed_packet",
249
&SV::max_allowed_packet);
250
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
251
&max_binlog_cache_size);
252
static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
254
fix_max_binlog_size);
255
static sys_var_long_ptr sys_max_connections(&vars, "max_connections",
257
fix_max_connections);
258
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
259
&max_connect_errors);
260
static sys_var_thd_ulong sys_max_error_count(&vars, "max_error_count",
261
&SV::max_error_count);
262
static sys_var_thd_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
263
&SV::max_heap_table_size);
264
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
265
&SV::pseudo_thread_id,
266
check_pseudo_thread_id, 0,
267
sys_var::SESSION_VARIABLE_IN_BINLOG);
268
static sys_var_thd_ha_rows sys_max_join_size(&vars, "max_join_size",
271
static sys_var_thd_ulong sys_max_seeks_for_key(&vars, "max_seeks_for_key",
272
&SV::max_seeks_for_key);
273
static sys_var_thd_ulong sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
274
&SV::max_length_for_sort_data);
275
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
277
fix_max_relay_log_size);
278
static sys_var_thd_ulong sys_max_sort_length(&vars, "max_sort_length",
279
&SV::max_sort_length);
280
static sys_var_max_user_conn sys_max_user_connections(&vars, "max_user_connections");
281
static sys_var_thd_ulong sys_max_tmp_tables(&vars, "max_tmp_tables",
282
&SV::max_tmp_tables);
283
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
284
&max_write_lock_count);
285
static sys_var_thd_ulong sys_min_examined_row_limit(&vars, "min_examined_row_limit",
286
&SV::min_examined_row_limit);
287
static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
288
&myisam_data_pointer_size);
289
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);
290
static sys_var_thd_ulong sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
291
static sys_var_thd_ulong sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
293
static sys_var_thd_enum sys_myisam_stats_method(&vars, "myisam_stats_method",
294
&SV::myisam_stats_method,
295
&myisam_stats_method_typelib,
297
static sys_var_thd_ulong sys_net_buffer_length(&vars, "net_buffer_length",
298
&SV::net_buffer_length);
299
static sys_var_thd_ulong sys_net_read_timeout(&vars, "net_read_timeout",
300
&SV::net_read_timeout,
301
0, fix_net_read_timeout);
302
static sys_var_thd_ulong sys_net_write_timeout(&vars, "net_write_timeout",
303
&SV::net_write_timeout,
304
0, fix_net_write_timeout);
305
static sys_var_thd_ulong sys_net_retry_count(&vars, "net_retry_count",
306
&SV::net_retry_count,
307
0, fix_net_retry_count);
308
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
309
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
310
&global_system_variables.old_mode);
176
311
/* these two cannot be static */
177
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
178
&system_variables::optimizer_prune_level);
179
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
180
&system_variables::optimizer_search_depth);
182
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
183
&system_variables::preload_buff_size);
184
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
185
&system_variables::read_buff_size);
186
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
187
&system_variables::read_rnd_buff_size);
188
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
189
&system_variables::div_precincrement);
191
static sys_var_session_size_t sys_range_alloc_block_size(&vars, "range_alloc_block_size",
192
&system_variables::range_alloc_block_size);
193
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
194
&system_variables::query_alloc_block_size,
195
false, fix_session_mem_root);
196
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
197
&system_variables::query_prealloc_size,
198
false, fix_session_mem_root);
199
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
312
sys_var_thd_bool sys_old_alter_table(&vars, "old_alter_table",
313
&SV::old_alter_table);
314
static sys_var_thd_ulong sys_optimizer_prune_level(&vars, "optimizer_prune_level",
315
&SV::optimizer_prune_level);
316
static sys_var_thd_ulong sys_optimizer_search_depth(&vars, "optimizer_search_depth",
317
&SV::optimizer_search_depth);
319
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
320
TYPELIB optimizer_use_mrr_typelib= {
321
array_elements(optimizer_use_mrr_names) - 1, "",
322
optimizer_use_mrr_names, NULL
325
static sys_var_thd_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
326
&SV::optimizer_use_mrr,
327
&optimizer_use_mrr_typelib,
330
static sys_var_thd_ulong sys_preload_buff_size(&vars, "preload_buffer_size",
331
&SV::preload_buff_size);
332
static sys_var_thd_ulong sys_read_buff_size(&vars, "read_buffer_size",
333
&SV::read_buff_size);
334
static sys_var_opt_readonly sys_readonly(&vars, "read_only", &opt_readonly);
335
static sys_var_thd_ulong sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
336
&SV::read_rnd_buff_size);
337
static sys_var_thd_ulong sys_div_precincrement(&vars, "div_precision_increment",
338
&SV::div_precincrement);
339
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
342
static sys_var_thd_ulong sys_range_alloc_block_size(&vars, "range_alloc_block_size",
343
&SV::range_alloc_block_size);
344
static sys_var_thd_ulong sys_query_alloc_block_size(&vars, "query_alloc_block_size",
345
&SV::query_alloc_block_size,
346
0, fix_thd_mem_root);
347
static sys_var_thd_ulong sys_query_prealloc_size(&vars, "query_prealloc_size",
348
&SV::query_prealloc_size,
349
0, fix_thd_mem_root);
350
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
351
static sys_var_thd_ulong sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
352
&SV::trans_alloc_block_size,
353
0, fix_trans_mem_root);
354
static sys_var_thd_ulong sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
355
&SV::trans_prealloc_size,
356
0, fix_trans_mem_root);
358
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
201
359
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
202
360
&opt_secure_file_priv);
204
static sys_var_const_str_ptr sys_scheduler(&vars, "scheduler",
207
static sys_var_uint32_t_ptr sys_server_id(&vars, "server_id", &server_id,
210
static sys_var_session_size_t sys_sort_buffer(&vars, "sort_buffer_size",
211
&system_variables::sortbuff_size);
213
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
214
&system_variables::storage_engine);
361
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
362
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
363
&opt_slave_compressed_protocol);
364
#ifdef HAVE_REPLICATION
365
static sys_var_bool_ptr sys_slave_allow_batching(&vars, "slave_allow_batching",
366
&slave_allow_batching);
367
static sys_var_set_slave_mode slave_exec_mode(&vars,
369
&slave_exec_mode_options,
370
&slave_exec_mode_typelib,
373
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
375
static sys_var_thd_ulong sys_sort_buffer(&vars, "sort_buffer_size",
378
sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
379
even though it is written to the binlog, the slave ignores the
380
MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
381
master's (see log_event.cc: Query_log_event::do_apply_event()).
383
static sys_var_thd_optimizer_switch sys_optimizer_switch(&vars, "optimizer_switch",
384
&SV::optimizer_switch);
385
static sys_var_const_str sys_ssl_ca(&vars, "ssl_ca", NULL);
386
static sys_var_const_str sys_ssl_capath(&vars, "ssl_capath", NULL);
387
static sys_var_const_str sys_ssl_cert(&vars, "ssl_cert", NULL);
388
static sys_var_const_str sys_ssl_cipher(&vars, "ssl_cipher", NULL);
389
static sys_var_const_str sys_ssl_key(&vars, "ssl_key", NULL);
391
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
393
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
215
394
static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone",
216
395
system_time_zone);
217
static sys_var_size_t_ptr sys_table_def_size(&vars, "table_definition_cache",
219
static sys_var_uint64_t_ptr sys_table_cache_size(&vars, "table_open_cache",
396
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
398
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
220
399
&table_cache_size);
221
static sys_var_uint64_t_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
400
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
222
401
&table_lock_wait_timeout);
223
static sys_var_session_enum sys_tx_isolation(&vars, "tx_isolation",
224
&system_variables::tx_isolation,
225
&tx_isolation_typelib,
228
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
229
&system_variables::tmp_table_size);
230
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &internal::timed_mutexes);
231
static sys_var_const_str sys_version(&vars, "version", version().c_str());
402
static sys_var_long_ptr sys_thread_cache_size(&vars, "thread_cache_size",
404
sys_var_long_ptr sys_thread_pool_size(&vars, "thread_pool_size",
406
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
408
&tx_isolation_typelib,
411
static sys_var_thd_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
412
&SV::tmp_table_size);
413
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
414
static sys_var_const_str sys_version(&vars, "version", server_version);
233
415
static sys_var_const_str sys_version_comment(&vars, "version_comment",
234
COMPILATION_COMMENT);
416
MYSQL_COMPILATION_COMMENT);
235
417
static sys_var_const_str sys_version_compile_machine(&vars, "version_compile_machine",
237
419
static sys_var_const_str sys_version_compile_os(&vars, "version_compile_os",
239
static sys_var_const_str sys_version_compile_vendor(&vars, "version_compile_vendor",
242
/* Variables that are bits in Session */
244
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
421
static sys_var_thd_ulong sys_net_wait_timeout(&vars, "wait_timeout",
422
&SV::net_wait_timeout);
424
/* Condition pushdown to storage engine */
425
static sys_var_thd_bool
426
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
427
&SV::engine_condition_pushdown);
429
/* Time/date/datetime formats */
431
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
433
MYSQL_TIMESTAMP_TIME);
434
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
436
MYSQL_TIMESTAMP_DATE);
437
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
438
&SV::datetime_format,
439
MYSQL_TIMESTAMP_DATETIME);
441
/* Variables that are bits in THD */
443
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
245
444
set_option_autocommit,
246
445
OPTION_NOT_AUTOCOMMIT,
248
static sys_var_session_bit sys_big_selects(&vars, "sql_big_selects", 0,
447
static sys_var_thd_bit sys_big_tables(&vars, "big_tables", 0,
450
#ifndef TO_BE_DELETED /* Alias for big_tables */
451
static sys_var_thd_bit sys_sql_big_tables(&vars, "sql_big_tables", 0,
455
static sys_var_thd_bit sys_big_selects(&vars, "sql_big_selects", 0,
250
457
OPTION_BIG_SELECTS);
251
static sys_var_session_bit sys_sql_warnings(&vars, "sql_warnings", 0,
458
static sys_var_thd_bit sys_log_off(&vars, "sql_log_off",
462
static sys_var_thd_bit sys_log_update(&vars, "sql_log_update",
466
static sys_var_thd_bit sys_log_binlog(&vars, "sql_log_bin",
470
static sys_var_thd_bit sys_sql_warnings(&vars, "sql_warnings", 0,
253
472
OPTION_WARNINGS);
254
static sys_var_session_bit sys_sql_notes(&vars, "sql_notes", 0,
473
static sys_var_thd_bit sys_sql_notes(&vars, "sql_notes", 0,
256
475
OPTION_SQL_NOTES);
257
static sys_var_session_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
476
static sys_var_thd_bit sys_auto_is_null(&vars, "sql_auto_is_null", 0,
478
OPTION_AUTO_IS_NULL, 0,
479
sys_var::SESSION_VARIABLE_IN_BINLOG);
480
static sys_var_thd_bit sys_safe_updates(&vars, "sql_safe_updates", 0,
482
OPTION_SAFE_UPDATES);
483
static sys_var_thd_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
259
485
OPTION_BUFFER_RESULT);
260
static sys_var_session_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
486
static sys_var_thd_bit sys_quote_show_create(&vars, "sql_quote_show_create", 0,
488
OPTION_QUOTE_SHOW_CREATE);
489
static sys_var_thd_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
262
OPTION_NO_FOREIGN_KEY_CHECKS, 1);
263
static sys_var_session_bit sys_unique_checks(&vars, "unique_checks", 0,
491
OPTION_NO_FOREIGN_KEY_CHECKS,
492
1, sys_var::SESSION_VARIABLE_IN_BINLOG);
493
static sys_var_thd_bit sys_unique_checks(&vars, "unique_checks", 0,
265
OPTION_RELAXED_UNIQUE_CHECKS, 1);
495
OPTION_RELAXED_UNIQUE_CHECKS,
497
sys_var::SESSION_VARIABLE_IN_BINLOG);
266
498
/* Local state variables */
268
static sys_var_session_ha_rows sys_select_limit(&vars, "sql_select_limit",
269
&system_variables::select_limit);
270
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
500
static sys_var_thd_ha_rows sys_select_limit(&vars, "sql_select_limit",
502
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
503
sys_var::SESSION_VARIABLE_IN_BINLOG);
271
504
static sys_var_last_insert_id
272
sys_last_insert_id(&vars, "last_insert_id");
505
sys_last_insert_id(&vars, "last_insert_id",
506
sys_var::SESSION_VARIABLE_IN_BINLOG);
274
508
identity is an alias for last_insert_id(), so that we are compatible
277
static sys_var_last_insert_id sys_identity(&vars, "identity");
511
static sys_var_last_insert_id
512
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
279
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
514
static sys_var_thd_lc_time_names
515
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
518
insert_id should *not* be marked as written to the binlog (i.e., it
519
should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
520
because we want any statement that refers to insert_id explicitly to
521
be unsafe. (By "explicitly", we mean using @@session.insert_id,
522
whereas insert_id is used "implicitly" when NULL value is inserted
523
into an auto_increment column).
282
525
We want statements referring explicitly to @@session.insert_id to be
283
526
unsafe, because insert_id is modified internally by the slave sql
284
527
thread when NULL values are inserted in an AUTO_INCREMENT column.
379
775
If one doesn't use the SESSION modifier, the isolation level
380
776
is only active for the next command.
382
static void fix_tx_isolation(Session *session, sql_var_t type)
778
static void fix_tx_isolation(THD *thd, enum_var_type type)
384
780
if (type == OPT_SESSION)
385
session->session_tx_isolation= ((enum_tx_isolation)
386
session->variables.tx_isolation);
781
thd->session_tx_isolation= ((enum_tx_isolation)
782
thd->variables.tx_isolation);
389
static void fix_completion_type(Session *, sql_var_t) {}
785
static void fix_completion_type(THD *thd __attribute__((unused)),
786
enum_var_type type __attribute__((unused))) {}
391
static int check_completion_type(Session *, set_var *var)
788
static int check_completion_type(THD *thd __attribute__((__unused__)),
393
791
int64_t val= var->value->val_int();
394
792
if (val < 0 || val > 2)
397
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
404
static void fix_session_mem_root(Session *session, sql_var_t type)
406
if (type != OPT_GLOBAL)
407
session->mem_root->reset_root_defaults(session->variables.query_alloc_block_size,
408
session->variables.query_prealloc_size);
412
static void fix_server_id(Session *, sql_var_t)
417
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
418
const std::string &name, int64_t val)
795
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
803
If we are changing the thread variable, we have to copy it to NET too
806
#ifdef HAVE_REPLICATION
807
static void fix_net_read_timeout(THD *thd, enum_var_type type)
809
if (type != OPT_GLOBAL)
810
my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
814
static void fix_net_write_timeout(THD *thd, enum_var_type type)
816
if (type != OPT_GLOBAL)
817
my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
820
static void fix_net_retry_count(THD *thd, enum_var_type type)
822
if (type != OPT_GLOBAL)
823
thd->net.retry_count=thd->variables.net_retry_count;
825
#else /* HAVE_REPLICATION */
826
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
827
enum_var_type type __attribute__((unused)))
829
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
830
enum_var_type type __attribute__((unused)))
832
static void fix_net_retry_count(THD *thd __attribute__((unused)),
833
enum_var_type type __attribute__((unused)))
835
#endif /* HAVE_REPLICATION */
838
extern void fix_delay_key_write(THD *thd __attribute__((__unused__)),
839
enum_var_type type __attribute__((__unused__)))
841
switch ((enum_delay_key_write) delay_key_write_options) {
842
case DELAY_KEY_WRITE_NONE:
843
myisam_delay_key_write=0;
845
case DELAY_KEY_WRITE_ON:
846
myisam_delay_key_write=1;
848
case DELAY_KEY_WRITE_ALL:
849
myisam_delay_key_write=1;
850
ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
855
bool sys_var_set::update(THD *thd __attribute__((__unused__)),
858
*value= var->save_result.ulong_value;
862
uchar *sys_var_set::value_ptr(THD *thd,
863
enum_var_type type __attribute__((__unused__)),
864
LEX_STRING *base __attribute__((__unused__)))
867
String tmp(buff, sizeof(buff), &my_charset_latin1);
872
for (uint i= 0; val; val>>= 1, i++)
876
tmp.append(enum_names->type_names[i],
877
enum_names->type_lengths[i]);
882
if ((length= tmp.length()))
884
return (uchar*) thd->strmake(tmp.ptr(), length);
887
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((__unused__)),
888
enum_var_type type __attribute__((__unused__)))
890
slave_exec_mode_options= 0;
891
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
894
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
896
bool rc= sys_var_set::check(thd, var);
898
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
899
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
902
my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
907
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
910
pthread_mutex_lock(&LOCK_global_system_variables);
911
rc= sys_var_set::update(thd, var);
912
pthread_mutex_unlock(&LOCK_global_system_variables);
916
void fix_slave_exec_mode(enum_var_type type __attribute__((__unused__)))
918
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
919
bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
921
sql_print_error("Ambiguous slave modes combination."
922
" STRICT will be used");
923
bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
925
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
926
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
929
bool sys_var_thd_binlog_format::is_readonly() const
932
Under certain circumstances, the variable is read-only (unchangeable):
934
THD *thd= current_thd;
936
If RBR and open temporary tables, their CREATE TABLE may not be in the
937
binlog, so we can't toggle to SBR in this connection.
938
The test below will also prevent SET GLOBAL, well it was not easy to test
939
if global or not here.
940
And this test will also prevent switching from RBR to RBR (a no-op which
941
should not happen too often).
943
If we don't have row-based replication compiled in, the variable
946
if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
947
thd->temporary_tables)
949
my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
953
if in a stored function/trigger, it's too late to change mode
955
if (thd->in_sub_stmt)
957
my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
960
return sys_var_thd_enum::is_readonly();
964
void fix_binlog_format_after_update(THD *thd,
965
enum_var_type type __attribute__((__unused__)))
967
thd->reset_current_stmt_binlog_row_based();
971
static void fix_max_binlog_size(THD *thd __attribute__((__unused__)),
972
enum_var_type type __attribute__((__unused__)))
974
mysql_bin_log.set_max_size(max_binlog_size);
975
#ifdef HAVE_REPLICATION
976
if (!max_relay_log_size)
977
active_mi->rli.relay_log.set_max_size(max_binlog_size);
982
static void fix_max_relay_log_size(THD *thd __attribute__((__unused__)),
983
enum_var_type type __attribute__((__unused__)))
985
#ifdef HAVE_REPLICATION
986
active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
987
max_relay_log_size: max_binlog_size);
992
static void fix_max_connections(THD *thd __attribute__((__unused__)),
993
enum_var_type type __attribute__((__unused__)))
995
resize_thr_alarm(max_connections + 10);
999
static void fix_thd_mem_root(THD *thd, enum_var_type type)
1001
if (type != OPT_GLOBAL)
1002
reset_root_defaults(thd->mem_root,
1003
thd->variables.query_alloc_block_size,
1004
thd->variables.query_prealloc_size);
1008
static void fix_trans_mem_root(THD *thd, enum_var_type type)
1010
if (type != OPT_GLOBAL)
1011
reset_root_defaults(&thd->transaction.mem_root,
1012
thd->variables.trans_alloc_block_size,
1013
thd->variables.trans_prealloc_size);
1017
static void fix_server_id(THD *thd __attribute__((__unused__)),
1018
enum_var_type type __attribute__((__unused__)))
1020
server_id_supplied = 1;
1021
thd->server_id= server_id;
1025
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
1026
const char *name, int64_t val)
425
internal::ullstr((uint64_t) val, buf);
1033
ullstr((uint64_t) val, buf);
427
internal::llstr(val, buf);
429
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1037
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
430
1038
ER_TRUNCATED_WRONG_VALUE,
431
ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
1039
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
436
uint64_t fix_unsigned(Session *session, uint64_t num,
437
const struct option *option_limits)
1044
static uint64_t fix_unsigned(THD *thd, uint64_t num,
1045
const struct my_option *option_limits)
439
1047
bool fixed= false;
440
1048
uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
442
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
447
static size_t fix_size_t(Session *session, size_t num,
448
const struct option *option_limits)
451
size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
453
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
457
static bool get_unsigned32(Session *session, set_var *var)
459
if (var->value->unsigned_flag)
460
var->save_result.uint32_t_value=
461
static_cast<uint32_t>(var->value->val_int());
464
int64_t v= var->value->val_int();
466
throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
468
var->save_result.uint32_t_value=
469
static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
474
static bool get_unsigned64(Session *, set_var *var)
476
if (var->value->unsigned_flag)
477
var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
480
int64_t v= var->value->val_int();
481
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
486
static bool get_size_t(Session *, set_var *var)
488
if (var->value->unsigned_flag)
489
var->save_result.size_t_value= (size_t) var->value->val_int();
492
ssize_t v= (ssize_t)var->value->val_int();
493
var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
498
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
500
var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
504
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
506
uint32_t tmp= var->save_result.uint32_t_value;
507
LOCK_global_system_variables.lock();
1050
throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
1054
static bool get_unsigned(THD *thd __attribute__((__unused__)), set_var *var)
1056
if (var->value->unsigned_flag)
1057
var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
1060
int64_t v= var->value->val_int();
1061
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
1068
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
1069
sys_after_update_func after_update_arg)
1070
:sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
1071
&LOCK_global_system_variables, after_update_arg)
1075
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
1077
return get_unsigned(thd, var);
1080
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
1082
uint64_t tmp= var->save_result.uint64_t_value;
1083
pthread_mutex_lock(guard);
508
1084
if (option_limits)
1085
*value= (ulong) fix_unsigned(thd, tmp, option_limits);
510
uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
1088
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1089
/* Avoid overflows on 32 bit systems */
1090
if (tmp > ULONG_MAX)
1093
throw_bounds_warning(thd, true, true, name,
1094
(int64_t) var->save_result.uint64_t_value);
1097
*value= (ulong) tmp;
515
*value= (uint32_t) tmp;
516
LOCK_global_system_variables.unlock();
1100
pthread_mutex_unlock(guard);
521
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
1105
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
524
LOCK_global_system_variables.lock();
525
*value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
526
option_limits, ¬_used);
527
LOCK_global_system_variables.unlock();
1108
pthread_mutex_lock(guard);
1109
*value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
1110
option_limits, ¬_used);
1111
pthread_mutex_unlock(guard);
531
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1115
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
533
1117
uint64_t tmp= var->save_result.uint64_t_value;
534
LOCK_global_system_variables.lock();
1118
pthread_mutex_lock(&LOCK_global_system_variables);
535
1119
if (option_limits)
537
uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
1120
*value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
542
1122
*value= (uint64_t) tmp;
543
LOCK_global_system_variables.unlock();
1123
pthread_mutex_unlock(&LOCK_global_system_variables);
548
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
1128
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((__unused__)),
1129
enum_var_type type __attribute__((__unused__)))
551
LOCK_global_system_variables.lock();
1132
pthread_mutex_lock(&LOCK_global_system_variables);
552
1133
*value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
553
1134
option_limits, ¬_used);
554
LOCK_global_system_variables.unlock();
558
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
560
size_t tmp= var->save_result.size_t_value;
561
LOCK_global_system_variables.lock();
563
*value= fix_size_t(session, tmp, option_limits);
566
LOCK_global_system_variables.unlock();
571
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
574
LOCK_global_system_variables.lock();
575
*value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
576
option_limits, ¬_used);
577
LOCK_global_system_variables.unlock();
580
bool sys_var_bool_ptr::update(Session *, set_var *var)
582
*value= (bool) var->save_result.uint32_t_value;
587
void sys_var_bool_ptr::set_default(Session *, sql_var_t)
1135
pthread_mutex_unlock(&LOCK_global_system_variables);
1139
bool sys_var_bool_ptr::update(THD *thd __attribute__((__unused__)), set_var *var)
1141
*value= (bool) var->save_result.ulong_value;
1146
void sys_var_bool_ptr::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
589
1148
*value= (bool) option_limits->def_value;
594
32 bit types for session variables
596
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
598
return (get_unsigned32(session, var) ||
599
(check_func && (*check_func)(session, var)));
602
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
604
uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
1152
bool sys_var_enum::update(THD *thd __attribute__((__unused__)), set_var *var)
1154
*value= (uint) var->save_result.ulong_value;
1159
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((__unused__)),
1160
enum_var_type type __attribute__((__unused__)),
1161
LEX_STRING *base __attribute__((__unused__)))
1163
return (uchar*) enum_names->type_names[*value];
1167
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((__unused__)),
1168
enum_var_type type __attribute__((__unused__)),
1169
LEX_STRING *base __attribute__((__unused__)))
1171
return (uchar*) enum_names->type_names[global_system_variables.*offset];
1174
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1176
return (get_unsigned(thd, var) ||
1177
(check_func && (*check_func)(thd, var)));
1180
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
1182
uint64_t tmp= var->save_result.uint64_t_value;
606
1184
/* Don't use bigger value than given with --maximum-variable-name=.. */
607
if ((uint32_t) tmp > max_system_variables.*offset)
1185
if ((ulong) tmp > max_system_variables.*offset)
609
throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
1187
throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
610
1188
tmp= max_system_variables.*offset;
613
1191
if (option_limits)
614
tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
615
else if (tmp > UINT32_MAX)
1192
tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1193
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1194
else if (tmp > ULONG_MAX)
618
throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
1197
throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
621
1201
if (var->type == OPT_GLOBAL)
622
global_system_variables.*offset= (uint32_t) tmp;
1202
global_system_variables.*offset= (ulong) tmp;
624
session->variables.*offset= (uint32_t) tmp;
1204
thd->variables.*offset= (ulong) tmp;
630
void sys_var_session_uint32_t::set_default(Session *session, sql_var_t type)
1210
void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
632
1212
if (type == OPT_GLOBAL)
635
1215
/* We will not come here if option_limits is not set */
636
1216
global_system_variables.*offset=
637
(uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
1217
(ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
638
1218
option_limits, ¬_used);
641
session->variables.*offset= global_system_variables.*offset;
1221
thd->variables.*offset= global_system_variables.*offset;
645
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
1225
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1226
LEX_STRING *base __attribute__((__unused__)))
649
1228
if (type == OPT_GLOBAL)
650
return (unsigned char*) &(global_system_variables.*offset);
651
return (unsigned char*) &(session->variables.*offset);
1229
return (uchar*) &(global_system_variables.*offset);
1230
return (uchar*) &(thd->variables.*offset);
655
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1234
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
657
1236
uint64_t tmp= var->save_result.uint64_t_value;
661
1240
tmp= max_system_variables.*offset;
663
1242
if (option_limits)
664
tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1243
tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
665
1244
if (var->type == OPT_GLOBAL)
667
1246
/* Lock is needed to make things safe on 32 bit systems */
668
LOCK_global_system_variables.lock();
1247
pthread_mutex_lock(&LOCK_global_system_variables);
669
1248
global_system_variables.*offset= (ha_rows) tmp;
670
LOCK_global_system_variables.unlock();
1249
pthread_mutex_unlock(&LOCK_global_system_variables);
673
session->variables.*offset= (ha_rows) tmp;
1252
thd->variables.*offset= (ha_rows) tmp;
678
void sys_var_session_ha_rows::set_default(Session *session, sql_var_t type)
1257
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
680
1259
if (type == OPT_GLOBAL)
683
1262
/* We will not come here if option_limits is not set */
684
LOCK_global_system_variables.lock();
1263
pthread_mutex_lock(&LOCK_global_system_variables);
685
1264
global_system_variables.*offset=
686
1265
(ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
687
1266
option_limits, ¬_used);
688
LOCK_global_system_variables.unlock();
1267
pthread_mutex_unlock(&LOCK_global_system_variables);
691
session->variables.*offset= global_system_variables.*offset;
1270
thd->variables.*offset= global_system_variables.*offset;
695
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
1274
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1275
LEX_STRING *base __attribute__((__unused__)))
699
1277
if (type == OPT_GLOBAL)
700
return (unsigned char*) &(global_system_variables.*offset);
701
return (unsigned char*) &(session->variables.*offset);
1278
return (uchar*) &(global_system_variables.*offset);
1279
return (uchar*) &(thd->variables.*offset);
704
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1282
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
706
return (get_unsigned64(session, var) ||
707
(check_func && (*check_func)(session, var)));
1284
return get_unsigned(thd, var);
710
bool sys_var_session_uint64_t::update(Session *session, set_var *var)
1287
bool sys_var_thd_uint64_t::update(THD *thd, set_var *var)
712
1289
uint64_t tmp= var->save_result.uint64_t_value;
714
1291
if (tmp > max_system_variables.*offset)
716
throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
717
1292
tmp= max_system_variables.*offset;
720
1294
if (option_limits)
721
tmp= fix_unsigned(session, tmp, option_limits);
1295
tmp= fix_unsigned(thd, tmp, option_limits);
722
1296
if (var->type == OPT_GLOBAL)
724
1298
/* Lock is needed to make things safe on 32 bit systems */
725
LOCK_global_system_variables.lock();
1299
pthread_mutex_lock(&LOCK_global_system_variables);
726
1300
global_system_variables.*offset= (uint64_t) tmp;
727
LOCK_global_system_variables.unlock();
1301
pthread_mutex_unlock(&LOCK_global_system_variables);
730
session->variables.*offset= (uint64_t) tmp;
1304
thd->variables.*offset= (uint64_t) tmp;
735
void sys_var_session_uint64_t::set_default(Session *session, sql_var_t type)
1309
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
737
1311
if (type == OPT_GLOBAL)
740
LOCK_global_system_variables.lock();
1314
pthread_mutex_lock(&LOCK_global_system_variables);
741
1315
global_system_variables.*offset=
742
1316
getopt_ull_limit_value((uint64_t) option_limits->def_value,
743
1317
option_limits, ¬_used);
744
LOCK_global_system_variables.unlock();
747
session->variables.*offset= global_system_variables.*offset;
751
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
755
if (type == OPT_GLOBAL)
756
return (unsigned char*) &(global_system_variables.*offset);
757
return (unsigned char*) &(session->variables.*offset);
760
bool sys_var_session_size_t::check(Session *session, set_var *var)
762
return (get_size_t(session, var) ||
763
(check_func && (*check_func)(session, var)));
766
bool sys_var_session_size_t::update(Session *session, set_var *var)
768
size_t tmp= var->save_result.size_t_value;
770
if (tmp > max_system_variables.*offset)
771
tmp= max_system_variables.*offset;
774
tmp= fix_size_t(session, tmp, option_limits);
775
if (var->type == OPT_GLOBAL)
777
/* Lock is needed to make things safe on 32 bit systems */
778
LOCK_global_system_variables.lock();
779
global_system_variables.*offset= tmp;
780
LOCK_global_system_variables.unlock();
783
session->variables.*offset= tmp;
788
void sys_var_session_size_t::set_default(Session *session, sql_var_t type)
790
if (type == OPT_GLOBAL)
793
LOCK_global_system_variables.lock();
794
global_system_variables.*offset=
795
(size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
796
option_limits, ¬_used);
797
LOCK_global_system_variables.unlock();
800
session->variables.*offset= global_system_variables.*offset;
804
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
808
if (type == OPT_GLOBAL)
809
return (unsigned char*) &(global_system_variables.*offset);
810
return (unsigned char*) &(session->variables.*offset);
814
bool sys_var_session_bool::update(Session *session, set_var *var)
816
if (var->type == OPT_GLOBAL)
817
global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
819
session->variables.*offset= (bool) var->save_result.uint32_t_value;
824
void sys_var_session_bool::set_default(Session *session, sql_var_t type)
1318
pthread_mutex_unlock(&LOCK_global_system_variables);
1321
thd->variables.*offset= global_system_variables.*offset;
1325
uchar *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1326
LEX_STRING *base __attribute__((__unused__)))
1328
if (type == OPT_GLOBAL)
1329
return (uchar*) &(global_system_variables.*offset);
1330
return (uchar*) &(thd->variables.*offset);
1334
bool sys_var_thd_bool::update(THD *thd, set_var *var)
1336
if (var->type == OPT_GLOBAL)
1337
global_system_variables.*offset= (bool) var->save_result.ulong_value;
1339
thd->variables.*offset= (bool) var->save_result.ulong_value;
1344
void sys_var_thd_bool::set_default(THD *thd, enum_var_type type)
826
1346
if (type == OPT_GLOBAL)
827
1347
global_system_variables.*offset= (bool) option_limits->def_value;
829
session->variables.*offset= global_system_variables.*offset;
1349
thd->variables.*offset= global_system_variables.*offset;
833
unsigned char *sys_var_session_bool::value_ptr(Session *session,
1353
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1354
LEX_STRING *base __attribute__((__unused__)))
837
1356
if (type == OPT_GLOBAL)
838
return (unsigned char*) &(global_system_variables.*offset);
839
return (unsigned char*) &(session->variables.*offset);
1357
return (uchar*) &(global_system_variables.*offset);
1358
return (uchar*) &(thd->variables.*offset);
843
bool sys_var::check_enum(Session *,
1362
bool sys_var::check_enum(THD *thd __attribute__((__unused__)),
844
1363
set_var *var, const TYPELIB *enum_names)
846
1365
char buff[STRING_BUFFER_USUAL_SIZE];
982
1566
tmp= new Item_null();
983
1567
tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
985
LOCK_global_system_variables.unlock();
1569
pthread_mutex_unlock(&LOCK_global_system_variables);
989
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
1573
my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
995
bool sys_var_session_enum::update(Session *session, set_var *var)
1579
bool sys_var_thd_enum::update(THD *thd, set_var *var)
997
1581
if (var->type == OPT_GLOBAL)
998
global_system_variables.*offset= var->save_result.uint32_t_value;
1582
global_system_variables.*offset= var->save_result.ulong_value;
1000
session->variables.*offset= var->save_result.uint32_t_value;
1584
thd->variables.*offset= var->save_result.ulong_value;
1005
void sys_var_session_enum::set_default(Session *session, sql_var_t type)
1589
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
1007
1591
if (type == OPT_GLOBAL)
1008
global_system_variables.*offset= (uint32_t) option_limits->def_value;
1592
global_system_variables.*offset= (ulong) option_limits->def_value;
1010
session->variables.*offset= global_system_variables.*offset;
1594
thd->variables.*offset= global_system_variables.*offset;
1014
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1598
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1599
LEX_STRING *base __attribute__((__unused__)))
1018
uint32_t tmp= ((type == OPT_GLOBAL) ?
1601
ulong tmp= ((type == OPT_GLOBAL) ?
1019
1602
global_system_variables.*offset :
1020
session->variables.*offset);
1021
return (unsigned char*) enum_names->type_names[tmp];
1024
bool sys_var_session_bit::check(Session *session, set_var *var)
1026
return (check_enum(session, var, &bool_typelib) ||
1027
(check_func && (*check_func)(session, var)));
1030
bool sys_var_session_bit::update(Session *session, set_var *var)
1032
int res= (*update_func)(session, var);
1603
thd->variables.*offset);
1604
return (uchar*) enum_names->type_names[tmp];
1607
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1609
return (check_enum(thd, var, &bool_typelib) ||
1610
(check_func && (*check_func)(thd, var)));
1613
bool sys_var_thd_bit::update(THD *thd, set_var *var)
1615
int res= (*update_func)(thd, var);
1037
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t,
1620
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1621
enum_var_type type __attribute__((__unused__)),
1622
LEX_STRING *base __attribute__((__unused__)))
1041
1625
If reverse is 0 (default) return 1 if bit is set.
1042
1626
If reverse is 1, return 0 if bit is set
1044
session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1628
thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
1045
1629
!reverse : reverse);
1046
return (unsigned char*) &session->sys_var_tmp.bool_value;
1630
return (uchar*) &thd->sys_var_tmp.bool_value;
1634
/** Update a date_time format variable based on given value. */
1636
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
1637
DATE_TIME_FORMAT *new_value)
1639
DATE_TIME_FORMAT *old;
1641
if (type == OPT_GLOBAL)
1643
pthread_mutex_lock(&LOCK_global_system_variables);
1644
old= (global_system_variables.*offset);
1645
(global_system_variables.*offset)= new_value;
1646
pthread_mutex_unlock(&LOCK_global_system_variables);
1650
old= (thd->variables.*offset);
1651
(thd->variables.*offset)= new_value;
1653
my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1658
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
1660
DATE_TIME_FORMAT *new_value;
1661
/* We must make a copy of the last value to get it into normal memory */
1662
new_value= date_time_format_copy((THD*) 0,
1663
var->save_result.date_time_format);
1665
return 1; // Out of memory
1666
update2(thd, var->type, new_value); // Can't fail
1671
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
1673
char buff[STRING_BUFFER_USUAL_SIZE];
1674
String str(buff,sizeof(buff), system_charset_info), *res;
1675
DATE_TIME_FORMAT *format;
1677
if (!(res=var->value->val_str(&str)))
1678
res= &my_empty_string;
1680
if (!(format= date_time_format_make(date_time_type,
1681
res->ptr(), res->length())))
1683
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1688
We must copy result to thread space to not get a memory leak if
1691
var->save_result.date_time_format= date_time_format_copy(thd, format);
1692
my_free((char*) format, MYF(0));
1693
return var->save_result.date_time_format == 0;
1697
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
1699
DATE_TIME_FORMAT *res= 0;
1701
if (type == OPT_GLOBAL)
1704
if ((format= opt_date_time_formats[date_time_type]))
1705
res= date_time_format_make(date_time_type, format, strlen(format));
1709
/* Make copy with malloc */
1710
res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
1713
if (res) // Should always be true
1714
update2(thd, type, res);
1718
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1719
LEX_STRING *base __attribute__((__unused__)))
1721
if (type == OPT_GLOBAL)
1725
We do a copy here just to be sure things will work even if someone
1726
is modifying the original string while the copy is accessed
1727
(Can't happen now in SQL SHOW, but this is a good safety for the future)
1729
res= thd->strmake((global_system_variables.*offset)->format.str,
1730
(global_system_variables.*offset)->format.length);
1731
return (uchar*) res;
1733
return (uchar*) (thd->variables.*offset)->format.str;
1090
bool sys_var_collation_sv::update(Session *session, set_var *var)
1806
bool sys_var_character_set::check(THD *thd __attribute__((__unused__)),
1811
if (var->value->result_type() == STRING_RESULT)
1813
char buff[STRING_BUFFER_USUAL_SIZE];
1814
String str(buff,sizeof(buff), system_charset_info), *res;
1815
if (!(res=var->value->val_str(&str)))
1819
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1824
else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
1825
!(tmp=get_old_charset_by_name(res->c_ptr())))
1827
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1833
if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1836
int10_to_str((int) var->value->val_int(), buf, -10);
1837
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf);
1841
var->save_result.charset= tmp; // Save for update
1846
bool sys_var_character_set::update(THD *thd, set_var *var)
1848
ci_ptr(thd,var->type)[0]= var->save_result.charset;
1849
thd->update_charset();
1854
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1855
LEX_STRING *base __attribute__((__unused__)))
1857
CHARSET_INFO *cs= ci_ptr(thd,type)[0];
1858
return cs ? (uchar*) cs->csname : (uchar*) NULL;
1862
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
1864
if (type == OPT_GLOBAL)
1865
global_system_variables.*offset= *global_default;
1868
thd->variables.*offset= global_system_variables.*offset;
1869
thd->update_charset();
1872
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1874
if (type == OPT_GLOBAL)
1875
return &(global_system_variables.*offset);
1877
return &(thd->variables.*offset);
1881
bool sys_var_character_set_client::check(THD *thd, set_var *var)
1883
if (sys_var_character_set_sv::check(thd, var))
1885
/* Currently, UCS-2 cannot be used as a client character set */
1886
if (var->save_result.charset->mbminlen > 1)
1888
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name,
1889
var->save_result.charset->csname);
1896
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1899
if (type == OPT_GLOBAL)
1900
return &global_system_variables.collation_database;
1902
return &thd->variables.collation_database;
1906
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
1908
if (type == OPT_GLOBAL)
1909
global_system_variables.collation_database= default_charset_info;
1912
thd->variables.collation_database= thd->db_charset;
1913
thd->update_charset();
1918
bool sys_var_collation_sv::update(THD *thd, set_var *var)
1092
1920
if (var->type == OPT_GLOBAL)
1093
1921
global_system_variables.*offset= var->save_result.charset;
1096
session->variables.*offset= var->save_result.charset;
1924
thd->variables.*offset= var->save_result.charset;
1925
thd->update_charset();
1102
void sys_var_collation_sv::set_default(Session *session, sql_var_t type)
1931
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
1104
1933
if (type == OPT_GLOBAL)
1105
1934
global_system_variables.*offset= *global_default;
1108
session->variables.*offset= global_system_variables.*offset;
1113
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1117
const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1118
global_system_variables.*offset :
1119
session->variables.*offset);
1120
return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1937
thd->variables.*offset= global_system_variables.*offset;
1938
thd->update_charset();
1943
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1944
LEX_STRING *base __attribute__((__unused__)))
1946
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1947
global_system_variables.*offset : thd->variables.*offset);
1948
return cs ? (uchar*) cs->name : (uchar*) "NULL";
1952
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1954
static KEY_CACHE zero_key_cache;
1956
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
1958
safe_mutex_assert_owner(&LOCK_global_system_variables);
1959
if (!cache_name || ! cache_name->length)
1960
cache_name= &default_key_cache_base;
1961
return ((KEY_CACHE*) find_named(&key_caches,
1962
cache_name->str, cache_name->length, 0));
1966
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((__unused__)),
1967
enum_var_type type __attribute__((__unused__)),
1968
LEX_STRING *base __attribute__((__unused__)))
1970
KEY_CACHE *key_cache= get_key_cache(base);
1972
key_cache= &zero_key_cache;
1973
return (uchar*) key_cache + offset ;
1977
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1979
uint64_t tmp= var->save_result.uint64_t_value;
1980
LEX_STRING *base_name= &var->base;
1981
KEY_CACHE *key_cache;
1984
/* If no basename, assume it's for the key cache named 'default' */
1985
if (!base_name->length)
1986
base_name= &default_key_cache_base;
1988
pthread_mutex_lock(&LOCK_global_system_variables);
1989
key_cache= get_key_cache(base_name);
1993
/* Key cache didn't exists */
1994
if (!tmp) // Tried to delete cache
1995
goto end; // Ok, nothing to do
1996
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
2004
Abort if some other thread is changing the key cache
2005
TODO: This should be changed so that we wait until the previous
2006
assignment is done and then do the new assign
2008
if (key_cache->in_init)
2011
if (!tmp) // Zero size means delete
2013
if (key_cache == dflt_key_cache)
2015
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2016
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
2017
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
2018
goto end; // Ignore default key cache
2021
if (key_cache->key_cache_inited) // If initied
2024
Move tables using this key cache to the default key cache
2025
and clear the old key cache.
2028
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
2029
base_name->length, &list);
2030
key_cache->in_init= 1;
2031
pthread_mutex_unlock(&LOCK_global_system_variables);
2032
error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
2033
pthread_mutex_lock(&LOCK_global_system_variables);
2034
key_cache->in_init= 0;
2037
We don't delete the key cache as some running threads my still be
2038
in the key cache code with a pointer to the deleted (empty) key cache
2043
key_cache->param_buff_size=
2044
(uint64_t) fix_unsigned(thd, tmp, option_limits);
2046
/* If key cache didn't existed initialize it, else resize it */
2047
key_cache->in_init= 1;
2048
pthread_mutex_unlock(&LOCK_global_system_variables);
2050
if (!key_cache->key_cache_inited)
2051
error= (bool) (ha_init_key_cache("", key_cache));
2053
error= (bool)(ha_resize_key_cache(key_cache));
2055
pthread_mutex_lock(&LOCK_global_system_variables);
2056
key_cache->in_init= 0;
2059
pthread_mutex_unlock(&LOCK_global_system_variables);
2066
Abort if some other thread is changing the key cache.
2067
This should be changed so that we wait until the previous
2068
assignment is done and then do the new assign
2070
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
2072
ulong tmp= (ulong) var->value->val_int();
2073
LEX_STRING *base_name= &var->base;
2076
if (!base_name->length)
2077
base_name= &default_key_cache_base;
2079
pthread_mutex_lock(&LOCK_global_system_variables);
2080
KEY_CACHE *key_cache= get_key_cache(base_name);
2082
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
2083
base_name->length)))
2090
Abort if some other thread is changing the key cache
2091
TODO: This should be changed so that we wait until the previous
2092
assignment is done and then do the new assign
2094
if (key_cache->in_init)
2097
*((ulong*) (((char*) key_cache) + offset))=
2098
(ulong) fix_unsigned(thd, tmp, option_limits);
2101
Don't create a new key cache if it didn't exist
2102
(key_caches are created only when the user sets block_size)
2104
key_cache->in_init= 1;
2106
pthread_mutex_unlock(&LOCK_global_system_variables);
2108
error= (bool) (ha_resize_key_cache(key_cache));
2110
pthread_mutex_lock(&LOCK_global_system_variables);
2111
key_cache->in_init= 0;
2114
pthread_mutex_unlock(&LOCK_global_system_variables);
2119
bool sys_var_log_state::update(THD *thd, set_var *var)
2122
pthread_mutex_lock(&LOCK_global_system_variables);
2123
if (!var->save_result.ulong_value)
2125
logger.deactivate_log_handler(thd, log_type);
2129
res= logger.activate_log_handler(thd, log_type);
2130
pthread_mutex_unlock(&LOCK_global_system_variables);
2134
void sys_var_log_state::set_default(THD *thd,
2135
enum_var_type type __attribute__((__unused__)))
2137
pthread_mutex_lock(&LOCK_global_system_variables);
2138
logger.deactivate_log_handler(thd, log_type);
2139
pthread_mutex_unlock(&LOCK_global_system_variables);
2143
static int sys_check_log_path(THD *thd __attribute__((__unused__)),
2146
char path[FN_REFLEN], buff[FN_REFLEN];
2148
String str(buff, sizeof(buff), system_charset_info), *res;
2149
const char *log_file_str;
2152
if (!(res= var->value->val_str(&str)))
2155
log_file_str= res->c_ptr();
2156
bzero(&f_stat, sizeof(struct stat));
2158
path_length= unpack_filename(path, log_file_str);
2162
/* File name is empty. */
2167
if (!stat(path, &f_stat))
2170
A file system object exists. Check if argument is a file and we have
2174
if (!MY_S_ISREG(f_stat.st_mode) ||
2175
!(f_stat.st_mode & MY_S_IWRITE))
2181
/* Get dirname of the file path. */
2182
(void) dirname_part(path, log_file_str, &path_length);
2184
/* Dirname is empty if file path is relative. */
2189
Check if directory exists and we have permission to create file and
2192
if (my_access(path, (F_OK|W_OK)))
2198
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name,
2199
res ? log_file_str : "NULL");
2204
bool update_sys_var_str_path(THD *thd __attribute__((__unused__)),
2205
sys_var_str *var_str,
2206
set_var *var, const char *log_ext,
2207
bool log_state, uint log_type)
2209
MYSQL_QUERY_LOG *file_log;
2210
char buff[FN_REFLEN];
2211
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2213
uint str_length= (var ? var->value->str_value.length() : 0);
2216
case QUERY_LOG_SLOW:
2217
file_log= logger.get_slow_log_file_handler();
2219
case QUERY_LOG_GENERAL:
2220
file_log= logger.get_log_file_handler();
2223
assert(0); // Impossible
2228
old_value= make_default_log_name(buff, log_ext);
2229
str_length= strlen(old_value);
2231
if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
2237
pthread_mutex_lock(&LOCK_global_system_variables);
2238
logger.lock_exclusive();
2240
if (file_log && log_state)
2242
old_value= var_str->value;
2243
var_str->value= res;
2244
var_str->value_length= str_length;
2245
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
2246
if (file_log && log_state)
2249
case QUERY_LOG_SLOW:
2250
file_log->open_slow_log(sys_var_slow_log_path.value);
2252
case QUERY_LOG_GENERAL:
2253
file_log->open_query_log(sys_var_general_log_path.value);
2261
pthread_mutex_unlock(&LOCK_global_system_variables);
2268
static bool sys_update_general_log_path(THD *thd, set_var * var)
2270
return update_sys_var_str_path(thd, &sys_var_general_log_path,
2271
var, ".log", opt_log, QUERY_LOG_GENERAL);
2275
static void sys_default_general_log_path(THD *thd,
2276
enum_var_type type __attribute__((__unused__)))
2278
(void) update_sys_var_str_path(thd, &sys_var_general_log_path,
2279
0, ".log", opt_log, QUERY_LOG_GENERAL);
2283
static bool sys_update_slow_log_path(THD *thd, set_var * var)
2285
return update_sys_var_str_path(thd, &sys_var_slow_log_path,
2286
var, "-slow.log", opt_slow_log,
2291
static void sys_default_slow_log_path(THD *thd,
2292
enum_var_type type __attribute__((__unused__)))
2294
(void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
2295
0, "-slow.log", opt_slow_log,
2300
bool sys_var_log_output::update(THD *thd __attribute__((__unused__)),
2303
pthread_mutex_lock(&LOCK_global_system_variables);
2304
logger.lock_exclusive();
2305
logger.init_slow_log(var->save_result.ulong_value);
2306
logger.init_general_log(var->save_result.ulong_value);
2307
*value= var->save_result.ulong_value;
2309
pthread_mutex_unlock(&LOCK_global_system_variables);
2314
void sys_var_log_output::set_default(THD *thd __attribute__((__unused__)),
2315
enum_var_type type __attribute__((__unused__)))
2317
pthread_mutex_lock(&LOCK_global_system_variables);
2318
logger.lock_exclusive();
2319
logger.init_slow_log(LOG_FILE);
2320
logger.init_general_log(LOG_FILE);
2323
pthread_mutex_unlock(&LOCK_global_system_variables);
2327
uchar *sys_var_log_output::value_ptr(THD *thd,
2328
enum_var_type type __attribute__((__unused__)),
2329
LEX_STRING *base __attribute__((__unused__)))
2332
String tmp(buff, sizeof(buff), &my_charset_latin1);
2337
for (uint i= 0; val; val>>= 1, i++)
2341
tmp.append(log_output_typelib.type_names[i],
2342
log_output_typelib.type_lengths[i]);
2347
if ((length= tmp.length()))
2349
return (uchar*) thd->strmake(tmp.ptr(), length);
2353
/*****************************************************************************
2354
Functions to handle SET NAMES and SET CHARACTER SET
2355
*****************************************************************************/
2357
int set_var_collation_client::check(THD *thd __attribute__((__unused__)))
2359
/* Currently, UCS-2 cannot be used as a client character set */
2360
if (character_set_client->mbminlen > 1)
2362
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
2363
character_set_client->csname);
2369
int set_var_collation_client::update(THD *thd)
2371
thd->variables.character_set_client= character_set_client;
2372
thd->variables.character_set_results= character_set_results;
2373
thd->variables.collation_connection= collation_connection;
2374
thd->update_charset();
2375
thd->protocol_text.init(thd);
1123
2379
/****************************************************************************/
1125
bool sys_var_timestamp::update(Session *session, set_var *var)
2381
bool sys_var_timestamp::update(THD *thd, set_var *var)
1127
session->set_time((time_t) var->save_result.uint64_t_value);
2383
thd->set_time((time_t) var->save_result.uint64_t_value);
1132
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1134
session->user_time=0;
1138
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
1141
session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
1142
return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1146
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1148
session->first_successful_insert_id_in_prev_stmt=
2388
void sys_var_timestamp::set_default(THD *thd,
2389
enum_var_type type __attribute__((__unused__)))
2395
uchar *sys_var_timestamp::value_ptr(THD *thd,
2396
enum_var_type type __attribute__((__unused__)),
2397
LEX_STRING *base __attribute__((__unused__)))
2399
thd->sys_var_tmp.long_value= (long) thd->start_time;
2400
return (uchar*) &thd->sys_var_tmp.long_value;
2404
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2406
thd->first_successful_insert_id_in_prev_stmt=
1149
2407
var->save_result.uint64_t_value;
1154
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
2412
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2413
enum_var_type type __attribute__((__unused__)),
2414
LEX_STRING *base __attribute__((__unused__)))
1159
2417
this tmp var makes it robust againt change of type of
1160
2418
read_first_successful_insert_id_in_prev_stmt().
1162
session->sys_var_tmp.uint64_t_value=
1163
session->read_first_successful_insert_id_in_prev_stmt();
1164
return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1168
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2420
thd->sys_var_tmp.uint64_t_value=
2421
thd->read_first_successful_insert_id_in_prev_stmt();
2422
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2426
bool sys_var_insert_id::update(THD *thd, set_var *var)
2428
thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2433
uchar *sys_var_insert_id::value_ptr(THD *thd,
2434
enum_var_type type __attribute__((__unused__)),
2435
LEX_STRING *base __attribute__((__unused__)))
2437
thd->sys_var_tmp.uint64_t_value=
2438
thd->auto_inc_intervals_forced.minimum();
2439
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2443
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2445
thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2449
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2451
thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2456
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
1170
2458
char buff[MAX_TIME_ZONE_NAME_LENGTH];
1171
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2459
String str(buff, sizeof(buff), &my_charset_latin1);
1172
2460
String *res= var->value->val_str(&str);
1174
if (!(var->save_result.time_zone= my_tz_find(session, res)))
2462
if (!(var->save_result.time_zone= my_tz_find(thd, res)))
1176
2464
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
1328
2663
microseconds= (int64_t) (num * 1000000.0 + 0.5);
1329
2664
if (var->type == OPT_GLOBAL)
1331
LOCK_global_system_variables.lock();
2666
pthread_mutex_lock(&LOCK_global_system_variables);
1332
2667
(global_system_variables.*offset)= microseconds;
1333
LOCK_global_system_variables.unlock();
2668
pthread_mutex_unlock(&LOCK_global_system_variables);
1336
session->variables.*offset= microseconds;
2671
thd->variables.*offset= microseconds;
1341
void sys_var_microseconds::set_default(Session *session, sql_var_t type)
2676
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
1343
2678
int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1344
2679
if (type == OPT_GLOBAL)
1346
LOCK_global_system_variables.lock();
2681
pthread_mutex_lock(&LOCK_global_system_variables);
1347
2682
global_system_variables.*offset= microseconds;
1348
LOCK_global_system_variables.unlock();
2683
pthread_mutex_unlock(&LOCK_global_system_variables);
1351
session->variables.*offset= microseconds;
2686
thd->variables.*offset= microseconds;
2690
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2691
LEX_STRING *base __attribute__((__unused__)))
2693
thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2694
global_system_variables.*offset :
2695
thd->variables.*offset) / 1000000.0;
2696
return (uchar*) &thd->tmp_double_value;
1355
Functions to update session->options bits
2701
Functions to update thd->options bits
1358
static bool set_option_bit(Session *session, set_var *var)
2704
static bool set_option_bit(THD *thd, set_var *var)
1360
sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1361
if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
1362
session->options&= ~sys_var->bit_flag;
2706
sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
2707
if ((var->save_result.ulong_value != 0) == sys_var->reverse)
2708
thd->options&= ~sys_var->bit_flag;
1364
session->options|= sys_var->bit_flag;
2710
thd->options|= sys_var->bit_flag;
1369
static bool set_option_autocommit(Session *session, set_var *var)
2715
static bool set_option_autocommit(THD *thd, set_var *var)
1371
2717
/* The test is negative as the flag we use is NOT autocommit */
1373
uint64_t org_options= session->options;
2719
uint64_t org_options= thd->options;
1375
if (var->save_result.uint32_t_value != 0)
1376
session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2721
if (var->save_result.ulong_value != 0)
2722
thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
1378
session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
2724
thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
1380
if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
2726
if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
1382
2728
if ((org_options & OPTION_NOT_AUTOCOMMIT))
1384
2730
/* We changed to auto_commit mode */
1385
session->options&= ~(uint64_t) (OPTION_BEGIN);
1386
session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1387
TransactionServices &transaction_services= TransactionServices::singleton();
1388
if (transaction_services.commitTransaction(session, true))
2731
thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2732
thd->transaction.all.modified_non_trans_table= false;
2733
thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
1393
session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2739
thd->transaction.all.modified_non_trans_table= false;
2740
thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1399
static int check_pseudo_thread_id(Session *, set_var *var)
2746
static int check_log_update(THD *thd __attribute__((__unused__)),
2747
set_var *var __attribute__((__unused__)))
2752
static bool set_log_update(THD *thd __attribute__((__unused__)),
2753
set_var *var __attribute__((__unused__)))
2756
The update log is not supported anymore since 5.0.
2757
See sql/mysqld.cc/, comments in function init_server_components() for an
2758
explaination of the different warnings we send below
2761
if (opt_sql_bin_update)
2763
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2764
ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
2765
ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
2768
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2769
ER_UPDATE_LOG_DEPRECATED_IGNORED,
2770
ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
2771
set_option_bit(thd, var);
2776
static int check_pseudo_thread_id(THD *thd __attribute__((__unused__)),
1401
2779
var->save_result.uint64_t_value= var->value->val_int();
1405
static unsigned char *get_warning_count(Session *session)
2783
static uchar *get_warning_count(THD *thd)
1407
session->sys_var_tmp.uint32_t_value=
1408
(session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
1409
session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
1410
session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
1411
return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
2785
thd->sys_var_tmp.long_value=
2786
(thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
2787
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] +
2788
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
2789
return (uchar*) &thd->sys_var_tmp.long_value;
1414
static unsigned char *get_error_count(Session *session)
2792
static uchar *get_error_count(THD *thd)
1416
session->sys_var_tmp.uint32_t_value=
1417
session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
1418
return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
2794
thd->sys_var_tmp.long_value=
2795
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
2796
return (uchar*) &thd->sys_var_tmp.long_value;
1868
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
3285
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3286
LEX_STRING *base __attribute__((__unused__)))
1872
unsigned char* result;
1874
plugin::StorageEngine *engine= session->variables.*offset;
1875
if (type == OPT_GLOBAL)
1876
engine= global_system_variables.*offset;
1877
engine_name= engine->getName();
1878
result= (unsigned char *) session->strmake(engine_name.c_str(),
1879
engine_name.size());
3290
LEX_STRING *engine_name;
3291
plugin_ref plugin= thd->variables.*offset;
3292
if (type == OPT_GLOBAL)
3293
plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
3294
hton= plugin_data(plugin, handlerton*);
3295
engine_name= &hton2plugin[hton->slot]->name;
3296
result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
3297
if (type == OPT_GLOBAL)
3298
plugin_unlock(thd, plugin);
1884
void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
3303
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
1886
plugin::StorageEngine *old_value, *new_value, **value;
3305
plugin_ref old_value, new_value, *value;
1887
3306
if (type == OPT_GLOBAL)
1889
3308
value= &(global_system_variables.*offset);
1890
new_value= myisam_engine;
3309
new_value= ha_lock_engine(NULL, myisam_hton);
1894
value= &(session->variables.*offset);
1895
new_value= global_system_variables.*offset;
3313
value= &(thd->variables.*offset);
3314
new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
1897
3316
assert(new_value);
1898
3317
old_value= *value;
1899
3318
*value= new_value;
3319
plugin_unlock(NULL, old_value);
1903
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3323
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
1905
plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
3325
plugin_ref *value= &(global_system_variables.*offset), old_value;
1906
3326
if (var->type != OPT_GLOBAL)
1907
value= &(session->variables.*offset);
3327
value= &(thd->variables.*offset);
1908
3328
old_value= *value;
1909
if (old_value != var->save_result.storage_engine)
1911
*value= var->save_result.storage_engine;
1916
} /* namespace drizzled */
3329
if (old_value != var->save_result.plugin)
3331
*value= my_plugin_lock(NULL, &var->save_result.plugin);
3332
plugin_unlock(NULL, old_value);
3338
sys_var_thd_optimizer_switch::
3339
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
3341
char buff[STRING_BUFFER_USUAL_SIZE*8];
3342
String tmp(buff, sizeof(buff), &my_charset_latin1);
3346
for (uint i= 0; val; val>>= 1, i++)
3350
tmp.append(optimizer_switch_typelib.type_names[i],
3351
optimizer_switch_typelib.type_lengths[i]);
3357
tmp.length(tmp.length() - 1); /* trim the trailing comma */
3359
rep->str= thd->strmake(tmp.ptr(), tmp.length());
3361
rep->length= rep->str ? tmp.length() : 0;
3363
return rep->length != tmp.length();
3367
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3368
LEX_STRING *base __attribute__((__unused__)))
3371
uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3372
thd->variables.*offset);
3373
(void) symbolic_mode_representation(thd, val, &opts);
3374
return (uchar *) opts.str;
3378
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
3380
if (type == OPT_GLOBAL)
3381
global_system_variables.*offset= 0;
3383
thd->variables.*offset= global_system_variables.*offset;
3387
/****************************************************************************
3389
****************************************************************************/
3391
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3394
I_List_iterator<NAMED_LIST> it(*list);
3395
NAMED_LIST *element;
3396
while ((element= it++))
3398
if (element->cmp(name, length))
3402
return element->data;
3409
void delete_elements(I_List<NAMED_LIST> *list,
3410
void (*free_element)(const char *name, uchar*))
3412
NAMED_LIST *element;
3413
while ((element= list->get()))
3415
(*free_element)(element->name, element->data);
3422
/* Key cache functions */
3424
static KEY_CACHE *create_key_cache(const char *name, uint length)
3426
KEY_CACHE *key_cache;
3428
if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3429
MYF(MY_ZEROFILL | MY_WME))))
3431
if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3433
my_free((char*) key_cache, MYF(0));
3439
Set default values for a key cache
3440
The values in dflt_key_cache_var is set by my_getopt() at startup
3442
We don't set 'buff_size' as this is used to enable the key cache
3444
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
3445
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
3446
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
3453
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3455
LEX_STRING key_cache_name;
3456
KEY_CACHE *key_cache;
3458
key_cache_name.str= (char *) name;
3459
key_cache_name.length= length;
3460
pthread_mutex_lock(&LOCK_global_system_variables);
3461
if (!(key_cache= get_key_cache(&key_cache_name)))
3462
key_cache= create_key_cache(name, length);
3463
pthread_mutex_unlock(&LOCK_global_system_variables);
3468
void free_key_cache(const char *name __attribute__((__unused__)),
3469
KEY_CACHE *key_cache)
3471
ha_end_key_cache(key_cache);
3472
my_free((char*) key_cache, MYF(0));
3476
bool process_key_caches(process_key_cache_t func)
3478
I_List_iterator<NAMED_LIST> it(key_caches);
3479
NAMED_LIST *element;
3481
while ((element= it++))
3483
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3484
func(element->name, key_cache);
3490
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
3494
/* Prevent self dead-lock */
3495
if (thd->locked_tables || thd->active_transaction())
3497
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3501
if (thd->global_read_lock)
3504
This connection already holds the global read lock.
3505
This can be the case with:
3506
- FLUSH TABLES WITH READ LOCK
3507
- SET GLOBAL READ_ONLY = 1
3509
result= sys_var_bool_ptr::update(thd, var);
3514
Perform a 'FLUSH TABLES WITH READ LOCK'.
3515
This is a 3 step process:
3516
- [1] lock_global_read_lock()
3517
- [2] close_cached_tables()
3518
- [3] make_global_read_lock_block_commit()
3519
[1] prevents new connections from obtaining tables locked for write.
3520
[2] waits until all existing connections close their tables.
3521
[3] prevents transactions from being committed.
3524
if (lock_global_read_lock(thd))
3528
This call will be blocked by any connection holding a READ or WRITE lock.
3529
Ideally, we want to wait only for pending WRITE locks, but since:
3530
con 1> LOCK TABLE T FOR READ;
3531
con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3532
con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3533
can cause to wait on a read lock, it's required for the client application
3534
to unlock everything, and acceptable for the server to wait on all locks.
3536
if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
3537
goto end_with_read_lock;
3539
if ((result= make_global_read_lock_block_commit(thd)) == true)
3540
goto end_with_read_lock;
3542
/* Change the opt_readonly system variable, safe because the lock is held */
3543
result= sys_var_bool_ptr::update(thd, var);
3546
/* Release the lock */
3547
unlock_global_read_lock(thd);
3551
/****************************************************************************
3553
****************************************************************************/
3555
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3556
template class List<set_var_base>;
3557
template class List_iterator_fast<set_var_base>;
3558
template class I_List_iterator<NAMED_LIST>;