29
28
- If the variable is thread specific, add it to 'system_variables' struct.
30
29
If not, add it to mysqld.cc and an declaration in 'mysql_priv.h'
31
30
- If the variable should be changed from the command line, add a definition
32
of it in the option structure list in mysqld.cc
31
of it in the my_option structure list in mysqld.cc
33
32
- Don't forget to initialize new fields in global_system_variables and
34
33
max_system_variables!
37
36
Add full support for the variable character_set (for 4.1)
39
When updating myisam_delay_key_write, we should do a 'flush tables'
40
of all MyISAM tables to ensure that they are reopen with the
44
Be careful with var->save_result: sys_var::check() only updates
45
uint64_t_value; so other members of the union are garbage then; to use
46
them you must first assign a value to them (in specific ::check() for
42
#include <drizzled/option.h>
43
#include <drizzled/error.h>
44
#include <drizzled/gettext.h>
45
#include <drizzled/tztime.h>
46
#include <drizzled/data_home.h>
47
#include <drizzled/set_var.h>
48
#include <drizzled/session.h>
49
#include <drizzled/sql_base.h>
50
#include <drizzled/lock.h>
51
#include <drizzled/item/uint.h>
52
#include <drizzled/item/null.h>
53
#include <drizzled/item/float.h>
54
#include <drizzled/item/string.h>
55
#include <drizzled/plugin.h>
56
#include <drizzled/version.h>
57
#include <drizzled/strfunc.h>
58
#include <drizzled/internal/m_string.h>
59
#include <drizzled/pthread_globals.h>
60
#include <drizzled/charset.h>
61
#include <drizzled/transaction_services.h>
62
#include <drizzled/constrained_value.h>
63
#include <drizzled/visibility.h>
64
#include <drizzled/typelib.h>
65
#include <drizzled/plugin/storage_engine.h>
79
extern bool timed_mutexes;
82
extern plugin::StorageEngine *myisam_engine;
83
extern bool timed_mutexes;
85
extern struct option my_long_options[];
86
extern const CHARSET_INFO *character_set_filesystem;
87
extern size_t my_thread_stack_size;
89
typedef map<string, sys_var *> SystemVariableMap;
90
static SystemVariableMap system_variable_map;
91
extern char *opt_drizzle_tmpdir;
93
extern TYPELIB tx_isolation_typelib;
97
static size_t revno= DRIZZLE7_VC_REVNO;
98
static size_t release_id= DRIZZLE7_RELEASE_ID;
101
const char *bool_type_names[]= { "OFF", "ON", NULL };
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;
65
static DYNAMIC_ARRAY fixed_show_vars;
66
static HASH system_variable_hash;
68
const char *bool_type_names[]= { "OFF", "ON", NullS };
102
69
TYPELIB bool_typelib=
104
71
array_elements(bool_type_names)-1, "", bool_type_names, NULL
107
static bool set_option_bit(Session *session, set_var *var);
108
static bool set_option_autocommit(Session *session, set_var *var);
109
static int check_pseudo_thread_id(Session *session, set_var *var);
110
static int check_tx_isolation(Session *session, set_var *var);
111
static void fix_tx_isolation(Session *session, sql_var_t type);
112
static int check_completion_type(Session *session, set_var *var);
113
static void fix_completion_type(Session *session, sql_var_t type);
114
static void fix_max_join_size(Session *session, sql_var_t type);
115
static void fix_session_mem_root(Session *session, sql_var_t type);
116
static void fix_server_id(Session *session, sql_var_t type);
117
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
118
const std::string &name, int64_t val);
119
static unsigned char *get_error_count(Session *session);
120
static unsigned char *get_warning_count(Session *session);
121
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);
124
131
Variable definition list
129
136
The variables are linked into the list. A variable is added to
130
137
it in the constructor (see sys_var class for details).
132
static sys_var_session_uint64_t
133
sys_auto_increment_increment("auto_increment_increment",
134
&drizzle_system_variables::auto_increment_increment);
135
static sys_var_session_uint64_t
136
sys_auto_increment_offset("auto_increment_offset",
137
&drizzle_system_variables::auto_increment_offset);
139
static sys_var_fs_path sys_basedir("basedir", basedir);
140
static sys_var_fs_path sys_pid_file("pid_file", pid_file);
141
static sys_var_fs_path sys_plugin_dir("plugin_dir", plugin_dir);
143
static sys_var_size_t_ptr sys_thread_stack_size("thread_stack",
144
&my_thread_stack_size);
145
static sys_var_constrained_value_readonly<uint32_t> sys_back_log("back_log", back_log);
147
static sys_var_session_uint64_t sys_bulk_insert_buff_size("bulk_insert_buffer_size",
148
&drizzle_system_variables::bulk_insert_buff_size);
149
static sys_var_session_uint32_t sys_completion_type("completion_type",
150
&drizzle_system_variables::completion_type,
151
check_completion_type,
152
fix_completion_type);
153
static sys_var_collation_sv
154
sys_collation_server("collation_server", &drizzle_system_variables::collation_server, &default_charset_info);
155
static sys_var_fs_path sys_datadir("datadir", getDataHome());
157
static sys_var_session_uint64_t sys_join_buffer_size("join_buffer_size",
158
&drizzle_system_variables::join_buff_size);
159
static sys_var_session_uint32_t sys_max_allowed_packet("max_allowed_packet",
160
&drizzle_system_variables::max_allowed_packet);
161
static sys_var_session_uint64_t sys_max_error_count("max_error_count",
162
&drizzle_system_variables::max_error_count);
163
static sys_var_session_uint64_t sys_max_heap_table_size("max_heap_table_size",
164
&drizzle_system_variables::max_heap_table_size);
165
static sys_var_session_uint64_t sys_pseudo_thread_id("pseudo_thread_id",
166
&drizzle_system_variables::pseudo_thread_id,
167
0, check_pseudo_thread_id);
168
static sys_var_session_ha_rows sys_max_join_size("max_join_size",
169
&drizzle_system_variables::max_join_size,
171
static sys_var_session_uint64_t sys_max_seeks_for_key("max_seeks_for_key",
172
&drizzle_system_variables::max_seeks_for_key);
173
static sys_var_session_uint64_t sys_max_length_for_sort_data("max_length_for_sort_data",
174
&drizzle_system_variables::max_length_for_sort_data);
175
static sys_var_session_size_t sys_max_sort_length("max_sort_length",
176
&drizzle_system_variables::max_sort_length);
177
static sys_var_uint64_t_ptr sys_max_write_lock_count("max_write_lock_count",
178
&max_write_lock_count);
179
static sys_var_session_uint64_t sys_min_examined_row_limit("min_examined_row_limit",
180
&drizzle_system_variables::min_examined_row_limit);
140
static sys_var_chain vars = { NULL, NULL };
142
static sys_var_thd_ulong
143
sys_auto_increment_increment(&vars, "auto_increment_increment",
144
&SV::auto_increment_increment, NULL, NULL,
145
sys_var::SESSION_VARIABLE_IN_BINLOG);
146
static sys_var_thd_ulong
147
sys_auto_increment_offset(&vars, "auto_increment_offset",
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
#ifndef TO_BE_DELETED /* Alias for max_join_size */
276
static sys_var_thd_ha_rows sys_sql_max_join_size(&vars, "sql_max_join_size",
280
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
282
fix_max_relay_log_size);
283
static sys_var_thd_ulong sys_max_sort_length(&vars, "max_sort_length",
284
&SV::max_sort_length);
285
static sys_var_max_user_conn sys_max_user_connections(&vars, "max_user_connections");
286
static sys_var_thd_ulong sys_max_tmp_tables(&vars, "max_tmp_tables",
287
&SV::max_tmp_tables);
288
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
289
&max_write_lock_count);
290
static sys_var_thd_ulong sys_min_examined_row_limit(&vars, "min_examined_row_limit",
291
&SV::min_examined_row_limit);
292
static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
293
&myisam_data_pointer_size);
294
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);
295
static sys_var_thd_ulong sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
296
static sys_var_thd_ulong sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
298
static sys_var_thd_enum sys_myisam_stats_method(&vars, "myisam_stats_method",
299
&SV::myisam_stats_method,
300
&myisam_stats_method_typelib,
302
static sys_var_thd_ulong sys_net_buffer_length(&vars, "net_buffer_length",
303
&SV::net_buffer_length);
304
static sys_var_thd_ulong sys_net_read_timeout(&vars, "net_read_timeout",
305
&SV::net_read_timeout,
306
0, fix_net_read_timeout);
307
static sys_var_thd_ulong sys_net_write_timeout(&vars, "net_write_timeout",
308
&SV::net_write_timeout,
309
0, fix_net_write_timeout);
310
static sys_var_thd_ulong sys_net_retry_count(&vars, "net_retry_count",
311
&SV::net_retry_count,
312
0, fix_net_retry_count);
313
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
314
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
315
&global_system_variables.old_mode);
182
316
/* these two cannot be static */
183
static sys_var_session_bool sys_optimizer_prune_level("optimizer_prune_level",
184
&drizzle_system_variables::optimizer_prune_level);
185
static sys_var_session_uint32_t sys_optimizer_search_depth("optimizer_search_depth",
186
&drizzle_system_variables::optimizer_search_depth);
188
static sys_var_session_uint64_t sys_preload_buff_size("preload_buffer_size",
189
&drizzle_system_variables::preload_buff_size);
190
static sys_var_session_uint32_t sys_read_buff_size("read_buffer_size",
191
&drizzle_system_variables::read_buff_size);
192
static sys_var_session_uint32_t sys_read_rnd_buff_size("read_rnd_buffer_size",
193
&drizzle_system_variables::read_rnd_buff_size);
194
static sys_var_session_uint32_t sys_div_precincrement("div_precision_increment",
195
&drizzle_system_variables::div_precincrement);
197
static sys_var_session_size_t sys_range_alloc_block_size("range_alloc_block_size",
198
&drizzle_system_variables::range_alloc_block_size);
200
static sys_var_session_bool sys_replicate_query("replicate_query",
201
&drizzle_system_variables::replicate_query);
203
static sys_var_session_uint32_t sys_query_alloc_block_size("query_alloc_block_size",
204
&drizzle_system_variables::query_alloc_block_size,
205
NULL, fix_session_mem_root);
206
static sys_var_session_uint32_t sys_query_prealloc_size("query_prealloc_size",
207
&drizzle_system_variables::query_prealloc_size,
208
NULL, fix_session_mem_root);
209
static sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
211
static sys_var_fs_path sys_secure_file_priv("secure_file_priv",
214
static sys_var_const_str_ptr sys_scheduler("scheduler",
215
(char**)&opt_scheduler);
217
static sys_var_uint32_t_ptr sys_server_id("server_id", &server_id,
220
static sys_var_session_size_t sys_sort_buffer("sort_buffer_size",
221
&drizzle_system_variables::sortbuff_size);
223
static sys_var_size_t_ptr_readonly sys_transaction_message_threshold("transaction_message_threshold",
224
&transaction_message_threshold);
226
static sys_var_session_storage_engine sys_storage_engine("storage_engine",
227
&drizzle_system_variables::storage_engine);
228
static sys_var_size_t_ptr sys_table_def_size("table_definition_cache",
230
static sys_var_uint64_t_ptr sys_table_cache_size("table_open_cache",
317
sys_var_thd_bool sys_old_alter_table(&vars, "old_alter_table",
318
&SV::old_alter_table);
319
static sys_var_thd_ulong sys_optimizer_prune_level(&vars, "optimizer_prune_level",
320
&SV::optimizer_prune_level);
321
static sys_var_thd_ulong sys_optimizer_search_depth(&vars, "optimizer_search_depth",
322
&SV::optimizer_search_depth);
324
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
325
TYPELIB optimizer_use_mrr_typelib= {
326
array_elements(optimizer_use_mrr_names) - 1, "",
327
optimizer_use_mrr_names, NULL
330
static sys_var_thd_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
331
&SV::optimizer_use_mrr,
332
&optimizer_use_mrr_typelib,
335
static sys_var_thd_ulong sys_preload_buff_size(&vars, "preload_buffer_size",
336
&SV::preload_buff_size);
337
static sys_var_thd_ulong sys_read_buff_size(&vars, "read_buffer_size",
338
&SV::read_buff_size);
339
static sys_var_opt_readonly sys_readonly(&vars, "read_only", &opt_readonly);
340
static sys_var_thd_ulong sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
341
&SV::read_rnd_buff_size);
342
static sys_var_thd_ulong sys_div_precincrement(&vars, "div_precision_increment",
343
&SV::div_precincrement);
344
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
347
static sys_var_thd_ulong sys_range_alloc_block_size(&vars, "range_alloc_block_size",
348
&SV::range_alloc_block_size);
349
static sys_var_thd_ulong sys_query_alloc_block_size(&vars, "query_alloc_block_size",
350
&SV::query_alloc_block_size,
351
0, fix_thd_mem_root);
352
static sys_var_thd_ulong sys_query_prealloc_size(&vars, "query_prealloc_size",
353
&SV::query_prealloc_size,
354
0, fix_thd_mem_root);
355
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
356
static sys_var_thd_ulong sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
357
&SV::trans_alloc_block_size,
358
0, fix_trans_mem_root);
359
static sys_var_thd_ulong sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
360
&SV::trans_prealloc_size,
361
0, fix_trans_mem_root);
363
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
364
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
365
&opt_secure_file_priv);
366
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
367
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
368
&opt_slave_compressed_protocol);
369
#ifdef HAVE_REPLICATION
370
static sys_var_bool_ptr sys_slave_allow_batching(&vars, "slave_allow_batching",
371
&slave_allow_batching);
372
static sys_var_set_slave_mode slave_exec_mode(&vars,
374
&slave_exec_mode_options,
375
&slave_exec_mode_typelib,
378
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
380
static sys_var_thd_ulong sys_sort_buffer(&vars, "sort_buffer_size",
383
sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
384
even though it is written to the binlog, the slave ignores the
385
MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
386
master's (see log_event.cc: Query_log_event::do_apply_event()).
388
static sys_var_thd_optimizer_switch sys_optimizer_switch(&vars, "optimizer_switch",
389
&SV::optimizer_switch);
390
static sys_var_const_str sys_ssl_ca(&vars, "ssl_ca", NULL);
391
static sys_var_const_str sys_ssl_capath(&vars, "ssl_capath", NULL);
392
static sys_var_const_str sys_ssl_cert(&vars, "ssl_cert", NULL);
393
static sys_var_const_str sys_ssl_cipher(&vars, "ssl_cipher", NULL);
394
static sys_var_const_str sys_ssl_key(&vars, "ssl_key", NULL);
396
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
398
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
399
static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone",
401
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
403
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
231
404
&table_cache_size);
232
static sys_var_uint64_t_ptr sys_table_lock_wait_timeout("table_lock_wait_timeout",
405
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
233
406
&table_lock_wait_timeout);
234
static sys_var_session_enum sys_tx_isolation("tx_isolation",
235
&drizzle_system_variables::tx_isolation,
236
&tx_isolation_typelib,
239
static sys_var_session_uint64_t sys_tmp_table_size("tmp_table_size",
240
&drizzle_system_variables::tmp_table_size);
241
static sys_var_bool_ptr sys_timed_mutexes("timed_mutexes", &internal::timed_mutexes);
242
static sys_var_const_str sys_version("version", version().c_str());
244
static sys_var_const_str sys_version_comment("version_comment",
245
COMPILATION_COMMENT);
246
static sys_var_const_str sys_version_compile_machine("version_compile_machine",
248
static sys_var_const_str sys_version_compile_os("version_compile_os",
250
static sys_var_const_str sys_version_compile_vendor("version_compile_vendor",
253
/* Variables that are bits in Session */
255
sys_var_session_bit sys_autocommit("autocommit", 0,
407
static sys_var_long_ptr sys_thread_cache_size(&vars, "thread_cache_size",
409
sys_var_long_ptr sys_thread_pool_size(&vars, "thread_pool_size",
411
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
413
&tx_isolation_typelib,
416
static sys_var_thd_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
417
&SV::tmp_table_size);
418
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
419
static sys_var_const_str sys_version(&vars, "version", server_version);
420
static sys_var_const_str sys_version_comment(&vars, "version_comment",
421
MYSQL_COMPILATION_COMMENT);
422
static sys_var_const_str sys_version_compile_machine(&vars, "version_compile_machine",
424
static sys_var_const_str sys_version_compile_os(&vars, "version_compile_os",
426
static sys_var_thd_ulong sys_net_wait_timeout(&vars, "wait_timeout",
427
&SV::net_wait_timeout);
429
/* Condition pushdown to storage engine */
430
static sys_var_thd_bool
431
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
432
&SV::engine_condition_pushdown);
434
/* Time/date/datetime formats */
436
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
438
MYSQL_TIMESTAMP_TIME);
439
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
441
MYSQL_TIMESTAMP_DATE);
442
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
443
&SV::datetime_format,
444
MYSQL_TIMESTAMP_DATETIME);
446
/* Variables that are bits in THD */
448
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
256
449
set_option_autocommit,
257
450
OPTION_NOT_AUTOCOMMIT,
259
static sys_var_session_bit sys_big_selects("sql_big_selects", 0,
452
static sys_var_thd_bit sys_big_tables(&vars, "big_tables", 0,
455
#ifndef TO_BE_DELETED /* Alias for big_tables */
456
static sys_var_thd_bit sys_sql_big_tables(&vars, "sql_big_tables", 0,
460
static sys_var_thd_bit sys_big_selects(&vars, "sql_big_selects", 0,
261
462
OPTION_BIG_SELECTS);
262
static sys_var_session_bit sys_sql_warnings("sql_warnings", 0,
463
static sys_var_thd_bit sys_log_off(&vars, "sql_log_off",
467
static sys_var_thd_bit sys_log_update(&vars, "sql_log_update",
471
static sys_var_thd_bit sys_log_binlog(&vars, "sql_log_bin",
475
static sys_var_thd_bit sys_sql_warnings(&vars, "sql_warnings", 0,
264
477
OPTION_WARNINGS);
265
static sys_var_session_bit sys_sql_notes("sql_notes", 0,
478
static sys_var_thd_bit sys_sql_notes(&vars, "sql_notes", 0,
267
480
OPTION_SQL_NOTES);
268
static sys_var_session_bit sys_buffer_results("sql_buffer_result", 0,
481
static sys_var_thd_bit sys_auto_is_null(&vars, "sql_auto_is_null", 0,
483
OPTION_AUTO_IS_NULL, 0,
484
sys_var::SESSION_VARIABLE_IN_BINLOG);
485
static sys_var_thd_bit sys_safe_updates(&vars, "sql_safe_updates", 0,
487
OPTION_SAFE_UPDATES);
488
static sys_var_thd_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
270
490
OPTION_BUFFER_RESULT);
271
static sys_var_session_bit sys_foreign_key_checks("foreign_key_checks", 0,
491
static sys_var_thd_bit sys_quote_show_create(&vars, "sql_quote_show_create", 0,
493
OPTION_QUOTE_SHOW_CREATE);
494
static sys_var_thd_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
273
OPTION_NO_FOREIGN_KEY_CHECKS, 1);
274
static sys_var_session_bit sys_unique_checks("unique_checks", 0,
496
OPTION_NO_FOREIGN_KEY_CHECKS,
497
1, sys_var::SESSION_VARIABLE_IN_BINLOG);
498
static sys_var_thd_bit sys_unique_checks(&vars, "unique_checks", 0,
276
OPTION_RELAXED_UNIQUE_CHECKS, 1);
500
OPTION_RELAXED_UNIQUE_CHECKS,
502
sys_var::SESSION_VARIABLE_IN_BINLOG);
277
503
/* Local state variables */
279
static sys_var_session_ha_rows sys_select_limit("sql_select_limit",
280
&drizzle_system_variables::select_limit);
281
static sys_var_timestamp sys_timestamp("timestamp");
505
static sys_var_thd_ha_rows sys_select_limit(&vars, "sql_select_limit",
507
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
508
sys_var::SESSION_VARIABLE_IN_BINLOG);
282
509
static sys_var_last_insert_id
283
sys_last_insert_id("last_insert_id");
510
sys_last_insert_id(&vars, "last_insert_id",
511
sys_var::SESSION_VARIABLE_IN_BINLOG);
285
513
identity is an alias for last_insert_id(), so that we are compatible
288
static sys_var_last_insert_id sys_identity("identity");
516
static sys_var_last_insert_id
517
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
290
static sys_var_session_lc_time_names sys_lc_time_names("lc_time_names");
519
static sys_var_thd_lc_time_names
520
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
523
insert_id should *not* be marked as written to the binlog (i.e., it
524
should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
525
because we want any statement that refers to insert_id explicitly to
526
be unsafe. (By "explicitly", we mean using @@session.insert_id,
527
whereas insert_id is used "implicitly" when NULL value is inserted
528
into an auto_increment column).
293
530
We want statements referring explicitly to @@session.insert_id to be
294
531
unsafe, because insert_id is modified internally by the slave sql
295
532
thread when NULL values are inserted in an AUTO_INCREMENT column.
301
538
statement-based logging mode: t will be different on master and
304
static sys_var_readonly sys_error_count("error_count",
308
static sys_var_readonly sys_warning_count("warning_count",
313
sys_var_session_uint64_t sys_group_concat_max_len("group_concat_max_len",
314
&drizzle_system_variables::group_concat_max_len);
541
static sys_var_insert_id sys_insert_id(&vars, "insert_id");
542
static sys_var_readonly sys_error_count(&vars, "error_count",
546
static sys_var_readonly sys_warning_count(&vars, "warning_count",
551
static sys_var_rand_seed1 sys_rand_seed1(&vars, "rand_seed1",
552
sys_var::SESSION_VARIABLE_IN_BINLOG);
553
static sys_var_rand_seed2 sys_rand_seed2(&vars, "rand_seed2",
554
sys_var::SESSION_VARIABLE_IN_BINLOG);
556
static sys_var_thd_ulong sys_default_week_format(&vars, "default_week_format",
557
&SV::default_week_format);
559
sys_var_thd_ulong sys_group_concat_max_len(&vars, "group_concat_max_len",
560
&SV::group_concat_max_len);
562
sys_var_thd_time_zone sys_time_zone(&vars, "time_zone",
563
sys_var::SESSION_VARIABLE_IN_BINLOG);
316
565
/* Global read-only variable containing hostname */
317
static sys_var_const_string sys_hostname("hostname", getServerHostname());
319
static sys_var_const_str sys_revid("vc_revid", DRIZZLE7_VC_REVID);
320
static sys_var_const_str sys_branch("vc_branch", DRIZZLE7_VC_BRANCH);
321
static sys_var_size_t_ptr_readonly sys_revno("vc_revno", &revno);
322
static sys_var_size_t_ptr_readonly sys_release_id("vc_release_id", &release_id);
324
bool sys_var::check(Session *session, set_var *var)
329
if ((res=(*check_func)(session, var)) < 0)
330
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
566
static sys_var_const_str sys_hostname(&vars, "hostname", glob_hostname);
568
static sys_var_const_str_ptr sys_repl_report_host(&vars, "report_host", &report_host);
569
static sys_var_const_str_ptr sys_repl_report_user(&vars, "report_user", &report_user);
570
static sys_var_const_str_ptr sys_repl_report_password(&vars, "report_password", &report_password);
572
static uchar *slave_get_report_port(THD *thd)
574
thd->sys_var_tmp.long_value= report_port;
575
return (uchar*) &thd->sys_var_tmp.long_value;
578
static sys_var_readonly sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
580
sys_var_thd_bool sys_keep_files_on_create(&vars, "keep_files_on_create",
581
&SV::keep_files_on_create);
582
/* Read only variables */
584
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
585
static sys_var_have_variable sys_have_crypt(&vars, "have_crypt", &have_crypt);
586
static sys_var_have_plugin sys_have_csv(&vars, "have_csv", C_STRING_WITH_LEN("csv"), MYSQL_STORAGE_ENGINE_PLUGIN);
587
static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
588
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
589
/* Global read-only variable describing server license */
590
static sys_var_const_str sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
591
/* Global variables which enable|disable logging */
592
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
594
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
595
static sys_var_log_state sys_var_log(&vars, "log", &opt_log, QUERY_LOG_GENERAL);
596
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
598
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
599
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
600
&opt_slow_log, QUERY_LOG_SLOW);
601
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
602
sys_update_general_log_path,
603
sys_default_general_log_path,
605
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
606
sys_update_slow_log_path,
607
sys_default_slow_log_path,
609
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
610
&log_output_typelib, 0);
614
Additional variables (not derived from sys_var class, not accessible as
615
@@varname in SELECT or SET). Sorted in alphabetical order to facilitate
616
maintenance - SHOW VARIABLES will sort its output.
617
TODO: remove this list completely
620
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
621
static SHOW_VAR fixed_vars[]= {
622
{"back_log", (char*) &back_log, SHOW_LONG},
623
{"character_sets_dir", mysql_charsets_dir, SHOW_CHAR},
624
{"init_file", (char*) &opt_init_file, SHOW_CHAR_PTR},
625
{"language", language, SHOW_CHAR},
627
{"locked_in_memory", (char*) &locked_in_memory, SHOW_MY_BOOL},
629
{"log_bin", (char*) &opt_bin_log, SHOW_BOOL},
630
{"log_error", (char*) log_error_file, SHOW_CHAR},
631
{"lower_case_file_system", (char*) &lower_case_file_system, SHOW_MY_BOOL},
632
{"lower_case_table_names", (char*) &lower_case_table_names, SHOW_INT},
633
{"myisam_recover_options", (char*) &myisam_recover_options_str, SHOW_CHAR_PTR},
634
{"open_files_limit", (char*) &open_files_limit, SHOW_LONG},
635
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
636
{"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR},
637
{"port", (char*) &mysqld_port, SHOW_INT},
638
{"protocol_version", (char*) &protocol_version, SHOW_INT},
639
{"skip_networking", (char*) &opt_disable_networking, SHOW_BOOL},
640
{"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL},
641
{"thread_stack", (char*) &my_thread_stack_size, SHOW_LONG},
645
bool sys_var::check(THD *thd __attribute__((__unused__)), set_var *var)
647
var->save_result.uint64_t_value= var->value->val_int();
337
bool sys_var_str::check(Session *session, set_var *var)
651
bool sys_var_str::check(THD *thd, set_var *var)
343
if ((res=(*check_func)(session, var)) < 0)
344
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
657
if ((res=(*check_func)(thd, var)) < 0)
658
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
659
name, var->value->str_value.ptr());
348
bool sys_var_std_string::check(Session *session, set_var *var)
350
if (check_func == NULL)
355
int res= (*check_func)(session, var);
358
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
365
664
Functions to check and update variables
669
Update variables 'init_connect, init_slave'.
671
In case of 'DEFAULT' value
672
(for example: 'set GLOBAL init_connect=DEFAULT')
673
'var' parameter is NULL pointer.
676
bool update_sys_var_str(sys_var_str *var_str, rw_lock_t *var_mutex,
679
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
680
uint new_length= (var ? var->value->str_value.length() : 0);
682
old_value= (char*) "";
683
if (!(res= my_strndup(old_value, new_length, MYF(0))))
686
Replace the old value in such a way that the any thread using
689
rw_wrlock(var_mutex);
690
old_value= var_str->value;
692
var_str->value_length= new_length;
693
rw_unlock(var_mutex);
694
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
699
static bool sys_update_init_connect(THD *thd __attribute__((__unused__)), set_var *var)
701
return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
705
static void sys_default_init_connect(THD* thd __attribute__((__unused__)),
706
enum_var_type type __attribute__((__unused__)))
708
update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
712
static bool sys_update_init_slave(THD *thd __attribute__((__unused__)),
715
return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
719
static void sys_default_init_slave(THD* thd __attribute__((__unused__)),
720
enum_var_type type __attribute__((__unused__)))
722
update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
727
If one sets the LOW_PRIORIY UPDATES flag, we also must change the
731
static void fix_low_priority_updates(THD *thd, enum_var_type type)
733
if (type == OPT_GLOBAL)
734
thr_upgraded_concurrent_insert_lock=
735
(global_system_variables.low_priority_updates ?
736
TL_WRITE_LOW_PRIORITY : TL_WRITE);
738
thd->update_lock_default= (thd->variables.low_priority_updates ?
739
TL_WRITE_LOW_PRIORITY : TL_WRITE);
744
fix_myisam_max_sort_file_size(THD *thd __attribute__((__unused__)),
745
enum_var_type type __attribute__((__unused__)))
747
myisam_max_temp_length=
748
(my_off_t) global_system_variables.myisam_max_sort_file_size;
370
752
Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
373
static void fix_max_join_size(Session *session, sql_var_t type)
755
static void fix_max_join_size(THD *thd, enum_var_type type)
375
757
if (type != OPT_GLOBAL)
377
if (session->variables.max_join_size == HA_POS_ERROR)
378
session->options|= OPTION_BIG_SELECTS;
759
if (thd->variables.max_join_size == HA_POS_ERROR)
760
thd->options|= OPTION_BIG_SELECTS;
380
session->options&= ~OPTION_BIG_SELECTS;
762
thd->options&= ~OPTION_BIG_SELECTS;
400
782
If one doesn't use the SESSION modifier, the isolation level
401
783
is only active for the next command.
403
static void fix_tx_isolation(Session *session, sql_var_t type)
785
static void fix_tx_isolation(THD *thd, enum_var_type type)
405
787
if (type == OPT_SESSION)
406
session->session_tx_isolation= ((enum_tx_isolation)
407
session->variables.tx_isolation);
788
thd->session_tx_isolation= ((enum_tx_isolation)
789
thd->variables.tx_isolation);
410
static void fix_completion_type(Session *, sql_var_t) {}
792
static void fix_completion_type(THD *thd __attribute__((unused)),
793
enum_var_type type __attribute__((unused))) {}
412
static int check_completion_type(Session *, set_var *var)
795
static int check_completion_type(THD *thd __attribute__((__unused__)),
414
798
int64_t val= var->value->val_int();
415
799
if (val < 0 || val > 2)
418
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
425
static void fix_session_mem_root(Session *session, sql_var_t type)
427
if (type != OPT_GLOBAL)
428
session->mem_root->reset_root_defaults(session->variables.query_alloc_block_size,
429
session->variables.query_prealloc_size);
433
static void fix_server_id(Session *, sql_var_t)
438
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
439
const std::string &name, int64_t val)
802
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
810
If we are changing the thread variable, we have to copy it to NET too
813
#ifdef HAVE_REPLICATION
814
static void fix_net_read_timeout(THD *thd, enum_var_type type)
816
if (type != OPT_GLOBAL)
817
my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
821
static void fix_net_write_timeout(THD *thd, enum_var_type type)
823
if (type != OPT_GLOBAL)
824
my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
827
static void fix_net_retry_count(THD *thd, enum_var_type type)
829
if (type != OPT_GLOBAL)
830
thd->net.retry_count=thd->variables.net_retry_count;
832
#else /* HAVE_REPLICATION */
833
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
834
enum_var_type type __attribute__((unused)))
836
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
837
enum_var_type type __attribute__((unused)))
839
static void fix_net_retry_count(THD *thd __attribute__((unused)),
840
enum_var_type type __attribute__((unused)))
842
#endif /* HAVE_REPLICATION */
845
extern void fix_delay_key_write(THD *thd __attribute__((__unused__)),
846
enum_var_type type __attribute__((__unused__)))
848
switch ((enum_delay_key_write) delay_key_write_options) {
849
case DELAY_KEY_WRITE_NONE:
850
myisam_delay_key_write=0;
852
case DELAY_KEY_WRITE_ON:
853
myisam_delay_key_write=1;
855
case DELAY_KEY_WRITE_ALL:
856
myisam_delay_key_write=1;
857
ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
862
bool sys_var_set::update(THD *thd __attribute__((__unused__)),
865
*value= var->save_result.ulong_value;
869
uchar *sys_var_set::value_ptr(THD *thd,
870
enum_var_type type __attribute__((__unused__)),
871
LEX_STRING *base __attribute__((__unused__)))
874
String tmp(buff, sizeof(buff), &my_charset_latin1);
879
for (uint i= 0; val; val>>= 1, i++)
883
tmp.append(enum_names->type_names[i],
884
enum_names->type_lengths[i]);
889
if ((length= tmp.length()))
891
return (uchar*) thd->strmake(tmp.ptr(), length);
894
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((__unused__)),
895
enum_var_type type __attribute__((__unused__)))
897
slave_exec_mode_options= 0;
898
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
901
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
903
bool rc= sys_var_set::check(thd, var);
905
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
906
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
909
my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
914
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
917
pthread_mutex_lock(&LOCK_global_system_variables);
918
rc= sys_var_set::update(thd, var);
919
pthread_mutex_unlock(&LOCK_global_system_variables);
923
void fix_slave_exec_mode(enum_var_type type __attribute__((__unused__)))
925
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
926
bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
928
sql_print_error("Ambiguous slave modes combination."
929
" STRICT will be used");
930
bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
932
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
933
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
936
bool sys_var_thd_binlog_format::is_readonly() const
939
Under certain circumstances, the variable is read-only (unchangeable):
941
THD *thd= current_thd;
943
If RBR and open temporary tables, their CREATE TABLE may not be in the
944
binlog, so we can't toggle to SBR in this connection.
945
The test below will also prevent SET GLOBAL, well it was not easy to test
946
if global or not here.
947
And this test will also prevent switching from RBR to RBR (a no-op which
948
should not happen too often).
950
If we don't have row-based replication compiled in, the variable
953
if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
954
thd->temporary_tables)
956
my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
960
if in a stored function/trigger, it's too late to change mode
962
if (thd->in_sub_stmt)
964
my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
967
return sys_var_thd_enum::is_readonly();
971
void fix_binlog_format_after_update(THD *thd,
972
enum_var_type type __attribute__((__unused__)))
974
thd->reset_current_stmt_binlog_row_based();
978
static void fix_max_binlog_size(THD *thd __attribute__((__unused__)),
979
enum_var_type type __attribute__((__unused__)))
981
mysql_bin_log.set_max_size(max_binlog_size);
982
#ifdef HAVE_REPLICATION
983
if (!max_relay_log_size)
984
active_mi->rli.relay_log.set_max_size(max_binlog_size);
989
static void fix_max_relay_log_size(THD *thd __attribute__((__unused__)),
990
enum_var_type type __attribute__((__unused__)))
992
#ifdef HAVE_REPLICATION
993
active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
994
max_relay_log_size: max_binlog_size);
999
static void fix_max_connections(THD *thd __attribute__((__unused__)),
1000
enum_var_type type __attribute__((__unused__)))
1002
resize_thr_alarm(max_connections + 10);
1006
static void fix_thd_mem_root(THD *thd, enum_var_type type)
1008
if (type != OPT_GLOBAL)
1009
reset_root_defaults(thd->mem_root,
1010
thd->variables.query_alloc_block_size,
1011
thd->variables.query_prealloc_size);
1015
static void fix_trans_mem_root(THD *thd, enum_var_type type)
1017
if (type != OPT_GLOBAL)
1018
reset_root_defaults(&thd->transaction.mem_root,
1019
thd->variables.trans_alloc_block_size,
1020
thd->variables.trans_prealloc_size);
1024
static void fix_server_id(THD *thd __attribute__((__unused__)),
1025
enum_var_type type __attribute__((__unused__)))
1027
server_id_supplied = 1;
1028
thd->server_id= server_id;
1032
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
1033
const char *name, int64_t val)
443
char buf[DECIMAL_LONGLONG_DIGITS];
446
internal::ullstr((uint64_t) val, buf);
1040
ullstr((uint64_t) val, buf);
448
internal::llstr(val, buf);
450
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1044
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
451
1045
ER_TRUNCATED_WRONG_VALUE,
452
ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
1046
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
457
uint64_t fix_unsigned(Session *session, uint64_t num,
458
const struct option *option_limits)
1051
static uint64_t fix_unsigned(THD *thd, uint64_t num,
1052
const struct my_option *option_limits)
460
1054
bool fixed= false;
461
1055
uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
463
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
468
static size_t fix_size_t(Session *session, size_t num,
469
const struct option *option_limits)
472
size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
474
throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
478
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
484
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
486
uint64_t tmp= var->getInteger();
487
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
491
uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
492
if(static_cast<uint64_t>(newvalue) == tmp)
497
*value= static_cast<uint32_t>(tmp);
504
void sys_var_uint32_t_ptr::set_default(Session *session, sql_var_t)
507
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
508
*value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
509
option_limits, ¬_used);
513
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
515
uint64_t tmp= var->getInteger();
516
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
520
uint64_t newvalue= fix_unsigned(session, tmp, option_limits);
533
void sys_var_uint64_t_ptr::set_default(Session *session, sql_var_t)
535
if (have_default_value)
537
*value= default_value;
542
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
543
*value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
544
option_limits, ¬_used);
549
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
551
size_t tmp= size_t(var->getInteger());
553
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
556
*value= fix_size_t(session, tmp, option_limits);
564
void sys_var_size_t_ptr::set_default(Session *session, sql_var_t)
567
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
568
*value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
1057
throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
1061
static bool get_unsigned(THD *thd __attribute__((__unused__)), set_var *var)
1063
if (var->value->unsigned_flag)
1064
var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
1067
int64_t v= var->value->val_int();
1068
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
1075
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
1076
sys_after_update_func after_update_arg)
1077
:sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
1078
&LOCK_global_system_variables, after_update_arg)
1082
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
1084
return get_unsigned(thd, var);
1087
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
1089
uint64_t tmp= var->save_result.uint64_t_value;
1090
pthread_mutex_lock(guard);
1092
*value= (ulong) fix_unsigned(thd, tmp, option_limits);
1095
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1096
/* Avoid overflows on 32 bit systems */
1097
if (tmp > ULONG_MAX)
1100
throw_bounds_warning(thd, true, true, name,
1101
(int64_t) var->save_result.uint64_t_value);
1104
*value= (ulong) tmp;
1107
pthread_mutex_unlock(guard);
1112
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
1115
pthread_mutex_lock(guard);
1116
*value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
569
1117
option_limits, ¬_used);
572
bool sys_var_bool_ptr::check(Session *session, set_var *var)
574
return check_enum(session, var, &bool_typelib);
577
bool sys_var_bool_ptr::update(Session *, set_var *var)
579
*value= bool(var->getInteger());
584
void sys_var_bool_ptr::set_default(Session *, sql_var_t)
586
*value= default_value;
591
32 bit types for session variables
593
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
596
return (check_func && (*check_func)(session, var));
599
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
601
uint64_t tmp= var->getInteger();
1118
pthread_mutex_unlock(guard);
1122
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
1124
uint64_t tmp= var->save_result.uint64_t_value;
1125
pthread_mutex_lock(&LOCK_global_system_variables);
1127
*value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
1129
*value= (uint64_t) tmp;
1130
pthread_mutex_unlock(&LOCK_global_system_variables);
1135
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((__unused__)),
1136
enum_var_type type __attribute__((__unused__)))
1139
pthread_mutex_lock(&LOCK_global_system_variables);
1140
*value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
1141
option_limits, ¬_used);
1142
pthread_mutex_unlock(&LOCK_global_system_variables);
1146
bool sys_var_bool_ptr::update(THD *thd __attribute__((__unused__)), set_var *var)
1148
*value= (bool) var->save_result.ulong_value;
1153
void sys_var_bool_ptr::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
1155
*value= (bool) option_limits->def_value;
1159
bool sys_var_enum::update(THD *thd __attribute__((__unused__)), set_var *var)
1161
*value= (uint) var->save_result.ulong_value;
1166
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((__unused__)),
1167
enum_var_type type __attribute__((__unused__)),
1168
LEX_STRING *base __attribute__((__unused__)))
1170
return (uchar*) enum_names->type_names[*value];
1174
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((__unused__)),
1175
enum_var_type type __attribute__((__unused__)),
1176
LEX_STRING *base __attribute__((__unused__)))
1178
return (uchar*) enum_names->type_names[global_system_variables.*offset];
1181
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1183
return (get_unsigned(thd, var) ||
1184
(check_func && (*check_func)(thd, var)));
1187
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
1189
uint64_t tmp= var->save_result.uint64_t_value;
603
1191
/* Don't use bigger value than given with --maximum-variable-name=.. */
604
if ((uint32_t) tmp > max_system_variables.*offset)
1192
if ((ulong) tmp > max_system_variables.*offset)
606
throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
1194
throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
607
1195
tmp= max_system_variables.*offset;
610
1198
if (option_limits)
611
tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
612
else if (tmp > UINT32_MAX)
1199
tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1200
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1201
else if (tmp > ULONG_MAX)
615
throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
1204
throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
618
1208
if (var->type == OPT_GLOBAL)
619
global_system_variables.*offset= (uint32_t) tmp;
1209
global_system_variables.*offset= (ulong) tmp;
621
session->variables.*offset= (uint32_t) tmp;
1211
thd->variables.*offset= (ulong) tmp;
627
void sys_var_session_uint32_t::set_default(Session *session, sql_var_t type)
1217
void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
629
1219
if (type == OPT_GLOBAL)
632
1222
/* We will not come here if option_limits is not set */
633
1223
global_system_variables.*offset=
634
(uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
1224
(ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
635
1225
option_limits, ¬_used);
638
session->variables.*offset= global_system_variables.*offset;
1228
thd->variables.*offset= global_system_variables.*offset;
642
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
1232
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1233
LEX_STRING *base __attribute__((__unused__)))
646
1235
if (type == OPT_GLOBAL)
647
return (unsigned char*) &(global_system_variables.*offset);
648
return (unsigned char*) &(session->variables.*offset);
1236
return (uchar*) &(global_system_variables.*offset);
1237
return (uchar*) &(thd->variables.*offset);
652
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1241
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
654
uint64_t tmp= var->getInteger();
1243
uint64_t tmp= var->save_result.uint64_t_value;
656
1245
/* Don't use bigger value than given with --maximum-variable-name=.. */
657
1246
if ((ha_rows) tmp > max_system_variables.*offset)
658
1247
tmp= max_system_variables.*offset;
660
1249
if (option_limits)
661
tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1250
tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
662
1251
if (var->type == OPT_GLOBAL)
664
1253
/* Lock is needed to make things safe on 32 bit systems */
665
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1254
pthread_mutex_lock(&LOCK_global_system_variables);
666
1255
global_system_variables.*offset= (ha_rows) tmp;
1256
pthread_mutex_unlock(&LOCK_global_system_variables);
670
session->variables.*offset= (ha_rows) tmp;
1259
thd->variables.*offset= (ha_rows) tmp;
677
void sys_var_session_ha_rows::set_default(Session *session, sql_var_t type)
1264
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
679
1266
if (type == OPT_GLOBAL)
682
1269
/* We will not come here if option_limits is not set */
683
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1270
pthread_mutex_lock(&LOCK_global_system_variables);
684
1271
global_system_variables.*offset=
685
1272
(ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
686
1273
option_limits, ¬_used);
1274
pthread_mutex_unlock(&LOCK_global_system_variables);
690
session->variables.*offset= global_system_variables.*offset;
1277
thd->variables.*offset= global_system_variables.*offset;
695
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
1281
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1282
LEX_STRING *base __attribute__((__unused__)))
699
1284
if (type == OPT_GLOBAL)
700
return (unsigned char*) &(global_system_variables.*offset);
701
return (unsigned char*) &(session->variables.*offset);
704
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
707
return (check_func && (*check_func)(session, var));
710
bool sys_var_session_uint64_t::update(Session *session, set_var *var)
712
uint64_t tmp= var->getInteger();
1285
return (uchar*) &(global_system_variables.*offset);
1286
return (uchar*) &(thd->variables.*offset);
1289
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
1291
return get_unsigned(thd, var);
1294
bool sys_var_thd_uint64_t::update(THD *thd, set_var *var)
1296
uint64_t tmp= var->save_result.uint64_t_value;
714
1298
if (tmp > max_system_variables.*offset)
716
throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
717
1299
tmp= max_system_variables.*offset;
720
1301
if (option_limits)
721
tmp= fix_unsigned(session, tmp, option_limits);
1302
tmp= fix_unsigned(thd, tmp, option_limits);
722
1303
if (var->type == OPT_GLOBAL)
724
1305
/* Lock is needed to make things safe on 32 bit systems */
725
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1306
pthread_mutex_lock(&LOCK_global_system_variables);
726
1307
global_system_variables.*offset= (uint64_t) tmp;
1308
pthread_mutex_unlock(&LOCK_global_system_variables);
730
session->variables.*offset= (uint64_t) tmp;
1311
thd->variables.*offset= (uint64_t) tmp;
737
void sys_var_session_uint64_t::set_default(Session *session, sql_var_t type)
1316
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
739
1318
if (type == OPT_GLOBAL)
742
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1321
pthread_mutex_lock(&LOCK_global_system_variables);
743
1322
global_system_variables.*offset=
744
1323
getopt_ull_limit_value((uint64_t) option_limits->def_value,
745
1324
option_limits, ¬_used);
749
session->variables.*offset= global_system_variables.*offset;
754
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
758
if (type == OPT_GLOBAL)
759
return (unsigned char*) &(global_system_variables.*offset);
760
return (unsigned char*) &(session->variables.*offset);
763
bool sys_var_session_size_t::check(Session *session, set_var *var)
766
return (check_func && (*check_func)(session, var));
769
bool sys_var_session_size_t::update(Session *session, set_var *var)
771
size_t tmp= size_t(var->getInteger());
773
if (tmp > max_system_variables.*offset)
774
tmp= max_system_variables.*offset;
777
tmp= fix_size_t(session, tmp, option_limits);
778
if (var->type == OPT_GLOBAL)
780
/* Lock is needed to make things safe on 32 bit systems */
781
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
782
global_system_variables.*offset= tmp;
786
session->variables.*offset= tmp;
793
void sys_var_session_size_t::set_default(Session *session, sql_var_t type)
795
if (type == OPT_GLOBAL)
798
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
799
global_system_variables.*offset=
800
(size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
801
option_limits, ¬_used);
805
session->variables.*offset= global_system_variables.*offset;
810
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
814
if (type == OPT_GLOBAL)
815
return (unsigned char*) &(global_system_variables.*offset);
816
return (unsigned char*) &(session->variables.*offset);
819
bool sys_var_session_bool::check(Session *session, set_var *var)
821
return check_enum(session, var, &bool_typelib);
824
bool sys_var_session_bool::update(Session *session, set_var *var)
826
if (var->type == OPT_GLOBAL)
827
global_system_variables.*offset= bool(var->getInteger());
829
session->variables.*offset= bool(var->getInteger());
835
void sys_var_session_bool::set_default(Session *session, sql_var_t type)
837
if (type == OPT_GLOBAL)
838
global_system_variables.*offset= (bool) option_limits->def_value;
840
session->variables.*offset= global_system_variables.*offset;
844
unsigned char *sys_var_session_bool::value_ptr(Session *session,
848
if (type == OPT_GLOBAL)
849
return (unsigned char*) &(global_system_variables.*offset);
850
return (unsigned char*) &(session->variables.*offset);
854
bool sys_var::check_enum(Session *,
1325
pthread_mutex_unlock(&LOCK_global_system_variables);
1328
thd->variables.*offset= global_system_variables.*offset;
1332
uchar *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1333
LEX_STRING *base __attribute__((__unused__)))
1335
if (type == OPT_GLOBAL)
1336
return (uchar*) &(global_system_variables.*offset);
1337
return (uchar*) &(thd->variables.*offset);
1341
bool sys_var_thd_bool::update(THD *thd, set_var *var)
1343
if (var->type == OPT_GLOBAL)
1344
global_system_variables.*offset= (my_bool) var->save_result.ulong_value;
1346
thd->variables.*offset= (my_bool) var->save_result.ulong_value;
1351
void sys_var_thd_bool::set_default(THD *thd, enum_var_type type)
1353
if (type == OPT_GLOBAL)
1354
global_system_variables.*offset= (my_bool) option_limits->def_value;
1356
thd->variables.*offset= global_system_variables.*offset;
1360
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1361
LEX_STRING *base __attribute__((__unused__)))
1363
if (type == OPT_GLOBAL)
1364
return (uchar*) &(global_system_variables.*offset);
1365
return (uchar*) &(thd->variables.*offset);
1369
bool sys_var::check_enum(THD *thd __attribute__((__unused__)),
855
1370
set_var *var, const TYPELIB *enum_names)
857
1372
char buff[STRING_BUFFER_USUAL_SIZE];
999
1573
tmp= new Item_null();
1000
1574
tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1576
pthread_mutex_unlock(&LOCK_global_system_variables);
1006
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
1580
my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
1012
bool sys_var_session_enum::update(Session *session, set_var *var)
1586
bool sys_var_thd_enum::update(THD *thd, set_var *var)
1014
1588
if (var->type == OPT_GLOBAL)
1015
global_system_variables.*offset= var->getInteger();
1589
global_system_variables.*offset= var->save_result.ulong_value;
1017
session->variables.*offset= var->getInteger();
1591
thd->variables.*offset= var->save_result.ulong_value;
1022
void sys_var_session_enum::set_default(Session *session, sql_var_t type)
1596
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
1024
1598
if (type == OPT_GLOBAL)
1025
global_system_variables.*offset= (uint32_t) option_limits->def_value;
1599
global_system_variables.*offset= (ulong) option_limits->def_value;
1027
session->variables.*offset= global_system_variables.*offset;
1601
thd->variables.*offset= global_system_variables.*offset;
1031
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1605
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1606
LEX_STRING *base __attribute__((__unused__)))
1035
uint32_t tmp= ((type == OPT_GLOBAL) ?
1608
ulong tmp= ((type == OPT_GLOBAL) ?
1036
1609
global_system_variables.*offset :
1037
session->variables.*offset);
1038
return (unsigned char*) enum_names->type_names[tmp];
1041
bool sys_var_session_bit::check(Session *session, set_var *var)
1043
return (check_enum(session, var, &bool_typelib) ||
1044
(check_func && (*check_func)(session, var)));
1047
bool sys_var_session_bit::update(Session *session, set_var *var)
1049
int res= (*update_func)(session, var);
1610
thd->variables.*offset);
1611
return (uchar*) enum_names->type_names[tmp];
1614
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1616
return (check_enum(thd, var, &bool_typelib) ||
1617
(check_func && (*check_func)(thd, var)));
1620
bool sys_var_thd_bit::update(THD *thd, set_var *var)
1622
int res= (*update_func)(thd, var);
1054
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t,
1627
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1628
enum_var_type type __attribute__((__unused__)),
1629
LEX_STRING *base __attribute__((__unused__)))
1058
1632
If reverse is 0 (default) return 1 if bit is set.
1059
1633
If reverse is 1, return 0 if bit is set
1061
session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1635
thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ?
1062
1636
!reverse : reverse);
1063
return (unsigned char*) &session->sys_var_tmp.bool_value;
1067
bool sys_var_collation_sv::update(Session *session, set_var *var)
1069
const CHARSET_INFO *tmp;
1637
return (uchar*) &thd->sys_var_tmp.my_bool_value;
1641
/** Update a date_time format variable based on given value. */
1643
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
1644
DATE_TIME_FORMAT *new_value)
1646
DATE_TIME_FORMAT *old;
1648
if (type == OPT_GLOBAL)
1650
pthread_mutex_lock(&LOCK_global_system_variables);
1651
old= (global_system_variables.*offset);
1652
(global_system_variables.*offset)= new_value;
1653
pthread_mutex_unlock(&LOCK_global_system_variables);
1657
old= (thd->variables.*offset);
1658
(thd->variables.*offset)= new_value;
1660
my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1665
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
1667
DATE_TIME_FORMAT *new_value;
1668
/* We must make a copy of the last value to get it into normal memory */
1669
new_value= date_time_format_copy((THD*) 0,
1670
var->save_result.date_time_format);
1672
return 1; // Out of memory
1673
update2(thd, var->type, new_value); // Can't fail
1678
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
1680
char buff[STRING_BUFFER_USUAL_SIZE];
1681
String str(buff,sizeof(buff), system_charset_info), *res;
1682
DATE_TIME_FORMAT *format;
1684
if (!(res=var->value->val_str(&str)))
1685
res= &my_empty_string;
1687
if (!(format= date_time_format_make(date_time_type,
1688
res->ptr(), res->length())))
1690
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1695
We must copy result to thread space to not get a memory leak if
1698
var->save_result.date_time_format= date_time_format_copy(thd, format);
1699
my_free((char*) format, MYF(0));
1700
return var->save_result.date_time_format == 0;
1704
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
1706
DATE_TIME_FORMAT *res= 0;
1708
if (type == OPT_GLOBAL)
1711
if ((format= opt_date_time_formats[date_time_type]))
1712
res= date_time_format_make(date_time_type, format, strlen(format));
1716
/* Make copy with malloc */
1717
res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
1720
if (res) // Should always be true
1721
update2(thd, type, res);
1725
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1726
LEX_STRING *base __attribute__((__unused__)))
1728
if (type == OPT_GLOBAL)
1732
We do a copy here just to be sure things will work even if someone
1733
is modifying the original string while the copy is accessed
1734
(Can't happen now in SQL SHOW, but this is a good safety for the future)
1736
res= thd->strmake((global_system_variables.*offset)->format.str,
1737
(global_system_variables.*offset)->format.length);
1738
return (uchar*) res;
1740
return (uchar*) (thd->variables.*offset)->format.str;
1744
typedef struct old_names_map_st
1746
const char *old_name;
1747
const char *new_name;
1750
static my_old_conv old_conv[]=
1752
{ "cp1251_koi8" , "cp1251" },
1753
{ "cp1250_latin2" , "cp1250" },
1754
{ "kam_latin2" , "keybcs2" },
1755
{ "mac_latin2" , "MacRoman" },
1756
{ "macce_latin2" , "MacCE" },
1757
{ "pc2_latin2" , "pclatin2" },
1758
{ "vga_latin2" , "pclatin1" },
1759
{ "koi8_cp1251" , "koi8r" },
1760
{ "win1251ukr_koi8_ukr" , "win1251ukr" },
1761
{ "koi8_ukr_win1251ukr" , "koi8u" },
1765
CHARSET_INFO *get_old_charset_by_name(const char *name)
1769
for (conv= old_conv; conv->old_name; conv++)
1771
if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
1772
return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
1778
bool sys_var_collation::check(THD *thd __attribute__((__unused__)),
1071
1783
if (var->value->result_type() == STRING_RESULT)
1074
1786
String str(buff,sizeof(buff), system_charset_info), *res;
1075
1787
if (!(res=var->value->val_str(&str)))
1077
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
1789
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1080
if (!(tmp=get_charset_by_name(res->c_ptr())))
1792
if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0))))
1082
1794
my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
1083
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string(res->c_ptr())));
1087
1798
else // INT_RESULT
1089
if (!(tmp=get_charset((int) var->value->val_int())))
1800
if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1092
internal::int10_to_str((int) var->value->val_int(), buf, -10);
1803
int10_to_str((int) var->value->val_int(), buf, -10);
1093
1804
my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
1094
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(boost::lexical_cast<std::string>(var->value->val_int())));
1808
var->save_result.charset= tmp; // Save for update
1813
bool sys_var_character_set::check(THD *thd __attribute__((__unused__)),
1818
if (var->value->result_type() == STRING_RESULT)
1820
char buff[STRING_BUFFER_USUAL_SIZE];
1821
String str(buff,sizeof(buff), system_charset_info), *res;
1822
if (!(res=var->value->val_str(&str)))
1826
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1831
else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
1832
!(tmp=get_old_charset_by_name(res->c_ptr())))
1834
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1840
if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1843
int10_to_str((int) var->value->val_int(), buf, -10);
1844
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf);
1848
var->save_result.charset= tmp; // Save for update
1853
bool sys_var_character_set::update(THD *thd, set_var *var)
1855
ci_ptr(thd,var->type)[0]= var->save_result.charset;
1856
thd->update_charset();
1861
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1862
LEX_STRING *base __attribute__((__unused__)))
1864
CHARSET_INFO *cs= ci_ptr(thd,type)[0];
1865
return cs ? (uchar*) cs->csname : (uchar*) NULL;
1869
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
1871
if (type == OPT_GLOBAL)
1872
global_system_variables.*offset= *global_default;
1875
thd->variables.*offset= global_system_variables.*offset;
1876
thd->update_charset();
1879
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1881
if (type == OPT_GLOBAL)
1882
return &(global_system_variables.*offset);
1884
return &(thd->variables.*offset);
1888
bool sys_var_character_set_client::check(THD *thd, set_var *var)
1890
if (sys_var_character_set_sv::check(thd, var))
1892
/* Currently, UCS-2 cannot be used as a client character set */
1893
if (var->save_result.charset->mbminlen > 1)
1895
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name,
1896
var->save_result.charset->csname);
1903
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1906
if (type == OPT_GLOBAL)
1907
return &global_system_variables.collation_database;
1909
return &thd->variables.collation_database;
1913
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
1915
if (type == OPT_GLOBAL)
1916
global_system_variables.collation_database= default_charset_info;
1919
thd->variables.collation_database= thd->db_charset;
1920
thd->update_charset();
1925
bool sys_var_collation_sv::update(THD *thd, set_var *var)
1098
1927
if (var->type == OPT_GLOBAL)
1099
global_system_variables.*offset= tmp;
1928
global_system_variables.*offset= var->save_result.charset;
1102
session->variables.*offset= tmp;
1931
thd->variables.*offset= var->save_result.charset;
1932
thd->update_charset();
1108
void sys_var_collation_sv::set_default(Session *session, sql_var_t type)
1938
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
1110
1940
if (type == OPT_GLOBAL)
1111
1941
global_system_variables.*offset= *global_default;
1114
session->variables.*offset= global_system_variables.*offset;
1119
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1123
const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1124
global_system_variables.*offset :
1125
session->variables.*offset);
1126
return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1944
thd->variables.*offset= global_system_variables.*offset;
1945
thd->update_charset();
1950
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1951
LEX_STRING *base __attribute__((__unused__)))
1953
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1954
global_system_variables.*offset : thd->variables.*offset);
1955
return cs ? (uchar*) cs->name : (uchar*) "NULL";
1959
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1961
static KEY_CACHE zero_key_cache;
1963
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
1965
safe_mutex_assert_owner(&LOCK_global_system_variables);
1966
if (!cache_name || ! cache_name->length)
1967
cache_name= &default_key_cache_base;
1968
return ((KEY_CACHE*) find_named(&key_caches,
1969
cache_name->str, cache_name->length, 0));
1973
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((__unused__)),
1974
enum_var_type type __attribute__((__unused__)),
1975
LEX_STRING *base __attribute__((__unused__)))
1977
KEY_CACHE *key_cache= get_key_cache(base);
1979
key_cache= &zero_key_cache;
1980
return (uchar*) key_cache + offset ;
1984
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1986
uint64_t tmp= var->save_result.uint64_t_value;
1987
LEX_STRING *base_name= &var->base;
1988
KEY_CACHE *key_cache;
1991
/* If no basename, assume it's for the key cache named 'default' */
1992
if (!base_name->length)
1993
base_name= &default_key_cache_base;
1995
pthread_mutex_lock(&LOCK_global_system_variables);
1996
key_cache= get_key_cache(base_name);
2000
/* Key cache didn't exists */
2001
if (!tmp) // Tried to delete cache
2002
goto end; // Ok, nothing to do
2003
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
2011
Abort if some other thread is changing the key cache
2012
TODO: This should be changed so that we wait until the previous
2013
assignment is done and then do the new assign
2015
if (key_cache->in_init)
2018
if (!tmp) // Zero size means delete
2020
if (key_cache == dflt_key_cache)
2022
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2023
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
2024
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
2025
goto end; // Ignore default key cache
2028
if (key_cache->key_cache_inited) // If initied
2031
Move tables using this key cache to the default key cache
2032
and clear the old key cache.
2035
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
2036
base_name->length, &list);
2037
key_cache->in_init= 1;
2038
pthread_mutex_unlock(&LOCK_global_system_variables);
2039
error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
2040
pthread_mutex_lock(&LOCK_global_system_variables);
2041
key_cache->in_init= 0;
2044
We don't delete the key cache as some running threads my still be
2045
in the key cache code with a pointer to the deleted (empty) key cache
2050
key_cache->param_buff_size=
2051
(uint64_t) fix_unsigned(thd, tmp, option_limits);
2053
/* If key cache didn't existed initialize it, else resize it */
2054
key_cache->in_init= 1;
2055
pthread_mutex_unlock(&LOCK_global_system_variables);
2057
if (!key_cache->key_cache_inited)
2058
error= (bool) (ha_init_key_cache("", key_cache));
2060
error= (bool)(ha_resize_key_cache(key_cache));
2062
pthread_mutex_lock(&LOCK_global_system_variables);
2063
key_cache->in_init= 0;
2066
pthread_mutex_unlock(&LOCK_global_system_variables);
2073
Abort if some other thread is changing the key cache.
2074
This should be changed so that we wait until the previous
2075
assignment is done and then do the new assign
2077
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
2079
ulong tmp= (ulong) var->value->val_int();
2080
LEX_STRING *base_name= &var->base;
2083
if (!base_name->length)
2084
base_name= &default_key_cache_base;
2086
pthread_mutex_lock(&LOCK_global_system_variables);
2087
KEY_CACHE *key_cache= get_key_cache(base_name);
2089
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
2090
base_name->length)))
2097
Abort if some other thread is changing the key cache
2098
TODO: This should be changed so that we wait until the previous
2099
assignment is done and then do the new assign
2101
if (key_cache->in_init)
2104
*((ulong*) (((char*) key_cache) + offset))=
2105
(ulong) fix_unsigned(thd, tmp, option_limits);
2108
Don't create a new key cache if it didn't exist
2109
(key_caches are created only when the user sets block_size)
2111
key_cache->in_init= 1;
2113
pthread_mutex_unlock(&LOCK_global_system_variables);
2115
error= (bool) (ha_resize_key_cache(key_cache));
2117
pthread_mutex_lock(&LOCK_global_system_variables);
2118
key_cache->in_init= 0;
2121
pthread_mutex_unlock(&LOCK_global_system_variables);
2126
bool sys_var_log_state::update(THD *thd, set_var *var)
2129
pthread_mutex_lock(&LOCK_global_system_variables);
2130
if (!var->save_result.ulong_value)
2132
logger.deactivate_log_handler(thd, log_type);
2136
res= logger.activate_log_handler(thd, log_type);
2137
pthread_mutex_unlock(&LOCK_global_system_variables);
2141
void sys_var_log_state::set_default(THD *thd,
2142
enum_var_type type __attribute__((__unused__)))
2144
pthread_mutex_lock(&LOCK_global_system_variables);
2145
logger.deactivate_log_handler(thd, log_type);
2146
pthread_mutex_unlock(&LOCK_global_system_variables);
2150
static int sys_check_log_path(THD *thd __attribute__((__unused__)),
2153
char path[FN_REFLEN], buff[FN_REFLEN];
2155
String str(buff, sizeof(buff), system_charset_info), *res;
2156
const char *log_file_str;
2159
if (!(res= var->value->val_str(&str)))
2162
log_file_str= res->c_ptr();
2163
bzero(&f_stat, sizeof(struct stat));
2165
path_length= unpack_filename(path, log_file_str);
2169
/* File name is empty. */
2174
if (!stat(path, &f_stat))
2177
A file system object exists. Check if argument is a file and we have
2181
if (!MY_S_ISREG(f_stat.st_mode) ||
2182
!(f_stat.st_mode & MY_S_IWRITE))
2188
/* Get dirname of the file path. */
2189
(void) dirname_part(path, log_file_str, &path_length);
2191
/* Dirname is empty if file path is relative. */
2196
Check if directory exists and we have permission to create file and
2199
if (my_access(path, (F_OK|W_OK)))
2205
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name,
2206
res ? log_file_str : "NULL");
2211
bool update_sys_var_str_path(THD *thd __attribute__((__unused__)),
2212
sys_var_str *var_str,
2213
set_var *var, const char *log_ext,
2214
bool log_state, uint log_type)
2216
MYSQL_QUERY_LOG *file_log;
2217
char buff[FN_REFLEN];
2218
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2220
uint str_length= (var ? var->value->str_value.length() : 0);
2223
case QUERY_LOG_SLOW:
2224
file_log= logger.get_slow_log_file_handler();
2226
case QUERY_LOG_GENERAL:
2227
file_log= logger.get_log_file_handler();
2230
assert(0); // Impossible
2235
old_value= make_default_log_name(buff, log_ext);
2236
str_length= strlen(old_value);
2238
if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
2244
pthread_mutex_lock(&LOCK_global_system_variables);
2245
logger.lock_exclusive();
2247
if (file_log && log_state)
2249
old_value= var_str->value;
2250
var_str->value= res;
2251
var_str->value_length= str_length;
2252
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
2253
if (file_log && log_state)
2256
case QUERY_LOG_SLOW:
2257
file_log->open_slow_log(sys_var_slow_log_path.value);
2259
case QUERY_LOG_GENERAL:
2260
file_log->open_query_log(sys_var_general_log_path.value);
2268
pthread_mutex_unlock(&LOCK_global_system_variables);
2275
static bool sys_update_general_log_path(THD *thd, set_var * var)
2277
return update_sys_var_str_path(thd, &sys_var_general_log_path,
2278
var, ".log", opt_log, QUERY_LOG_GENERAL);
2282
static void sys_default_general_log_path(THD *thd,
2283
enum_var_type type __attribute__((__unused__)))
2285
(void) update_sys_var_str_path(thd, &sys_var_general_log_path,
2286
0, ".log", opt_log, QUERY_LOG_GENERAL);
2290
static bool sys_update_slow_log_path(THD *thd, set_var * var)
2292
return update_sys_var_str_path(thd, &sys_var_slow_log_path,
2293
var, "-slow.log", opt_slow_log,
2298
static void sys_default_slow_log_path(THD *thd,
2299
enum_var_type type __attribute__((__unused__)))
2301
(void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
2302
0, "-slow.log", opt_slow_log,
2307
bool sys_var_log_output::update(THD *thd __attribute__((__unused__)),
2310
pthread_mutex_lock(&LOCK_global_system_variables);
2311
logger.lock_exclusive();
2312
logger.init_slow_log(var->save_result.ulong_value);
2313
logger.init_general_log(var->save_result.ulong_value);
2314
*value= var->save_result.ulong_value;
2316
pthread_mutex_unlock(&LOCK_global_system_variables);
2321
void sys_var_log_output::set_default(THD *thd __attribute__((__unused__)),
2322
enum_var_type type __attribute__((__unused__)))
2324
pthread_mutex_lock(&LOCK_global_system_variables);
2325
logger.lock_exclusive();
2326
logger.init_slow_log(LOG_FILE);
2327
logger.init_general_log(LOG_FILE);
2330
pthread_mutex_unlock(&LOCK_global_system_variables);
2334
uchar *sys_var_log_output::value_ptr(THD *thd,
2335
enum_var_type type __attribute__((__unused__)),
2336
LEX_STRING *base __attribute__((__unused__)))
2339
String tmp(buff, sizeof(buff), &my_charset_latin1);
2344
for (uint i= 0; val; val>>= 1, i++)
2348
tmp.append(log_output_typelib.type_names[i],
2349
log_output_typelib.type_lengths[i]);
2354
if ((length= tmp.length()))
2356
return (uchar*) thd->strmake(tmp.ptr(), length);
2360
/*****************************************************************************
2361
Functions to handle SET NAMES and SET CHARACTER SET
2362
*****************************************************************************/
2364
int set_var_collation_client::check(THD *thd __attribute__((__unused__)))
2366
/* Currently, UCS-2 cannot be used as a client character set */
2367
if (character_set_client->mbminlen > 1)
2369
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
2370
character_set_client->csname);
2376
int set_var_collation_client::update(THD *thd)
2378
thd->variables.character_set_client= character_set_client;
2379
thd->variables.character_set_results= character_set_results;
2380
thd->variables.collation_connection= collation_connection;
2381
thd->update_charset();
2382
thd->protocol_text.init(thd);
1129
2386
/****************************************************************************/
1131
bool sys_var_timestamp::update(Session *session, set_var *var)
1133
session->set_time(time_t(var->getInteger()));
1138
void sys_var_timestamp::set_default(Session *session, sql_var_t)
1140
session->resetUserTime();
1144
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
1147
session->sys_var_tmp.int32_t_value= (int32_t) session->getCurrentTimestampEpoch();
1148
return (unsigned char*) &session->sys_var_tmp.int32_t_value;
1152
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1154
session->first_successful_insert_id_in_prev_stmt= var->getInteger();
1159
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
2388
bool sys_var_timestamp::update(THD *thd, set_var *var)
2390
thd->set_time((time_t) var->save_result.uint64_t_value);
2395
void sys_var_timestamp::set_default(THD *thd,
2396
enum_var_type type __attribute__((__unused__)))
2402
uchar *sys_var_timestamp::value_ptr(THD *thd,
2403
enum_var_type type __attribute__((__unused__)),
2404
LEX_STRING *base __attribute__((__unused__)))
2406
thd->sys_var_tmp.long_value= (long) thd->start_time;
2407
return (uchar*) &thd->sys_var_tmp.long_value;
2411
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2413
thd->first_successful_insert_id_in_prev_stmt=
2414
var->save_result.uint64_t_value;
2419
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2420
enum_var_type type __attribute__((__unused__)),
2421
LEX_STRING *base __attribute__((__unused__)))
1164
2424
this tmp var makes it robust againt change of type of
1165
2425
read_first_successful_insert_id_in_prev_stmt().
1167
session->sys_var_tmp.uint64_t_value=
1168
session->read_first_successful_insert_id_in_prev_stmt();
1169
return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1172
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
2427
thd->sys_var_tmp.uint64_t_value=
2428
thd->read_first_successful_insert_id_in_prev_stmt();
2429
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2433
bool sys_var_insert_id::update(THD *thd, set_var *var)
2435
thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2440
uchar *sys_var_insert_id::value_ptr(THD *thd,
2441
enum_var_type type __attribute__((__unused__)),
2442
LEX_STRING *base __attribute__((__unused__)))
2444
thd->sys_var_tmp.uint64_t_value=
2445
thd->auto_inc_intervals_forced.minimum();
2446
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2450
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2452
thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2456
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2458
thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2463
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
2465
char buff[MAX_TIME_ZONE_NAME_LENGTH];
2466
String str(buff, sizeof(buff), &my_charset_latin1);
2467
String *res= var->value->val_str(&str);
2469
if (!(var->save_result.time_zone= my_tz_find(thd, res)))
2471
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2478
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
2480
/* We are using Time_zone object found during check() phase. */
2481
if (var->type == OPT_GLOBAL)
2483
pthread_mutex_lock(&LOCK_global_system_variables);
2484
global_system_variables.time_zone= var->save_result.time_zone;
2485
pthread_mutex_unlock(&LOCK_global_system_variables);
2488
thd->variables.time_zone= var->save_result.time_zone;
2493
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2494
LEX_STRING *base __attribute__((__unused__)))
2497
We can use ptr() instead of c_ptr() here because String contaning
2498
time zone name is guaranteed to be zero ended.
2500
if (type == OPT_GLOBAL)
2501
return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
2505
This is an ugly fix for replication: we don't replicate properly queries
2506
invoking system variables' values to update tables; but
2507
CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
2508
replicable (i.e. we tell the binlog code to store the session
2509
timezone). If it's the global value which was used we can't replicate
2510
(binlog code stores session value only).
2512
thd->time_zone_used= 1;
2513
return (uchar *)(thd->variables.time_zone->get_name()->ptr());
2518
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
2520
pthread_mutex_lock(&LOCK_global_system_variables);
2521
if (type == OPT_GLOBAL)
2523
if (default_tz_name)
2525
String str(default_tz_name, &my_charset_latin1);
2527
We are guaranteed to find this time zone since its existence
2528
is checked during start-up.
2530
global_system_variables.time_zone= my_tz_find(thd, &str);
2533
global_system_variables.time_zone= my_tz_SYSTEM;
2536
thd->variables.time_zone= global_system_variables.time_zone;
2537
pthread_mutex_unlock(&LOCK_global_system_variables);
2541
bool sys_var_max_user_conn::check(THD *thd, set_var *var)
2543
if (var->type == OPT_GLOBAL)
2544
return sys_var_thd::check(thd, var);
2548
Per-session values of max_user_connections can't be set directly.
2549
May be we should have a separate error message for this?
2551
my_error(ER_GLOBAL_VARIABLE, MYF(0), name);
2556
bool sys_var_max_user_conn::update(THD *thd __attribute__((__unused__)),
2559
assert(var->type == OPT_GLOBAL);
2560
pthread_mutex_lock(&LOCK_global_system_variables);
2561
max_user_connections= (uint)var->save_result.uint64_t_value;
2562
pthread_mutex_unlock(&LOCK_global_system_variables);
2567
void sys_var_max_user_conn::set_default(THD *thd __attribute__((__unused__)),
2568
enum_var_type type __attribute__((__unused__)))
2570
assert(type == OPT_GLOBAL);
2571
pthread_mutex_lock(&LOCK_global_system_variables);
2572
max_user_connections= (ulong) option_limits->def_value;
2573
pthread_mutex_unlock(&LOCK_global_system_variables);
2577
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2578
LEX_STRING *base __attribute__((__unused__)))
2580
if (type != OPT_GLOBAL &&
2581
thd->user_connect && thd->user_connect->user_resources.user_conn)
2582
return (uchar*) &(thd->user_connect->user_resources.user_conn);
2583
return (uchar*) &(max_user_connections);
2587
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((__unused__)),
1174
2590
MY_LOCALE *locale_match;
1176
2592
if (var->value->result_type() == INT_RESULT)
1178
if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
2594
if (!(locale_match= my_locale_by_number((uint) var->value->val_int())))
1180
char buf[DECIMAL_LONGLONG_DIGITS];
1181
internal::int10_to_str((int) var->value->val_int(), buf, -10);
2597
int10_to_str((int) var->value->val_int(), buf, -10);
1182
2598
my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1186
2602
else // STRING_RESULT
1189
String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
2605
String str(buff, sizeof(buff), &my_charset_latin1), *res;
1190
2606
if (!(res=var->value->val_str(&str)))
1192
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
2608
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1195
2611
const char *locale_str= res->c_ptr();
1247
2670
microseconds= (int64_t) (num * 1000000.0 + 0.5);
1248
2671
if (var->type == OPT_GLOBAL)
1250
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
2673
pthread_mutex_lock(&LOCK_global_system_variables);
1251
2674
(global_system_variables.*offset)= microseconds;
2675
pthread_mutex_unlock(&LOCK_global_system_variables);
1254
session->variables.*offset= microseconds;
2678
thd->variables.*offset= microseconds;
1259
void sys_var_microseconds::set_default(Session *session, sql_var_t type)
2683
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
1261
2685
int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1262
2686
if (type == OPT_GLOBAL)
1264
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
2688
pthread_mutex_lock(&LOCK_global_system_variables);
1265
2689
global_system_variables.*offset= microseconds;
2690
pthread_mutex_unlock(&LOCK_global_system_variables);
1268
session->variables.*offset= microseconds;
2693
thd->variables.*offset= microseconds;
2697
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2698
LEX_STRING *base __attribute__((__unused__)))
2700
thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2701
global_system_variables.*offset :
2702
thd->variables.*offset) / 1000000.0;
2703
return (uchar*) &thd->tmp_double_value;
1272
Functions to update session->options bits
2708
Functions to update thd->options bits
1275
static bool set_option_bit(Session *session, set_var *var)
2711
static bool set_option_bit(THD *thd, set_var *var)
1277
sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1278
if ((var->getInteger() != 0) == sys_var->reverse)
1279
session->options&= ~sys_var->bit_flag;
2713
sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
2714
if ((var->save_result.ulong_value != 0) == sys_var->reverse)
2715
thd->options&= ~sys_var->bit_flag;
1281
session->options|= sys_var->bit_flag;
2717
thd->options|= sys_var->bit_flag;
1286
static bool set_option_autocommit(Session *session, set_var *var)
2722
static bool set_option_autocommit(THD *thd, set_var *var)
1289
2724
/* The test is negative as the flag we use is NOT autocommit */
1291
uint64_t org_options= session->options;
1292
uint64_t new_options= session->options;
2726
uint64_t org_options= thd->options;
1294
if (var->getInteger() != 0)
1295
new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2728
if (var->save_result.ulong_value != 0)
2729
thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
1297
new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
2731
thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
1299
if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
2733
if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
1301
2735
if ((org_options & OPTION_NOT_AUTOCOMMIT))
1303
success= session->endActiveTransaction();
1304
2737
/* We changed to auto_commit mode */
1305
session->options&= ~(uint64_t) (OPTION_BEGIN);
1306
session->server_status|= SERVER_STATUS_AUTOCOMMIT;
2738
thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2739
thd->transaction.all.modified_non_trans_table= false;
2740
thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
1310
session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2746
thd->transaction.all.modified_non_trans_table= false;
2747
thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1314
if (var->getInteger() != 0)
1315
session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2753
static int check_log_update(THD *thd __attribute__((__unused__)),
2754
set_var *var __attribute__((__unused__)))
2759
static bool set_log_update(THD *thd __attribute__((__unused__)),
2760
set_var *var __attribute__((__unused__)))
2763
The update log is not supported anymore since 5.0.
2764
See sql/mysqld.cc/, comments in function init_server_components() for an
2765
explaination of the different warnings we send below
2768
if (opt_sql_bin_update)
2770
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2771
ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
2772
ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
1317
session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
1325
static int check_pseudo_thread_id(Session *, set_var *var)
1331
static unsigned char *get_warning_count(Session *session)
1333
session->sys_var_tmp.uint32_t_value=
1334
(session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
1335
session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
1336
session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
1337
return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1340
static unsigned char *get_error_count(Session *session)
1342
session->sys_var_tmp.uint32_t_value=
1343
session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
1344
return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
2775
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2776
ER_UPDATE_LOG_DEPRECATED_IGNORED,
2777
ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
2778
set_option_bit(thd, var);
2783
static int check_pseudo_thread_id(THD *thd __attribute__((__unused__)),
2786
var->save_result.uint64_t_value= var->value->val_int();
2790
static uchar *get_warning_count(THD *thd)
2792
thd->sys_var_tmp.long_value=
2793
(thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
2794
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] +
2795
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
2796
return (uchar*) &thd->sys_var_tmp.long_value;
2799
static uchar *get_error_count(THD *thd)
2801
thd->sys_var_tmp.long_value=
2802
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
2803
return (uchar*) &thd->sys_var_tmp.long_value;
2868
Return variable name and length for hashing of variables.
2871
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
2872
my_bool first __attribute__((__unused__)))
2874
*length= var->name_length;
2875
return (uchar*) var->name;
2880
Add variables to the dynamic hash of system variables
2883
mysql_add_sys_var_chain()
2884
first Pointer to first system variable to add
2885
long_opt (optional)command line arguments may be tied for limit checks.
2893
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
2897
/* A write lock should be held on LOCK_system_variables_hash */
2899
for (var= first; var; var= var->next)
2901
var->name_length= strlen(var->name);
2902
/* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2903
if (my_hash_insert(&system_variable_hash, (uchar*) var))
2906
var->option_limits= find_option(long_options, var->name);
2911
for (; first != var; first= first->next)
2912
hash_delete(&system_variable_hash, (uchar*) first);
2918
Remove variables to the dynamic hash of system variables
2921
mysql_del_sys_var_chain()
2922
first Pointer to first system variable to remove
2929
int mysql_del_sys_var_chain(sys_var *first)
2933
/* A write lock should be held on LOCK_system_variables_hash */
2935
for (sys_var *var= first; var; var= var->next)
2936
result|= hash_delete(&system_variable_hash, (uchar*) var);
2942
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
2944
return strcmp(a->name, b->name);
1411
2949
Constructs an array of system variables for display to the user.
1414
2952
enumerate_sys_vars()
1415
session current thread
2954
sorted If TRUE, the system variables should be sorted
1418
pointer Array of drizzle_show_var elements for display
2957
pointer Array of SHOW_VAR elements for display
1422
drizzle_show_var* enumerate_sys_vars(Session *session)
2961
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
1424
int size= sizeof(drizzle_show_var) * (system_variable_map.size() + 1);
1425
drizzle_show_var *result= (drizzle_show_var*) session->getMemRoot()->allocate(size);
2963
int count= system_variable_hash.records, i;
2964
int fixed_count= fixed_show_vars.elements;
2965
int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2966
SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
1429
drizzle_show_var *show= result;
2970
SHOW_VAR *show= result + fixed_count;
2971
memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
1431
SystemVariableMap::const_iterator iter= system_variable_map.begin();
1432
while (iter != system_variable_map.end())
2973
for (i= 0; i < count; i++)
1434
sys_var *var= (*iter).second;
1435
show->name= var->getName().c_str();
2975
sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
2976
show->name= var->name;
1436
2977
show->value= (char*) var;
1437
2978
show->type= SHOW_SYS;
2982
/* sort into order */
2984
my_qsort(result, count + fixed_count, sizeof(SHOW_VAR),
2985
(qsort_cmp) show_cmp);
1442
2987
/* make last element empty */
1443
memset(show, 0, sizeof(drizzle_show_var));
2988
bzero(show, sizeof(SHOW_VAR));
1450
void add_sys_var_to_list(sys_var *var)
1452
string lower_name(var->getName());
1453
transform(lower_name.begin(), lower_name.end(),
1454
lower_name.begin(), ::tolower);
1456
/* this fails if there is a conflicting variable name. */
1457
if (system_variable_map.find(lower_name) != system_variable_map.end())
1459
errmsg_printf(error::ERROR, _("Variable named %s already exists!\n"),
1460
var->getName().c_str());
1464
pair<SystemVariableMap::iterator, bool> ret=
1465
system_variable_map.insert(make_pair(lower_name, var));
1466
if (ret.second == false)
1468
errmsg_printf(error::ERROR, _("Could not add Variable: %s\n"),
1469
var->getName().c_str());
1474
void add_sys_var_to_list(sys_var *var, struct option *long_options)
1476
add_sys_var_to_list(var);
1477
var->setOptionLimits(find_option(long_options, var->getName().c_str()));
1481
2995
Initialize the system variables
1488
3002
otherwise FAILURE
1495
add_sys_var_to_list(&sys_auto_increment_increment, my_long_options);
1496
add_sys_var_to_list(&sys_auto_increment_offset, my_long_options);
1497
add_sys_var_to_list(&sys_autocommit, my_long_options);
1498
add_sys_var_to_list(&sys_back_log, my_long_options);
1499
add_sys_var_to_list(&sys_basedir, my_long_options);
1500
add_sys_var_to_list(&sys_big_selects, my_long_options);
1501
add_sys_var_to_list(&sys_branch, my_long_options);
1502
add_sys_var_to_list(&sys_buffer_results, my_long_options);
1503
add_sys_var_to_list(&sys_bulk_insert_buff_size, my_long_options);
1504
add_sys_var_to_list(&sys_collation_server, my_long_options);
1505
add_sys_var_to_list(&sys_completion_type, my_long_options);
1506
add_sys_var_to_list(&sys_datadir, my_long_options);
1507
add_sys_var_to_list(&sys_div_precincrement, my_long_options);
1508
add_sys_var_to_list(&sys_error_count, my_long_options);
1509
add_sys_var_to_list(&sys_foreign_key_checks, my_long_options);
1510
add_sys_var_to_list(&sys_group_concat_max_len, my_long_options);
1511
add_sys_var_to_list(&sys_hostname, my_long_options);
1512
add_sys_var_to_list(&sys_identity, my_long_options);
1513
add_sys_var_to_list(&sys_join_buffer_size, my_long_options);
1514
add_sys_var_to_list(&sys_last_insert_id, my_long_options);
1515
add_sys_var_to_list(&sys_lc_time_names, my_long_options);
1516
add_sys_var_to_list(&sys_max_allowed_packet, my_long_options);
1517
add_sys_var_to_list(&sys_max_error_count, my_long_options);
1518
add_sys_var_to_list(&sys_max_heap_table_size, my_long_options);
1519
add_sys_var_to_list(&sys_max_join_size, my_long_options);
1520
add_sys_var_to_list(&sys_max_length_for_sort_data, my_long_options);
1521
add_sys_var_to_list(&sys_max_seeks_for_key, my_long_options);
1522
add_sys_var_to_list(&sys_max_sort_length, my_long_options);
1523
add_sys_var_to_list(&sys_max_write_lock_count, my_long_options);
1524
add_sys_var_to_list(&sys_min_examined_row_limit, my_long_options);
1525
add_sys_var_to_list(&sys_optimizer_prune_level, my_long_options);
1526
add_sys_var_to_list(&sys_optimizer_search_depth, my_long_options);
1527
add_sys_var_to_list(&sys_pid_file, my_long_options);
1528
add_sys_var_to_list(&sys_plugin_dir, my_long_options);
1529
add_sys_var_to_list(&sys_preload_buff_size, my_long_options);
1530
add_sys_var_to_list(&sys_pseudo_thread_id, my_long_options);
1531
add_sys_var_to_list(&sys_query_alloc_block_size, my_long_options);
1532
add_sys_var_to_list(&sys_query_prealloc_size, my_long_options);
1533
add_sys_var_to_list(&sys_range_alloc_block_size, my_long_options);
1534
add_sys_var_to_list(&sys_read_buff_size, my_long_options);
1535
add_sys_var_to_list(&sys_read_rnd_buff_size, my_long_options);
1536
add_sys_var_to_list(&sys_release_id, my_long_options);
1537
add_sys_var_to_list(&sys_replicate_query, my_long_options);
1538
add_sys_var_to_list(&sys_revid, my_long_options);
1539
add_sys_var_to_list(&sys_revno, my_long_options);
1540
add_sys_var_to_list(&sys_scheduler, my_long_options);
1541
add_sys_var_to_list(&sys_secure_file_priv, my_long_options);
1542
add_sys_var_to_list(&sys_select_limit, my_long_options);
1543
add_sys_var_to_list(&sys_server_id, my_long_options);
1544
add_sys_var_to_list(&sys_sort_buffer, my_long_options);
1545
add_sys_var_to_list(&sys_sql_notes, my_long_options);
1546
add_sys_var_to_list(&sys_sql_warnings, my_long_options);
1547
add_sys_var_to_list(&sys_storage_engine, my_long_options);
1548
add_sys_var_to_list(&sys_table_cache_size, my_long_options);
1549
add_sys_var_to_list(&sys_table_def_size, my_long_options);
1550
add_sys_var_to_list(&sys_table_lock_wait_timeout, my_long_options);
1551
add_sys_var_to_list(&sys_thread_stack_size, my_long_options);
1552
add_sys_var_to_list(&sys_timed_mutexes, my_long_options);
1553
add_sys_var_to_list(&sys_timestamp, my_long_options);
1554
add_sys_var_to_list(&sys_tmp_table_size, my_long_options);
1555
add_sys_var_to_list(&sys_tmpdir, my_long_options);
1556
add_sys_var_to_list(&sys_transaction_message_threshold, my_long_options);
1557
add_sys_var_to_list(&sys_tx_isolation, my_long_options);
1558
add_sys_var_to_list(&sys_unique_checks, my_long_options);
1559
add_sys_var_to_list(&sys_version, my_long_options);
1560
add_sys_var_to_list(&sys_version_comment, my_long_options);
1561
add_sys_var_to_list(&sys_version_compile_machine, my_long_options);
1562
add_sys_var_to_list(&sys_version_compile_os, my_long_options);
1563
add_sys_var_to_list(&sys_version_compile_vendor, my_long_options);
1564
add_sys_var_to_list(&sys_warning_count, my_long_options);
1566
catch (std::exception&)
1568
errmsg_printf(error::ERROR, _("Failed to initialize system variables"));
3009
for (sys_var *var=vars.first; var; var= var->next, count++) {};
3011
if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
3012
FIXED_VARS_SIZE + 64, 64))
3015
fixed_show_vars.elements= FIXED_VARS_SIZE;
3016
memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
3018
if (hash_init(&system_variable_hash, system_charset_info, count, 0,
3019
0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
3022
vars.last->next= NULL;
3023
if (mysql_add_sys_var_chain(vars.first, my_long_options))
3028
Needed because MySQL can't find the limits for a variable it it has
3029
a different name than the command line option.
3030
As these variables are deprecated, this code will disappear soon...
3032
sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
3037
fprintf(stderr, "failed to initialize system variables");
3044
hash_free(&system_variable_hash);
3045
delete_dynamic(&fixed_show_vars);
3050
Add elements to the dynamic list of read-only system variables.
3053
mysql_append_static_vars()
3054
show_vars Pointer to start of array
3055
count Number of elements
3061
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
3063
for (; count > 0; count--, show_vars++)
3064
if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
1576
3071
Find a user set-table variable.
1578
@param name Name of system variable to find
3073
@param str Name of system variable to find
3074
@param length Length of variable. zero means that we should use strlen()
3076
@param no_error Refuse to emit an error, even if one occurred.
1581
3079
pointer pointer to variable definitions
1583
3081
0 Unknown variable (error message is given)
1586
sys_var *find_sys_var(const std::string &name)
1588
string lower_name(name);
1589
transform(lower_name.begin(), lower_name.end(),
1590
lower_name.begin(), ::tolower);
1592
sys_var *result= NULL;
1594
SystemVariableMap::iterator iter= system_variable_map.find(lower_name);
1595
if (iter != system_variable_map.end())
1597
result= (*iter).second;
1602
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), name.c_str());
3084
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
3089
This function is only called from the sql_plugin.cc.
3090
A lock on LOCK_system_variable_hash should be held
3092
var= (sys_var*) hash_search(&system_variable_hash,
3093
(uchar*) str, length ? length : strlen(str));
3094
if (!(var || no_error))
3095
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
3102
Execute update of all variables.
3104
First run a check of all variables that all updates will go ok.
3105
If yes, then execute all updates, returning an error if any one failed.
3107
This should ensure that in all normal cases none all or variables are
3110
@param THD Thread id
3111
@param var_list List of variables to update
3116
1 ERROR, message sent (normally no variables was updated)
3118
-1 ERROR, message not sent
3121
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
3124
List_iterator_fast<set_var_base> it(*var_list);
3129
if ((error= var->check(thd)))
3132
if (!(error= test(thd->is_error())))
3136
error|= var->update(thd); // Returns 0, -1 or 1
3140
free_underlaid_joins(thd, &thd->lex->select_lex);
3146
Say if all variables set by a SET support the ONE_SHOT keyword
3147
(currently, only character set and collation do; later timezones
3150
@param var_list List of variables to update
3153
It has a "not_" because it makes faster tests (no need to "!")
3156
0 all variables of the list support ONE_SHOT
3158
1 at least one does not support ONE_SHOT
3161
bool not_all_support_one_shot(List<set_var_base> *var_list)
3163
List_iterator_fast<set_var_base> it(*var_list);
3167
if (var->no_support_one_shot())
3174
/*****************************************************************************
3175
Functions to handle SET mysql_internal_variable=const_expr
3176
*****************************************************************************/
3178
int set_var::check(THD *thd)
3180
if (var->is_readonly())
3182
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name, "read only");
3185
if (var->check_type(type))
3187
int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
3188
my_error(err, MYF(0), var->name);
3191
/* value is a NULL pointer if we are using SET ... = DEFAULT */
3194
if (var->check_default(type))
3196
my_error(ER_NO_DEFAULT, MYF(0), var->name);
3202
if ((!value->fixed &&
3203
value->fix_fields(thd, &value)) || value->check_cols(1))
3205
if (var->check_update_type(value->result_type()))
3207
my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
3210
return var->check(thd, this) ? -1 : 0;
3216
@param thd thread handler
3217
@returns 0|1 ok or ERROR
3219
@note ERROR can be only due to abnormal operations involving
3220
the server's execution evironment such as
3221
out of memory, hard disk failure or the computer blows up.
3222
Consider set_var::check() method if there is a need to return
3223
an error due to logics.
3225
int set_var::update(THD *thd)
3228
var->set_default(thd, type);
3229
else if (var->update(thd, this))
3230
return -1; // should never happen
3231
if (var->after_update)
3232
(*var->after_update)(thd, type);
3237
/*****************************************************************************
3238
Functions to handle SET @user_variable=const_expr
3239
*****************************************************************************/
3241
int set_var_user::check(THD *thd)
3244
Item_func_set_user_var can't substitute something else on its place =>
3245
0 can be passed as last argument (reference on item)
3247
return (user_var_item->fix_fields(thd, (Item**) 0) ||
3248
user_var_item->check(0)) ? -1 : 0;
3252
int set_var_user::update(THD *thd __attribute__((__unused__)))
3254
if (user_var_item->update())
3256
/* Give an error if it's not given already */
3257
my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
1610
3263
/****************************************************************************
1611
3264
Functions to handle table_type
1612
3265
****************************************************************************/
1614
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1618
unsigned char* result;
1620
plugin::StorageEngine *engine= session->variables.*offset;
1621
if (type == OPT_GLOBAL)
1622
engine= global_system_variables.*offset;
1623
engine_name= engine->getName();
1624
result= (unsigned char *) session->strmake(engine_name.c_str(),
1625
engine_name.size());
3267
/* Based upon sys_var::check_enum() */
3269
bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
3271
char buff[STRING_BUFFER_USUAL_SIZE];
3273
String str(buff, sizeof(buff), &my_charset_latin1), *res;
3275
var->save_result.plugin= NULL;
3276
if (var->value->result_type() == STRING_RESULT)
3278
LEX_STRING engine_name;
3280
if (!(res=var->value->val_str(&str)) ||
3281
!(engine_name.str= (char *)res->ptr()) ||
3282
!(engine_name.length= res->length()) ||
3283
!(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
3284
!(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
3285
ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
3287
value= res ? res->c_ptr() : "NULL";
3295
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
3300
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3301
LEX_STRING *base __attribute__((__unused__)))
3305
LEX_STRING *engine_name;
3306
plugin_ref plugin= thd->variables.*offset;
3307
if (type == OPT_GLOBAL)
3308
plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
3309
hton= plugin_data(plugin, handlerton*);
3310
engine_name= &hton2plugin[hton->slot]->name;
3311
result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
3312
if (type == OPT_GLOBAL)
3313
plugin_unlock(thd, plugin);
1630
void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
3318
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
1632
plugin::StorageEngine *old_value, *new_value, **value;
3320
plugin_ref old_value, new_value, *value;
1633
3321
if (type == OPT_GLOBAL)
1635
3323
value= &(global_system_variables.*offset);
1636
new_value= myisam_engine;
3324
new_value= ha_lock_engine(NULL, myisam_hton);
1640
value= &(session->variables.*offset);
1641
new_value= global_system_variables.*offset;
3328
value= &(thd->variables.*offset);
3329
new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
1643
3331
assert(new_value);
1644
3332
old_value= *value;
1645
3333
*value= new_value;
3334
plugin_unlock(NULL, old_value);
1649
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3338
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
1651
char buff[STRING_BUFFER_USUAL_SIZE];
1652
const char *name_value;
1653
String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1655
plugin::StorageEngine *tmp= NULL;
1656
plugin::StorageEngine **value= NULL;
1658
if (var->value->result_type() == STRING_RESULT)
1660
res= var->value->val_str(&str);
1661
if (res == NULL || res->ptr() == NULL)
1668
const std::string engine_name(res->ptr());
1669
tmp= plugin::StorageEngine::findByName(*session, engine_name);
1672
name_value= res->c_ptr();
1679
name_value= "unknown";
1682
value= &(global_system_variables.*offset);
3340
plugin_ref *value= &(global_system_variables.*offset), old_value;
1683
3341
if (var->type != OPT_GLOBAL)
1684
value= &(session->variables.*offset);
1691
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
1695
} /* namespace drizzled */
3342
value= &(thd->variables.*offset);
3344
if (old_value != var->save_result.plugin)
3346
*value= my_plugin_lock(NULL, &var->save_result.plugin);
3347
plugin_unlock(NULL, old_value);
3353
sys_var_thd_optimizer_switch::
3354
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
3356
char buff[STRING_BUFFER_USUAL_SIZE*8];
3357
String tmp(buff, sizeof(buff), &my_charset_latin1);
3361
for (uint i= 0; val; val>>= 1, i++)
3365
tmp.append(optimizer_switch_typelib.type_names[i],
3366
optimizer_switch_typelib.type_lengths[i]);
3372
tmp.length(tmp.length() - 1); /* trim the trailing comma */
3374
rep->str= thd->strmake(tmp.ptr(), tmp.length());
3376
rep->length= rep->str ? tmp.length() : 0;
3378
return rep->length != tmp.length();
3382
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3383
LEX_STRING *base __attribute__((__unused__)))
3386
uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3387
thd->variables.*offset);
3388
(void) symbolic_mode_representation(thd, val, &opts);
3389
return (uchar *) opts.str;
3393
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
3395
if (type == OPT_GLOBAL)
3396
global_system_variables.*offset= 0;
3398
thd->variables.*offset= global_system_variables.*offset;
3402
/****************************************************************************
3404
****************************************************************************/
3406
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3409
I_List_iterator<NAMED_LIST> it(*list);
3410
NAMED_LIST *element;
3411
while ((element= it++))
3413
if (element->cmp(name, length))
3417
return element->data;
3424
void delete_elements(I_List<NAMED_LIST> *list,
3425
void (*free_element)(const char *name, uchar*))
3427
NAMED_LIST *element;
3428
while ((element= list->get()))
3430
(*free_element)(element->name, element->data);
3437
/* Key cache functions */
3439
static KEY_CACHE *create_key_cache(const char *name, uint length)
3441
KEY_CACHE *key_cache;
3443
if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3444
MYF(MY_ZEROFILL | MY_WME))))
3446
if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3448
my_free((char*) key_cache, MYF(0));
3454
Set default values for a key cache
3455
The values in dflt_key_cache_var is set by my_getopt() at startup
3457
We don't set 'buff_size' as this is used to enable the key cache
3459
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
3460
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
3461
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
3468
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3470
LEX_STRING key_cache_name;
3471
KEY_CACHE *key_cache;
3473
key_cache_name.str= (char *) name;
3474
key_cache_name.length= length;
3475
pthread_mutex_lock(&LOCK_global_system_variables);
3476
if (!(key_cache= get_key_cache(&key_cache_name)))
3477
key_cache= create_key_cache(name, length);
3478
pthread_mutex_unlock(&LOCK_global_system_variables);
3483
void free_key_cache(const char *name __attribute__((__unused__)),
3484
KEY_CACHE *key_cache)
3486
ha_end_key_cache(key_cache);
3487
my_free((char*) key_cache, MYF(0));
3491
bool process_key_caches(process_key_cache_t func)
3493
I_List_iterator<NAMED_LIST> it(key_caches);
3494
NAMED_LIST *element;
3496
while ((element= it++))
3498
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3499
func(element->name, key_cache);
3505
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
3509
/* Prevent self dead-lock */
3510
if (thd->locked_tables || thd->active_transaction())
3512
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3516
if (thd->global_read_lock)
3519
This connection already holds the global read lock.
3520
This can be the case with:
3521
- FLUSH TABLES WITH READ LOCK
3522
- SET GLOBAL READ_ONLY = 1
3524
result= sys_var_bool_ptr::update(thd, var);
3529
Perform a 'FLUSH TABLES WITH READ LOCK'.
3530
This is a 3 step process:
3531
- [1] lock_global_read_lock()
3532
- [2] close_cached_tables()
3533
- [3] make_global_read_lock_block_commit()
3534
[1] prevents new connections from obtaining tables locked for write.
3535
[2] waits until all existing connections close their tables.
3536
[3] prevents transactions from being committed.
3539
if (lock_global_read_lock(thd))
3543
This call will be blocked by any connection holding a READ or WRITE lock.
3544
Ideally, we want to wait only for pending WRITE locks, but since:
3545
con 1> LOCK TABLE T FOR READ;
3546
con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3547
con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3548
can cause to wait on a read lock, it's required for the client application
3549
to unlock everything, and acceptable for the server to wait on all locks.
3551
if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
3552
goto end_with_read_lock;
3554
if ((result= make_global_read_lock_block_commit(thd)) == true)
3555
goto end_with_read_lock;
3557
/* Change the opt_readonly system variable, safe because the lock is held */
3558
result= sys_var_bool_ptr::update(thd, var);
3561
/* Release the lock */
3562
unlock_global_read_lock(thd);
3566
/****************************************************************************
3568
****************************************************************************/
3570
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3571
template class List<set_var_base>;
3572
template class List_iterator_fast<set_var_base>;
3573
template class I_List_iterator<NAMED_LIST>;