47
#include "drizzled/my_getopt.h"
48
#include <plugin/myisam/myisam.h>
49
#include <drizzled/error.h>
50
#include <drizzled/gettext.h>
51
#include <drizzled/tztime.h>
52
#include <drizzled/data_home.h>
53
#include <drizzled/set_var.h>
54
#include <drizzled/session.h>
55
#include <drizzled/sql_base.h>
56
#include <drizzled/lock.h>
57
#include <drizzled/item/uint.h>
58
#include <drizzled/item/null.h>
59
#include <drizzled/item/float.h>
60
#include <drizzled/plugin.h>
61
#include "drizzled/version.h"
62
#include "drizzled/strfunc.h"
63
#include "drizzled/internal/m_string.h"
64
#include "drizzled/pthread_globals.h"
65
#include "drizzled/charset.h"
71
using namespace drizzled;
73
extern plugin::StorageEngine *myisam_engine;
75
extern struct my_option my_long_options[];
76
extern const CHARSET_INFO *character_set_filesystem;
77
extern size_t my_thread_stack_size;
79
class sys_var_pluginvar;
50
#ifdef USE_PRAGMA_IMPLEMENTATION
51
#pragma implementation // gcc: Class implementation
54
#include "mysql_priv.h"
57
#include <mysys/my_getopt.h>
58
#include <mysys/thr_alarm.h>
59
#include <storage/myisam/myisam.h>
60
#include <drizzled/drizzled_error_messages.h>
62
extern CHARSET_INFO *character_set_filesystem;
80
65
static DYNAMIC_ARRAY fixed_show_vars;
81
typedef map<string, sys_var *> SystemVariableMap;
82
static SystemVariableMap system_variable_map;
83
extern char *opt_drizzle_tmpdir;
85
extern TYPELIB tx_isolation_typelib;
87
const char *bool_type_names[]= { "OFF", "ON", NULL };
66
static HASH system_variable_hash;
68
const char *bool_type_names[]= { "OFF", "ON", NullS };
88
69
TYPELIB bool_typelib=
90
71
array_elements(bool_type_names)-1, "", bool_type_names, NULL
93
static bool set_option_bit(Session *session, set_var *var);
94
static bool set_option_autocommit(Session *session, set_var *var);
95
static int check_pseudo_thread_id(Session *session, set_var *var);
96
static int check_tx_isolation(Session *session, set_var *var);
97
static void fix_tx_isolation(Session *session, enum_var_type type);
98
static int check_completion_type(Session *session, set_var *var);
99
static void fix_completion_type(Session *session, enum_var_type type);
100
static void fix_max_join_size(Session *session, enum_var_type type);
101
static void fix_session_mem_root(Session *session, enum_var_type type);
102
static void fix_trans_mem_root(Session *session, enum_var_type type);
103
static void fix_server_id(Session *session, enum_var_type type);
104
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
105
static bool get_unsigned32(Session *session, set_var *var);
106
static bool get_unsigned64(Session *session, set_var *var);
107
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
108
const std::string &name, int64_t val);
109
static unsigned char *get_error_count(Session *session);
110
static unsigned char *get_warning_count(Session *session);
111
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);
114
131
Variable definition list
119
136
The variables are linked into the list. A variable is added to
120
137
it in the constructor (see sys_var class for details).
122
140
static sys_var_chain vars = { NULL, NULL };
124
static sys_var_session_uint64_t
142
static sys_var_thd_ulong
125
143
sys_auto_increment_increment(&vars, "auto_increment_increment",
126
&SV::auto_increment_increment);
127
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
128
147
sys_auto_increment_offset(&vars, "auto_increment_offset",
129
&SV::auto_increment_offset);
131
static sys_var_const_str sys_basedir(&vars, "basedir", drizzle_home);
132
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
133
&SV::bulk_insert_buff_size);
134
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
135
&SV::completion_type,
136
check_completion_type,
137
fix_completion_type);
138
static sys_var_collation_sv
139
sys_collation_server(&vars, "collation_server", &SV::collation_server, &default_charset_info);
140
static sys_var_const_str sys_datadir(&vars, "datadir", drizzle_real_data_home);
142
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
143
&SV::join_buff_size);
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);
144
222
static sys_var_key_buffer_size sys_key_buffer_size(&vars, "key_buffer_size");
145
static sys_var_key_cache_uint32_t sys_key_cache_block_size(&vars, "key_cache_block_size",
148
static sys_var_key_cache_uint32_t sys_key_cache_division_limit(&vars, "key_cache_division_limit",
150
param_division_limit));
151
static sys_var_key_cache_uint32_t sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
153
param_age_threshold));
154
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
155
&SV::max_allowed_packet);
156
static sys_var_uint64_t_ptr sys_max_connect_errors(&vars, "max_connect_errors",
157
&max_connect_errors);
158
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
159
&SV::max_error_count);
160
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
161
&SV::max_heap_table_size);
162
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
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",
163
265
&SV::pseudo_thread_id,
164
0, check_pseudo_thread_id);
165
static sys_var_session_ha_rows sys_max_join_size(&vars, "max_join_size",
168
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
169
&SV::max_seeks_for_key);
170
static sys_var_session_uint64_t sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
171
&SV::max_length_for_sort_data);
172
static sys_var_session_size_t sys_max_sort_length(&vars, "max_sort_length",
173
&SV::max_sort_length);
174
static sys_var_uint64_t_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
175
&max_write_lock_count);
176
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
177
&SV::min_examined_row_limit);
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);
179
311
/* these two cannot be static */
180
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
181
&SV::optimizer_prune_level);
182
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
183
&SV::optimizer_search_depth);
185
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
186
&SV::preload_buff_size);
187
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
188
&SV::read_buff_size);
189
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
190
&SV::read_rnd_buff_size);
191
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
192
&SV::div_precincrement);
194
static sys_var_session_size_t sys_range_alloc_block_size(&vars, "range_alloc_block_size",
195
&SV::range_alloc_block_size);
196
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
197
&SV::query_alloc_block_size,
198
false, fix_session_mem_root);
199
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
200
&SV::query_prealloc_size,
201
false, fix_session_mem_root);
202
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
203
static sys_var_session_uint32_t sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
204
&SV::trans_alloc_block_size,
205
false, fix_trans_mem_root);
206
static sys_var_session_uint32_t sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
207
&SV::trans_prealloc_size,
208
false, fix_session_mem_root);
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);
210
359
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
211
360
&opt_secure_file_priv);
212
static sys_var_uint32_t_ptr sys_server_id(&vars, "server_id", &server_id,
215
static sys_var_session_size_t sys_sort_buffer(&vars, "sort_buffer_size",
217
static sys_var_session_optimizer_switch sys_optimizer_switch(&vars, "optimizer_switch",
218
&SV::optimizer_switch);
220
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
221
&SV::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);
222
394
static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone",
223
395
system_time_zone);
224
static sys_var_size_t_ptr sys_table_def_size(&vars, "table_definition_cache",
226
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",
227
399
&table_cache_size);
228
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",
229
401
&table_lock_wait_timeout);
230
static sys_var_session_enum sys_tx_isolation(&vars, "tx_isolation",
232
&tx_isolation_typelib,
235
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
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",
236
412
&SV::tmp_table_size);
237
413
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
238
static sys_var_const_str sys_version(&vars, "version", drizzled::version().c_str());
414
static sys_var_const_str sys_version(&vars, "version", server_version);
240
415
static sys_var_const_str sys_version_comment(&vars, "version_comment",
241
COMPILATION_COMMENT);
416
MYSQL_COMPILATION_COMMENT);
242
417
static sys_var_const_str sys_version_compile_machine(&vars, "version_compile_machine",
244
419
static sys_var_const_str sys_version_compile_os(&vars, "version_compile_os",
246
static sys_var_const_str sys_version_compile_vendor(&vars, "version_compile_vendor",
249
/* Variables that are bits in Session */
251
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
DRIZZLE_TIMESTAMP_TIME);
434
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
436
DRIZZLE_TIMESTAMP_DATE);
437
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
438
&SV::datetime_format,
439
DRIZZLE_TIMESTAMP_DATETIME);
441
/* Variables that are bits in THD */
443
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
252
444
set_option_autocommit,
253
445
OPTION_NOT_AUTOCOMMIT,
255
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,
257
457
OPTION_BIG_SELECTS);
258
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,
260
472
OPTION_WARNINGS);
261
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,
263
475
OPTION_SQL_NOTES);
264
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,
266
485
OPTION_BUFFER_RESULT);
267
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,
269
OPTION_NO_FOREIGN_KEY_CHECKS, 1);
270
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,
272
OPTION_RELAXED_UNIQUE_CHECKS, 1);
495
OPTION_RELAXED_UNIQUE_CHECKS,
497
sys_var::SESSION_VARIABLE_IN_BINLOG);
273
498
/* Local state variables */
275
static sys_var_session_ha_rows sys_select_limit(&vars, "sql_select_limit",
500
static sys_var_thd_ha_rows sys_select_limit(&vars, "sql_select_limit",
276
501
&SV::select_limit);
277
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
502
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
503
sys_var::SESSION_VARIABLE_IN_BINLOG);
278
504
static sys_var_last_insert_id
279
sys_last_insert_id(&vars, "last_insert_id");
505
sys_last_insert_id(&vars, "last_insert_id",
506
sys_var::SESSION_VARIABLE_IN_BINLOG);
281
508
identity is an alias for last_insert_id(), so that we are compatible
284
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);
286
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).
289
525
We want statements referring explicitly to @@session.insert_id to be
290
526
unsafe, because insert_id is modified internally by the slave sql
291
527
thread when NULL values are inserted in an AUTO_INCREMENT column.
391
771
If one doesn't use the SESSION modifier, the isolation level
392
772
is only active for the next command.
394
static void fix_tx_isolation(Session *session, enum_var_type type)
774
static void fix_tx_isolation(THD *thd, enum_var_type type)
396
776
if (type == OPT_SESSION)
397
session->session_tx_isolation= ((enum_tx_isolation)
398
session->variables.tx_isolation);
777
thd->session_tx_isolation= ((enum_tx_isolation)
778
thd->variables.tx_isolation);
401
static void fix_completion_type(Session *, enum_var_type) {}
781
static void fix_completion_type(THD *thd __attribute__((unused)),
782
enum_var_type type __attribute__((unused))) {}
403
static int check_completion_type(Session *, set_var *var)
784
static int check_completion_type(THD *thd __attribute__((unused)),
405
787
int64_t val= var->value->val_int();
406
788
if (val < 0 || val > 2)
409
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), llstr(val, buf));
416
static void fix_session_mem_root(Session *session, enum_var_type type)
418
if (type != OPT_GLOBAL)
419
reset_root_defaults(session->mem_root,
420
session->variables.query_alloc_block_size,
421
session->variables.query_prealloc_size);
425
static void fix_trans_mem_root(Session *session, enum_var_type type)
427
if (type != OPT_GLOBAL)
428
reset_root_defaults(&session->transaction.mem_root,
429
session->variables.trans_alloc_block_size,
430
session->variables.trans_prealloc_size);
434
static void fix_server_id(Session *, enum_var_type)
439
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
440
const std::string &name, int64_t val)
791
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
799
If we are changing the thread variable, we have to copy it to NET too
802
#ifdef HAVE_REPLICATION
803
static void fix_net_read_timeout(THD *thd, enum_var_type type)
805
if (type != OPT_GLOBAL)
806
my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
810
static void fix_net_write_timeout(THD *thd, enum_var_type type)
812
if (type != OPT_GLOBAL)
813
my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
816
static void fix_net_retry_count(THD *thd, enum_var_type type)
818
if (type != OPT_GLOBAL)
819
thd->net.retry_count=thd->variables.net_retry_count;
821
#else /* HAVE_REPLICATION */
822
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
823
enum_var_type type __attribute__((unused)))
825
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
826
enum_var_type type __attribute__((unused)))
828
static void fix_net_retry_count(THD *thd __attribute__((unused)),
829
enum_var_type type __attribute__((unused)))
831
#endif /* HAVE_REPLICATION */
834
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
835
enum_var_type type __attribute__((unused)))
837
switch ((enum_delay_key_write) delay_key_write_options) {
838
case DELAY_KEY_WRITE_NONE:
839
myisam_delay_key_write=0;
841
case DELAY_KEY_WRITE_ON:
842
myisam_delay_key_write=1;
844
case DELAY_KEY_WRITE_ALL:
845
myisam_delay_key_write=1;
846
ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
851
bool sys_var_set::update(THD *thd __attribute__((unused)),
854
*value= var->save_result.ulong_value;
858
uchar *sys_var_set::value_ptr(THD *thd,
859
enum_var_type type __attribute__((unused)),
860
LEX_STRING *base __attribute__((unused)))
863
String tmp(buff, sizeof(buff), &my_charset_latin1);
868
for (uint i= 0; val; val>>= 1, i++)
872
tmp.append(enum_names->type_names[i],
873
enum_names->type_lengths[i]);
878
if ((length= tmp.length()))
880
return (uchar*) thd->strmake(tmp.ptr(), length);
883
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
884
enum_var_type type __attribute__((unused)))
886
slave_exec_mode_options= 0;
887
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
890
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
892
bool rc= sys_var_set::check(thd, var);
894
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
895
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
898
my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
903
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
906
pthread_mutex_lock(&LOCK_global_system_variables);
907
rc= sys_var_set::update(thd, var);
908
pthread_mutex_unlock(&LOCK_global_system_variables);
912
void fix_slave_exec_mode(enum_var_type type __attribute__((unused)))
914
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
915
bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
917
sql_print_error("Ambiguous slave modes combination."
918
" STRICT will be used");
919
bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
921
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
922
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
925
bool sys_var_thd_binlog_format::is_readonly() const
928
Under certain circumstances, the variable is read-only (unchangeable):
930
THD *thd= current_thd;
932
If RBR and open temporary tables, their CREATE TABLE may not be in the
933
binlog, so we can't toggle to SBR in this connection.
934
The test below will also prevent SET GLOBAL, well it was not easy to test
935
if global or not here.
936
And this test will also prevent switching from RBR to RBR (a no-op which
937
should not happen too often).
939
If we don't have row-based replication compiled in, the variable
942
if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
943
thd->temporary_tables)
945
my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
949
if in a stored function/trigger, it's too late to change mode
951
if (thd->in_sub_stmt)
953
my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
956
return sys_var_thd_enum::is_readonly();
960
void fix_binlog_format_after_update(THD *thd,
961
enum_var_type type __attribute__((unused)))
963
thd->reset_current_stmt_binlog_row_based();
967
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
968
enum_var_type type __attribute__((unused)))
970
mysql_bin_log.set_max_size(max_binlog_size);
971
#ifdef HAVE_REPLICATION
972
if (!max_relay_log_size)
973
active_mi->rli.relay_log.set_max_size(max_binlog_size);
978
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
979
enum_var_type type __attribute__((unused)))
981
#ifdef HAVE_REPLICATION
982
active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
983
max_relay_log_size: max_binlog_size);
988
static void fix_max_connections(THD *thd __attribute__((unused)),
989
enum_var_type type __attribute__((unused)))
991
resize_thr_alarm(max_connections + 10);
995
static void fix_thd_mem_root(THD *thd, enum_var_type type)
997
if (type != OPT_GLOBAL)
998
reset_root_defaults(thd->mem_root,
999
thd->variables.query_alloc_block_size,
1000
thd->variables.query_prealloc_size);
1004
static void fix_trans_mem_root(THD *thd, enum_var_type type)
1006
if (type != OPT_GLOBAL)
1007
reset_root_defaults(&thd->transaction.mem_root,
1008
thd->variables.trans_alloc_block_size,
1009
thd->variables.trans_prealloc_size);
1013
static void fix_server_id(THD *thd __attribute__((unused)),
1014
enum_var_type type __attribute__((unused)))
1016
server_id_supplied = 1;
1017
thd->server_id= server_id;
1021
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
1022
const char *name, int64_t val)
449
1031
llstr(val, buf);
451
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1033
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
452
1034
ER_TRUNCATED_WRONG_VALUE,
453
ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
1035
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
458
static uint64_t fix_unsigned(Session *session, uint64_t num,
1040
static uint64_t fix_unsigned(THD *thd, uint64_t num,
459
1041
const struct my_option *option_limits)
461
1043
bool fixed= false;
462
1044
uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
464
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
469
static size_t fix_size_t(Session *session, size_t num,
470
const struct my_option *option_limits)
473
size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
475
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
479
static bool get_unsigned32(Session *session, set_var *var)
481
if (var->value->unsigned_flag)
482
var->save_result.uint32_t_value=
483
static_cast<uint32_t>(var->value->val_int());
486
int64_t v= var->value->val_int();
488
throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
490
var->save_result.uint32_t_value=
491
static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
496
static bool get_unsigned64(Session *, set_var *var)
498
if (var->value->unsigned_flag)
499
var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
502
int64_t v= var->value->val_int();
503
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
508
static bool get_size_t(Session *, set_var *var)
510
if (var->value->unsigned_flag)
511
var->save_result.size_t_value= (size_t) var->value->val_int();
514
ssize_t v= (ssize_t)var->value->val_int();
515
var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
520
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
522
var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
526
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
528
uint32_t tmp= var->save_result.uint32_t_value;
529
pthread_mutex_lock(&LOCK_global_system_variables);
1046
throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
1050
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
1052
if (var->value->unsigned_flag)
1053
var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
1056
int64_t v= var->value->val_int();
1057
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
1064
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
1065
sys_after_update_func after_update_arg)
1066
:sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
1067
&LOCK_global_system_variables, after_update_arg)
1071
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
1073
return get_unsigned(thd, var);
1076
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
1078
uint64_t tmp= var->save_result.uint64_t_value;
1079
pthread_mutex_lock(guard);
530
1080
if (option_limits)
1081
*value= (ulong) fix_unsigned(thd, tmp, option_limits);
532
uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
1084
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1085
/* Avoid overflows on 32 bit systems */
1086
if (tmp > ULONG_MAX)
1089
throw_bounds_warning(thd, true, true, name,
1090
(int64_t) var->save_result.uint64_t_value);
1093
*value= (ulong) tmp;
537
*value= (uint32_t) tmp;
538
pthread_mutex_unlock(&LOCK_global_system_variables);
1096
pthread_mutex_unlock(guard);
543
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
1101
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
546
pthread_mutex_lock(&LOCK_global_system_variables);
547
*value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
548
option_limits, ¬_used);
549
pthread_mutex_unlock(&LOCK_global_system_variables);
1104
pthread_mutex_lock(guard);
1105
*value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
1106
option_limits, ¬_used);
1107
pthread_mutex_unlock(guard);
553
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1111
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
555
1113
uint64_t tmp= var->save_result.uint64_t_value;
556
1114
pthread_mutex_lock(&LOCK_global_system_variables);
557
1115
if (option_limits)
559
uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
1116
*value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
564
1118
*value= (uint64_t) tmp;
565
1119
pthread_mutex_unlock(&LOCK_global_system_variables);
580
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
582
size_t tmp= var->save_result.size_t_value;
583
pthread_mutex_lock(&LOCK_global_system_variables);
585
*value= fix_size_t(session, tmp, option_limits);
588
pthread_mutex_unlock(&LOCK_global_system_variables);
593
void sys_var_size_t_ptr::set_default(Session *, enum_var_type)
596
pthread_mutex_lock(&LOCK_global_system_variables);
597
*value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
598
option_limits, ¬_used);
599
pthread_mutex_unlock(&LOCK_global_system_variables);
602
bool sys_var_bool_ptr::update(Session *, set_var *var)
604
*value= (bool) var->save_result.uint32_t_value;
609
void sys_var_bool_ptr::set_default(Session *, enum_var_type)
1135
bool sys_var_bool_ptr::update(THD *thd __attribute__((unused)), set_var *var)
1137
*value= (bool) var->save_result.ulong_value;
1142
void sys_var_bool_ptr::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
611
1144
*value= (bool) option_limits->def_value;
615
bool sys_var_enum::update(Session *, set_var *var)
1148
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
617
*value= (uint32_t) var->save_result.uint32_t_value;
1150
*value= (uint) var->save_result.ulong_value;
622
unsigned char *sys_var_enum::value_ptr(Session *, enum_var_type, const LEX_STRING *)
624
return (unsigned char*) enum_names->type_names[*value];
628
unsigned char *sys_var_enum_const::value_ptr(Session *, enum_var_type,
631
return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
635
32 bit types for session variables
637
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
639
return (get_unsigned32(session, var) ||
640
(check_func && (*check_func)(session, var)));
643
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
645
uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
1155
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
1156
enum_var_type type __attribute__((unused)),
1157
LEX_STRING *base __attribute__((unused)))
1159
return (uchar*) enum_names->type_names[*value];
1163
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
1164
enum_var_type type __attribute__((unused)),
1165
LEX_STRING *base __attribute__((unused)))
1167
return (uchar*) enum_names->type_names[global_system_variables.*offset];
1170
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1172
return (get_unsigned(thd, var) ||
1173
(check_func && (*check_func)(thd, var)));
1176
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
1178
uint64_t tmp= var->save_result.uint64_t_value;
647
1180
/* Don't use bigger value than given with --maximum-variable-name=.. */
648
if ((uint32_t) tmp > max_system_variables.*offset)
1181
if ((ulong) tmp > max_system_variables.*offset)
650
throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
1183
throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
651
1184
tmp= max_system_variables.*offset;
654
1187
if (option_limits)
655
tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
656
else if (tmp > UINT32_MAX)
1188
tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1189
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1190
else if (tmp > ULONG_MAX)
659
throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
1193
throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
662
1197
if (var->type == OPT_GLOBAL)
663
global_system_variables.*offset= (uint32_t) tmp;
1198
global_system_variables.*offset= (ulong) tmp;
665
session->variables.*offset= (uint32_t) tmp;
1200
thd->variables.*offset= (ulong) tmp;
671
void sys_var_session_uint32_t::set_default(Session *session, enum_var_type type)
1206
void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
673
1208
if (type == OPT_GLOBAL)
676
1211
/* We will not come here if option_limits is not set */
677
1212
global_system_variables.*offset=
678
(uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
1213
(ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
679
1214
option_limits, ¬_used);
682
session->variables.*offset= global_system_variables.*offset;
1217
thd->variables.*offset= global_system_variables.*offset;
686
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
1221
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1222
LEX_STRING *base __attribute__((unused)))
690
1224
if (type == OPT_GLOBAL)
691
return (unsigned char*) &(global_system_variables.*offset);
692
return (unsigned char*) &(session->variables.*offset);
1225
return (uchar*) &(global_system_variables.*offset);
1226
return (uchar*) &(thd->variables.*offset);
696
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1230
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
698
1232
uint64_t tmp= var->save_result.uint64_t_value;
1096
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
1569
my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
1102
bool sys_var_session_enum::update(Session *session, set_var *var)
1575
bool sys_var_thd_enum::update(THD *thd, set_var *var)
1104
1577
if (var->type == OPT_GLOBAL)
1105
global_system_variables.*offset= var->save_result.uint32_t_value;
1578
global_system_variables.*offset= var->save_result.ulong_value;
1107
session->variables.*offset= var->save_result.uint32_t_value;
1580
thd->variables.*offset= var->save_result.ulong_value;
1112
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1585
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
1114
1587
if (type == OPT_GLOBAL)
1115
global_system_variables.*offset= (uint32_t) option_limits->def_value;
1588
global_system_variables.*offset= (ulong) option_limits->def_value;
1117
session->variables.*offset= global_system_variables.*offset;
1590
thd->variables.*offset= global_system_variables.*offset;
1121
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1594
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1595
LEX_STRING *base __attribute__((unused)))
1125
uint32_t tmp= ((type == OPT_GLOBAL) ?
1597
ulong tmp= ((type == OPT_GLOBAL) ?
1126
1598
global_system_variables.*offset :
1127
session->variables.*offset);
1128
return (unsigned char*) enum_names->type_names[tmp];
1131
bool sys_var_session_bit::check(Session *session, set_var *var)
1133
return (check_enum(session, var, &bool_typelib) ||
1134
(check_func && (*check_func)(session, var)));
1137
bool sys_var_session_bit::update(Session *session, set_var *var)
1139
int res= (*update_func)(session, var);
1599
thd->variables.*offset);
1600
return (uchar*) enum_names->type_names[tmp];
1603
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1605
return (check_enum(thd, var, &bool_typelib) ||
1606
(check_func && (*check_func)(thd, var)));
1609
bool sys_var_thd_bit::update(THD *thd, set_var *var)
1611
int res= (*update_func)(thd, var);
1144
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
1616
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1617
enum_var_type type __attribute__((unused)),
1618
LEX_STRING *base __attribute__((unused)))
1148
1621
If reverse is 0 (default) return 1 if bit is set.
1149
1622
If reverse is 1, return 0 if bit is set
1151
session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1624
thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
1152
1625
!reverse : reverse);
1153
return (unsigned char*) &session->sys_var_tmp.bool_value;
1626
return (uchar*) &thd->sys_var_tmp.bool_value;
1630
/** Update a date_time format variable based on given value. */
1632
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
1633
DATE_TIME_FORMAT *new_value)
1635
DATE_TIME_FORMAT *old;
1637
if (type == OPT_GLOBAL)
1639
pthread_mutex_lock(&LOCK_global_system_variables);
1640
old= (global_system_variables.*offset);
1641
(global_system_variables.*offset)= new_value;
1642
pthread_mutex_unlock(&LOCK_global_system_variables);
1646
old= (thd->variables.*offset);
1647
(thd->variables.*offset)= new_value;
1649
my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1654
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
1656
DATE_TIME_FORMAT *new_value;
1657
/* We must make a copy of the last value to get it into normal memory */
1658
new_value= date_time_format_copy((THD*) 0,
1659
var->save_result.date_time_format);
1661
return 1; // Out of memory
1662
update2(thd, var->type, new_value); // Can't fail
1667
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
1669
char buff[STRING_BUFFER_USUAL_SIZE];
1670
String str(buff,sizeof(buff), system_charset_info), *res;
1671
DATE_TIME_FORMAT *format;
1673
if (!(res=var->value->val_str(&str)))
1674
res= &my_empty_string;
1676
if (!(format= date_time_format_make(date_time_type,
1677
res->ptr(), res->length())))
1679
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1684
We must copy result to thread space to not get a memory leak if
1687
var->save_result.date_time_format= date_time_format_copy(thd, format);
1688
my_free((char*) format, MYF(0));
1689
return var->save_result.date_time_format == 0;
1693
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
1695
DATE_TIME_FORMAT *res= 0;
1697
if (type == OPT_GLOBAL)
1700
if ((format= opt_date_time_formats[date_time_type]))
1701
res= date_time_format_make(date_time_type, format, strlen(format));
1705
/* Make copy with malloc */
1706
res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
1709
if (res) // Should always be true
1710
update2(thd, type, res);
1714
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1715
LEX_STRING *base __attribute__((unused)))
1717
if (type == OPT_GLOBAL)
1721
We do a copy here just to be sure things will work even if someone
1722
is modifying the original string while the copy is accessed
1723
(Can't happen now in SQL SHOW, but this is a good safety for the future)
1725
res= thd->strmake((global_system_variables.*offset)->format.str,
1726
(global_system_variables.*offset)->format.length);
1727
return (uchar*) res;
1729
return (uchar*) (thd->variables.*offset)->format.str;
1197
bool sys_var_collation_sv::update(Session *session, set_var *var)
1802
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
1807
if (var->value->result_type() == STRING_RESULT)
1809
char buff[STRING_BUFFER_USUAL_SIZE];
1810
String str(buff,sizeof(buff), system_charset_info), *res;
1811
if (!(res=var->value->val_str(&str)))
1815
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1820
else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
1821
!(tmp=get_old_charset_by_name(res->c_ptr())))
1823
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1829
if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1832
int10_to_str((int) var->value->val_int(), buf, -10);
1833
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf);
1837
var->save_result.charset= tmp; // Save for update
1842
bool sys_var_character_set::update(THD *thd, set_var *var)
1844
ci_ptr(thd,var->type)[0]= var->save_result.charset;
1845
thd->update_charset();
1850
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1851
LEX_STRING *base __attribute__((unused)))
1853
CHARSET_INFO *cs= ci_ptr(thd,type)[0];
1854
return cs ? (uchar*) cs->csname : (uchar*) NULL;
1858
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
1860
if (type == OPT_GLOBAL)
1861
global_system_variables.*offset= *global_default;
1864
thd->variables.*offset= global_system_variables.*offset;
1865
thd->update_charset();
1868
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1870
if (type == OPT_GLOBAL)
1871
return &(global_system_variables.*offset);
1873
return &(thd->variables.*offset);
1877
bool sys_var_character_set_client::check(THD *thd, set_var *var)
1879
if (sys_var_character_set_sv::check(thd, var))
1881
/* Currently, UCS-2 cannot be used as a client character set */
1882
if (var->save_result.charset->mbminlen > 1)
1884
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name,
1885
var->save_result.charset->csname);
1892
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1895
if (type == OPT_GLOBAL)
1896
return &global_system_variables.collation_database;
1898
return &thd->variables.collation_database;
1902
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
1904
if (type == OPT_GLOBAL)
1905
global_system_variables.collation_database= default_charset_info;
1908
thd->variables.collation_database= thd->db_charset;
1909
thd->update_charset();
1914
bool sys_var_collation_sv::update(THD *thd, set_var *var)
1199
1916
if (var->type == OPT_GLOBAL)
1200
1917
global_system_variables.*offset= var->save_result.charset;
1203
session->variables.*offset= var->save_result.charset;
1920
thd->variables.*offset= var->save_result.charset;
1921
thd->update_charset();
1209
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1927
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
1211
1929
if (type == OPT_GLOBAL)
1212
1930
global_system_variables.*offset= *global_default;
1215
session->variables.*offset= global_system_variables.*offset;
1933
thd->variables.*offset= global_system_variables.*offset;
1934
thd->update_charset();
1220
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1224
const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1225
global_system_variables.*offset :
1226
session->variables.*offset);
1227
return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1231
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
1234
return (unsigned char*) dflt_key_cache + offset ;
1240
static int resize_key_cache_with_lock(KEY_CACHE *key_cache)
1242
assert(key_cache->key_cache_inited);
1244
pthread_mutex_lock(&LOCK_global_system_variables);
1245
long tmp_buff_size= (long) key_cache->param_buff_size;
1246
long tmp_block_size= (long) key_cache->param_block_size;
1247
uint32_t division_limit= key_cache->param_division_limit;
1248
uint32_t age_threshold= key_cache->param_age_threshold;
1249
pthread_mutex_unlock(&LOCK_global_system_variables);
1251
return(!resize_key_cache(key_cache, tmp_block_size,
1253
division_limit, age_threshold));
1256
sys_var_key_buffer_size::sys_var_key_buffer_size(sys_var_chain *chain,
1257
const char *name_arg)
1258
: sys_var_key_cache_param(chain, name_arg,
1259
offsetof(KEY_CACHE, param_buff_size))
1262
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1939
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1940
LEX_STRING *base __attribute__((unused)))
1942
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1943
global_system_variables.*offset : thd->variables.*offset);
1944
return cs ? (uchar*) cs->name : (uchar*) "NULL";
1948
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1950
static KEY_CACHE zero_key_cache;
1952
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
1954
safe_mutex_assert_owner(&LOCK_global_system_variables);
1955
if (!cache_name || ! cache_name->length)
1956
cache_name= &default_key_cache_base;
1957
return ((KEY_CACHE*) find_named(&key_caches,
1958
cache_name->str, cache_name->length, 0));
1962
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
1963
enum_var_type type __attribute__((unused)),
1964
LEX_STRING *base __attribute__((unused)))
1966
KEY_CACHE *key_cache= get_key_cache(base);
1968
key_cache= &zero_key_cache;
1969
return (uchar*) key_cache + offset ;
1973
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1264
1975
uint64_t tmp= var->save_result.uint64_t_value;
1976
LEX_STRING *base_name= &var->base;
1265
1977
KEY_CACHE *key_cache;
1980
/* If no basename, assume it's for the key cache named 'default' */
1981
if (!base_name->length)
1982
base_name= &default_key_cache_base;
1268
1984
pthread_mutex_lock(&LOCK_global_system_variables);
1269
key_cache= dflt_key_cache;
1985
key_cache= get_key_cache(base_name);
1989
/* Key cache didn't exists */
1990
if (!tmp) // Tried to delete cache
1991
goto end; // Ok, nothing to do
1992
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
1272
2000
Abort if some other thread is changing the key cache
2115
bool sys_var_log_state::update(THD *thd, set_var *var)
2118
pthread_mutex_lock(&LOCK_global_system_variables);
2119
if (!var->save_result.ulong_value)
2121
logger.deactivate_log_handler(thd, log_type);
2125
res= logger.activate_log_handler(thd, log_type);
2126
pthread_mutex_unlock(&LOCK_global_system_variables);
2130
void sys_var_log_state::set_default(THD *thd,
2131
enum_var_type type __attribute__((unused)))
2133
pthread_mutex_lock(&LOCK_global_system_variables);
2134
logger.deactivate_log_handler(thd, log_type);
2135
pthread_mutex_unlock(&LOCK_global_system_variables);
2139
static int sys_check_log_path(THD *thd __attribute__((unused)),
2142
char path[FN_REFLEN], buff[FN_REFLEN];
2144
String str(buff, sizeof(buff), system_charset_info), *res;
2145
const char *log_file_str;
2148
if (!(res= var->value->val_str(&str)))
2151
log_file_str= res->c_ptr();
2152
memset(&f_stat, 0, sizeof(struct stat));
2154
path_length= unpack_filename(path, log_file_str);
2158
/* File name is empty. */
2163
if (!stat(path, &f_stat))
2166
A file system object exists. Check if argument is a file and we have
2170
if (!S_ISREG(f_stat.st_mode) ||
2171
!(f_stat.st_mode & S_IWRITE))
2177
/* Get dirname of the file path. */
2178
(void) dirname_part(path, log_file_str, &path_length);
2180
/* Dirname is empty if file path is relative. */
2185
Check if directory exists and we have permission to create file and
2188
if (my_access(path, (F_OK|W_OK)))
2194
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name,
2195
res ? log_file_str : "NULL");
2200
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
2201
sys_var_str *var_str,
2202
set_var *var, const char *log_ext,
2203
bool log_state, uint log_type)
2205
MYSQL_QUERY_LOG *file_log;
2206
char buff[FN_REFLEN];
2207
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2209
uint str_length= (var ? var->value->str_value.length() : 0);
2212
case QUERY_LOG_SLOW:
2213
file_log= logger.get_slow_log_file_handler();
2215
case QUERY_LOG_GENERAL:
2216
file_log= logger.get_log_file_handler();
2219
assert(0); // Impossible
2224
old_value= make_default_log_name(buff, log_ext);
2225
str_length= strlen(old_value);
2227
if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
2233
pthread_mutex_lock(&LOCK_global_system_variables);
2234
logger.lock_exclusive();
2236
if (file_log && log_state)
2238
old_value= var_str->value;
2239
var_str->value= res;
2240
var_str->value_length= str_length;
2241
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
2242
if (file_log && log_state)
2245
case QUERY_LOG_SLOW:
2246
file_log->open_slow_log(sys_var_slow_log_path.value);
2248
case QUERY_LOG_GENERAL:
2249
file_log->open_query_log(sys_var_general_log_path.value);
2257
pthread_mutex_unlock(&LOCK_global_system_variables);
2264
static bool sys_update_general_log_path(THD *thd, set_var * var)
2266
return update_sys_var_str_path(thd, &sys_var_general_log_path,
2267
var, ".log", opt_log, QUERY_LOG_GENERAL);
2271
static void sys_default_general_log_path(THD *thd,
2272
enum_var_type type __attribute__((unused)))
2274
(void) update_sys_var_str_path(thd, &sys_var_general_log_path,
2275
0, ".log", opt_log, QUERY_LOG_GENERAL);
2279
static bool sys_update_slow_log_path(THD *thd, set_var * var)
2281
return update_sys_var_str_path(thd, &sys_var_slow_log_path,
2282
var, "-slow.log", opt_slow_log,
2287
static void sys_default_slow_log_path(THD *thd,
2288
enum_var_type type __attribute__((unused)))
2290
(void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
2291
0, "-slow.log", opt_slow_log,
2296
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
2299
pthread_mutex_lock(&LOCK_global_system_variables);
2300
logger.lock_exclusive();
2301
logger.init_slow_log(var->save_result.ulong_value);
2302
logger.init_general_log(var->save_result.ulong_value);
2303
*value= var->save_result.ulong_value;
2305
pthread_mutex_unlock(&LOCK_global_system_variables);
2310
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
2311
enum_var_type type __attribute__((unused)))
2313
pthread_mutex_lock(&LOCK_global_system_variables);
2314
logger.lock_exclusive();
2315
logger.init_slow_log(LOG_FILE);
2316
logger.init_general_log(LOG_FILE);
2319
pthread_mutex_unlock(&LOCK_global_system_variables);
2323
uchar *sys_var_log_output::value_ptr(THD *thd,
2324
enum_var_type type __attribute__((unused)),
2325
LEX_STRING *base __attribute__((unused)))
2328
String tmp(buff, sizeof(buff), &my_charset_latin1);
2333
for (uint i= 0; val; val>>= 1, i++)
2337
tmp.append(log_output_typelib.type_names[i],
2338
log_output_typelib.type_lengths[i]);
2343
if ((length= tmp.length()))
2345
return (uchar*) thd->strmake(tmp.ptr(), length);
2349
/*****************************************************************************
2350
Functions to handle SET NAMES and SET CHARACTER SET
2351
*****************************************************************************/
2353
int set_var_collation_client::check(THD *thd __attribute__((unused)))
2355
/* Currently, UCS-2 cannot be used as a client character set */
2356
if (character_set_client->mbminlen > 1)
2358
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
2359
character_set_client->csname);
2365
int set_var_collation_client::update(THD *thd)
2367
thd->variables.character_set_client= character_set_client;
2368
thd->variables.character_set_results= character_set_results;
2369
thd->variables.collation_connection= collation_connection;
2370
thd->update_charset();
2371
thd->protocol_text.init(thd);
1348
2375
/****************************************************************************/
1350
bool sys_var_timestamp::update(Session *session, set_var *var)
2377
bool sys_var_timestamp::update(THD *thd, set_var *var)
1352
session->set_time((time_t) var->save_result.uint64_t_value);
2379
thd->set_time((time_t) var->save_result.uint64_t_value);
1357
void sys_var_timestamp::set_default(Session *session, enum_var_type)
1359
session->user_time=0;
1363
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
1366
session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
1367
return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1371
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1373
session->first_successful_insert_id_in_prev_stmt=
2384
void sys_var_timestamp::set_default(THD *thd,
2385
enum_var_type type __attribute__((unused)))
2391
uchar *sys_var_timestamp::value_ptr(THD *thd,
2392
enum_var_type type __attribute__((unused)),
2393
LEX_STRING *base __attribute__((unused)))
2395
thd->sys_var_tmp.long_value= (long) thd->start_time;
2396
return (uchar*) &thd->sys_var_tmp.long_value;
2400
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2402
thd->first_successful_insert_id_in_prev_stmt=
1374
2403
var->save_result.uint64_t_value;
1379
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
2408
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2409
enum_var_type type __attribute__((unused)),
2410
LEX_STRING *base __attribute__((unused)))
1384
2413
this tmp var makes it robust againt change of type of
1385
2414
read_first_successful_insert_id_in_prev_stmt().
1387
session->sys_var_tmp.uint64_t_value=
1388
session->read_first_successful_insert_id_in_prev_stmt();
1389
return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1393
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2416
thd->sys_var_tmp.uint64_t_value=
2417
thd->read_first_successful_insert_id_in_prev_stmt();
2418
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2422
bool sys_var_insert_id::update(THD *thd, set_var *var)
2424
thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2429
uchar *sys_var_insert_id::value_ptr(THD *thd,
2430
enum_var_type type __attribute__((unused)),
2431
LEX_STRING *base __attribute__((unused)))
2433
thd->sys_var_tmp.uint64_t_value=
2434
thd->auto_inc_intervals_forced.minimum();
2435
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2439
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2441
thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2445
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2447
thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2452
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
1395
2454
char buff[MAX_TIME_ZONE_NAME_LENGTH];
1396
String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2455
String str(buff, sizeof(buff), &my_charset_latin1);
1397
2456
String *res= var->value->val_str(&str);
1399
if (!(var->save_result.time_zone= my_tz_find(session, res)))
2458
if (!(var->save_result.time_zone= my_tz_find(thd, res)))
1401
2460
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2193
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
3363
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3364
LEX_STRING *base __attribute__((unused)))
2197
3366
LEX_STRING opts;
2198
uint32_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
2199
session->variables.*offset);
2200
(void) symbolic_mode_representation(session, val, &opts);
2201
return (unsigned char *) opts.str;
3367
uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3368
thd->variables.*offset);
3369
(void) symbolic_mode_representation(thd, val, &opts);
3370
return (uchar *) opts.str;
2205
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
3374
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
2207
3376
if (type == OPT_GLOBAL)
2208
3377
global_system_variables.*offset= 0;
2210
session->variables.*offset= global_system_variables.*offset;
3379
thd->variables.*offset= global_system_variables.*offset;
3383
/****************************************************************************
3385
****************************************************************************/
3387
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3390
I_List_iterator<NAMED_LIST> it(*list);
3391
NAMED_LIST *element;
3392
while ((element= it++))
3394
if (element->cmp(name, length))
3398
return element->data;
3405
void delete_elements(I_List<NAMED_LIST> *list,
3406
void (*free_element)(const char *name, uchar*))
3408
NAMED_LIST *element;
3409
while ((element= list->get()))
3411
(*free_element)(element->name, element->data);
3418
/* Key cache functions */
3420
static KEY_CACHE *create_key_cache(const char *name, uint length)
3422
KEY_CACHE *key_cache;
3424
if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3425
MYF(MY_ZEROFILL | MY_WME))))
3427
if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3429
my_free((char*) key_cache, MYF(0));
3435
Set default values for a key cache
3436
The values in dflt_key_cache_var is set by my_getopt() at startup
3438
We don't set 'buff_size' as this is used to enable the key cache
3440
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
3441
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
3442
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
3449
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3451
LEX_STRING key_cache_name;
3452
KEY_CACHE *key_cache;
3454
key_cache_name.str= (char *) name;
3455
key_cache_name.length= length;
3456
pthread_mutex_lock(&LOCK_global_system_variables);
3457
if (!(key_cache= get_key_cache(&key_cache_name)))
3458
key_cache= create_key_cache(name, length);
3459
pthread_mutex_unlock(&LOCK_global_system_variables);
3464
void free_key_cache(const char *name __attribute__((unused)),
3465
KEY_CACHE *key_cache)
3467
ha_end_key_cache(key_cache);
3468
my_free((char*) key_cache, MYF(0));
3472
bool process_key_caches(process_key_cache_t func)
3474
I_List_iterator<NAMED_LIST> it(key_caches);
3475
NAMED_LIST *element;
3477
while ((element= it++))
3479
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3480
func(element->name, key_cache);
3486
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
3490
/* Prevent self dead-lock */
3491
if (thd->locked_tables || thd->active_transaction())
3493
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3497
if (thd->global_read_lock)
3500
This connection already holds the global read lock.
3501
This can be the case with:
3502
- FLUSH TABLES WITH READ LOCK
3503
- SET GLOBAL READ_ONLY = 1
3505
result= sys_var_bool_ptr::update(thd, var);
3510
Perform a 'FLUSH TABLES WITH READ LOCK'.
3511
This is a 3 step process:
3512
- [1] lock_global_read_lock()
3513
- [2] close_cached_tables()
3514
- [3] make_global_read_lock_block_commit()
3515
[1] prevents new connections from obtaining tables locked for write.
3516
[2] waits until all existing connections close their tables.
3517
[3] prevents transactions from being committed.
3520
if (lock_global_read_lock(thd))
3524
This call will be blocked by any connection holding a READ or WRITE lock.
3525
Ideally, we want to wait only for pending WRITE locks, but since:
3526
con 1> LOCK TABLE T FOR READ;
3527
con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3528
con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3529
can cause to wait on a read lock, it's required for the client application
3530
to unlock everything, and acceptable for the server to wait on all locks.
3532
if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
3533
goto end_with_read_lock;
3535
if ((result= make_global_read_lock_block_commit(thd)) == true)
3536
goto end_with_read_lock;
3538
/* Change the opt_readonly system variable, safe because the lock is held */
3539
result= sys_var_bool_ptr::update(thd, var);
3542
/* Release the lock */
3543
unlock_global_read_lock(thd);
3547
/****************************************************************************
3549
****************************************************************************/
3551
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3552
template class List<set_var_base>;
3553
template class List_iterator_fast<set_var_base>;
3554
template class I_List_iterator<NAMED_LIST>;