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_variable sys_have_dlopen(&vars, "have_dynamic_loading", &have_dlopen);
588
static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
589
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
590
/* Global read-only variable describing server license */
591
static sys_var_const_str sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
592
/* Global variables which enable|disable logging */
593
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
595
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
596
static sys_var_log_state sys_var_log(&vars, "log", &opt_log, QUERY_LOG_GENERAL);
597
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
599
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
600
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
601
&opt_slow_log, QUERY_LOG_SLOW);
602
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
603
sys_update_general_log_path,
604
sys_default_general_log_path,
606
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
607
sys_update_slow_log_path,
608
sys_default_slow_log_path,
610
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
611
&log_output_typelib, 0);
615
Additional variables (not derived from sys_var class, not accessible as
616
@@varname in SELECT or SET). Sorted in alphabetical order to facilitate
617
maintenance - SHOW VARIABLES will sort its output.
618
TODO: remove this list completely
621
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
622
static SHOW_VAR fixed_vars[]= {
623
{"back_log", (char*) &back_log, SHOW_LONG},
624
{"character_sets_dir", mysql_charsets_dir, SHOW_CHAR},
625
{"init_file", (char*) &opt_init_file, SHOW_CHAR_PTR},
626
{"language", language, SHOW_CHAR},
628
{"locked_in_memory", (char*) &locked_in_memory, SHOW_MY_BOOL},
630
{"log_bin", (char*) &opt_bin_log, SHOW_BOOL},
631
{"log_error", (char*) log_error_file, SHOW_CHAR},
632
{"lower_case_file_system", (char*) &lower_case_file_system, SHOW_MY_BOOL},
633
{"lower_case_table_names", (char*) &lower_case_table_names, SHOW_INT},
634
{"myisam_recover_options", (char*) &myisam_recover_options_str, SHOW_CHAR_PTR},
635
{"open_files_limit", (char*) &open_files_limit, SHOW_LONG},
636
{"pid_file", (char*) pidfile_name, SHOW_CHAR},
637
{"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR},
638
{"port", (char*) &mysqld_port, SHOW_INT},
639
{"protocol_version", (char*) &protocol_version, SHOW_INT},
640
{"skip_networking", (char*) &opt_disable_networking, SHOW_BOOL},
641
{"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL},
642
{"thread_stack", (char*) &my_thread_stack_size, SHOW_LONG},
646
bool sys_var::check(THD *thd __attribute__((__unused__)), set_var *var)
648
var->save_result.uint64_t_value= var->value->val_int();
337
bool sys_var_str::check(Session *session, set_var *var)
652
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());
658
if ((res=(*check_func)(thd, var)) < 0)
659
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
660
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
665
Functions to check and update variables
670
Update variables 'init_connect, init_slave'.
672
In case of 'DEFAULT' value
673
(for example: 'set GLOBAL init_connect=DEFAULT')
674
'var' parameter is NULL pointer.
677
bool update_sys_var_str(sys_var_str *var_str, rw_lock_t *var_mutex,
680
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
681
uint new_length= (var ? var->value->str_value.length() : 0);
683
old_value= (char*) "";
684
if (!(res= my_strndup(old_value, new_length, MYF(0))))
687
Replace the old value in such a way that the any thread using
690
rw_wrlock(var_mutex);
691
old_value= var_str->value;
693
var_str->value_length= new_length;
694
rw_unlock(var_mutex);
695
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
700
static bool sys_update_init_connect(THD *thd __attribute__((__unused__)), set_var *var)
702
return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
706
static void sys_default_init_connect(THD* thd __attribute__((__unused__)),
707
enum_var_type type __attribute__((__unused__)))
709
update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
713
static bool sys_update_init_slave(THD *thd __attribute__((__unused__)),
716
return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
720
static void sys_default_init_slave(THD* thd __attribute__((__unused__)),
721
enum_var_type type __attribute__((__unused__)))
723
update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
728
If one sets the LOW_PRIORIY UPDATES flag, we also must change the
732
static void fix_low_priority_updates(THD *thd, enum_var_type type)
734
if (type == OPT_GLOBAL)
735
thr_upgraded_concurrent_insert_lock=
736
(global_system_variables.low_priority_updates ?
737
TL_WRITE_LOW_PRIORITY : TL_WRITE);
739
thd->update_lock_default= (thd->variables.low_priority_updates ?
740
TL_WRITE_LOW_PRIORITY : TL_WRITE);
745
fix_myisam_max_sort_file_size(THD *thd __attribute__((__unused__)),
746
enum_var_type type __attribute__((__unused__)))
748
myisam_max_temp_length=
749
(my_off_t) global_system_variables.myisam_max_sort_file_size;
370
753
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)
756
static void fix_max_join_size(THD *thd, enum_var_type type)
375
758
if (type != OPT_GLOBAL)
377
if (session->variables.max_join_size == HA_POS_ERROR)
378
session->options|= OPTION_BIG_SELECTS;
760
if (thd->variables.max_join_size == HA_POS_ERROR)
761
thd->options|= OPTION_BIG_SELECTS;
380
session->options&= ~OPTION_BIG_SELECTS;
763
thd->options&= ~OPTION_BIG_SELECTS;
400
783
If one doesn't use the SESSION modifier, the isolation level
401
784
is only active for the next command.
403
static void fix_tx_isolation(Session *session, sql_var_t type)
786
static void fix_tx_isolation(THD *thd, enum_var_type type)
405
788
if (type == OPT_SESSION)
406
session->session_tx_isolation= ((enum_tx_isolation)
407
session->variables.tx_isolation);
789
thd->session_tx_isolation= ((enum_tx_isolation)
790
thd->variables.tx_isolation);
410
static void fix_completion_type(Session *, sql_var_t) {}
793
static void fix_completion_type(THD *thd __attribute__((unused)),
794
enum_var_type type __attribute__((unused))) {}
412
static int check_completion_type(Session *, set_var *var)
796
static int check_completion_type(THD *thd __attribute__((__unused__)),
414
799
int64_t val= var->value->val_int();
415
800
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)
803
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
811
If we are changing the thread variable, we have to copy it to NET too
814
#ifdef HAVE_REPLICATION
815
static void fix_net_read_timeout(THD *thd, enum_var_type type)
817
if (type != OPT_GLOBAL)
818
my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
822
static void fix_net_write_timeout(THD *thd, enum_var_type type)
824
if (type != OPT_GLOBAL)
825
my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
828
static void fix_net_retry_count(THD *thd, enum_var_type type)
830
if (type != OPT_GLOBAL)
831
thd->net.retry_count=thd->variables.net_retry_count;
833
#else /* HAVE_REPLICATION */
834
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
835
enum_var_type type __attribute__((unused)))
837
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
838
enum_var_type type __attribute__((unused)))
840
static void fix_net_retry_count(THD *thd __attribute__((unused)),
841
enum_var_type type __attribute__((unused)))
843
#endif /* HAVE_REPLICATION */
846
extern void fix_delay_key_write(THD *thd __attribute__((__unused__)),
847
enum_var_type type __attribute__((__unused__)))
849
switch ((enum_delay_key_write) delay_key_write_options) {
850
case DELAY_KEY_WRITE_NONE:
851
myisam_delay_key_write=0;
853
case DELAY_KEY_WRITE_ON:
854
myisam_delay_key_write=1;
856
case DELAY_KEY_WRITE_ALL:
857
myisam_delay_key_write=1;
858
ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
863
bool sys_var_set::update(THD *thd __attribute__((__unused__)),
866
*value= var->save_result.ulong_value;
870
uchar *sys_var_set::value_ptr(THD *thd,
871
enum_var_type type __attribute__((__unused__)),
872
LEX_STRING *base __attribute__((__unused__)))
875
String tmp(buff, sizeof(buff), &my_charset_latin1);
880
for (uint i= 0; val; val>>= 1, i++)
884
tmp.append(enum_names->type_names[i],
885
enum_names->type_lengths[i]);
890
if ((length= tmp.length()))
892
return (uchar*) thd->strmake(tmp.ptr(), length);
895
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((__unused__)),
896
enum_var_type type __attribute__((__unused__)))
898
slave_exec_mode_options= 0;
899
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
902
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
904
bool rc= sys_var_set::check(thd, var);
906
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
907
bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
910
my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
915
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
918
pthread_mutex_lock(&LOCK_global_system_variables);
919
rc= sys_var_set::update(thd, var);
920
pthread_mutex_unlock(&LOCK_global_system_variables);
924
void fix_slave_exec_mode(enum_var_type type __attribute__((__unused__)))
926
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
927
bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
929
sql_print_error("Ambiguous slave modes combination."
930
" STRICT will be used");
931
bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
933
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
934
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
937
bool sys_var_thd_binlog_format::is_readonly() const
940
Under certain circumstances, the variable is read-only (unchangeable):
942
THD *thd= current_thd;
944
If RBR and open temporary tables, their CREATE TABLE may not be in the
945
binlog, so we can't toggle to SBR in this connection.
946
The test below will also prevent SET GLOBAL, well it was not easy to test
947
if global or not here.
948
And this test will also prevent switching from RBR to RBR (a no-op which
949
should not happen too often).
951
If we don't have row-based replication compiled in, the variable
954
if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
955
thd->temporary_tables)
957
my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
961
if in a stored function/trigger, it's too late to change mode
963
if (thd->in_sub_stmt)
965
my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
968
return sys_var_thd_enum::is_readonly();
972
void fix_binlog_format_after_update(THD *thd,
973
enum_var_type type __attribute__((__unused__)))
975
thd->reset_current_stmt_binlog_row_based();
979
static void fix_max_binlog_size(THD *thd __attribute__((__unused__)),
980
enum_var_type type __attribute__((__unused__)))
982
mysql_bin_log.set_max_size(max_binlog_size);
983
#ifdef HAVE_REPLICATION
984
if (!max_relay_log_size)
985
active_mi->rli.relay_log.set_max_size(max_binlog_size);
990
static void fix_max_relay_log_size(THD *thd __attribute__((__unused__)),
991
enum_var_type type __attribute__((__unused__)))
993
#ifdef HAVE_REPLICATION
994
active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
995
max_relay_log_size: max_binlog_size);
1000
static void fix_max_connections(THD *thd __attribute__((__unused__)),
1001
enum_var_type type __attribute__((__unused__)))
1003
resize_thr_alarm(max_connections + 10);
1007
static void fix_thd_mem_root(THD *thd, enum_var_type type)
1009
if (type != OPT_GLOBAL)
1010
reset_root_defaults(thd->mem_root,
1011
thd->variables.query_alloc_block_size,
1012
thd->variables.query_prealloc_size);
1016
static void fix_trans_mem_root(THD *thd, enum_var_type type)
1018
if (type != OPT_GLOBAL)
1019
reset_root_defaults(&thd->transaction.mem_root,
1020
thd->variables.trans_alloc_block_size,
1021
thd->variables.trans_prealloc_size);
1025
static void fix_server_id(THD *thd __attribute__((__unused__)),
1026
enum_var_type type __attribute__((__unused__)))
1028
server_id_supplied = 1;
1029
thd->server_id= server_id;
1033
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
1034
const char *name, int64_t val)
443
char buf[DECIMAL_LONGLONG_DIGITS];
446
internal::ullstr((uint64_t) val, buf);
1041
ullstr((uint64_t) val, buf);
448
internal::llstr(val, buf);
450
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
1045
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
451
1046
ER_TRUNCATED_WRONG_VALUE,
452
ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
1047
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
457
uint64_t fix_unsigned(Session *session, uint64_t num,
458
const struct option *option_limits)
1052
static uint64_t fix_unsigned(THD *thd, uint64_t num,
1053
const struct my_option *option_limits)
460
1055
bool fixed= false;
461
1056
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,
1058
throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
1062
static bool get_unsigned(THD *thd __attribute__((__unused__)), set_var *var)
1064
if (var->value->unsigned_flag)
1065
var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
1068
int64_t v= var->value->val_int();
1069
var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
1076
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
1077
sys_after_update_func after_update_arg)
1078
:sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
1079
&LOCK_global_system_variables, after_update_arg)
1083
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
1085
return get_unsigned(thd, var);
1088
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
1090
uint64_t tmp= var->save_result.uint64_t_value;
1091
pthread_mutex_lock(guard);
1093
*value= (ulong) fix_unsigned(thd, tmp, option_limits);
1096
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1097
/* Avoid overflows on 32 bit systems */
1098
if (tmp > ULONG_MAX)
1101
throw_bounds_warning(thd, true, true, name,
1102
(int64_t) var->save_result.uint64_t_value);
1105
*value= (ulong) tmp;
1108
pthread_mutex_unlock(guard);
1113
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
1116
pthread_mutex_lock(guard);
1117
*value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
569
1118
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();
1119
pthread_mutex_unlock(guard);
1123
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
1125
uint64_t tmp= var->save_result.uint64_t_value;
1126
pthread_mutex_lock(&LOCK_global_system_variables);
1128
*value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
1130
*value= (uint64_t) tmp;
1131
pthread_mutex_unlock(&LOCK_global_system_variables);
1136
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((__unused__)),
1137
enum_var_type type __attribute__((__unused__)))
1140
pthread_mutex_lock(&LOCK_global_system_variables);
1141
*value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
1142
option_limits, ¬_used);
1143
pthread_mutex_unlock(&LOCK_global_system_variables);
1147
bool sys_var_bool_ptr::update(THD *thd __attribute__((__unused__)), set_var *var)
1149
*value= (bool) var->save_result.ulong_value;
1154
void sys_var_bool_ptr::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
1156
*value= (bool) option_limits->def_value;
1160
bool sys_var_enum::update(THD *thd __attribute__((__unused__)), set_var *var)
1162
*value= (uint) var->save_result.ulong_value;
1167
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((__unused__)),
1168
enum_var_type type __attribute__((__unused__)),
1169
LEX_STRING *base __attribute__((__unused__)))
1171
return (uchar*) enum_names->type_names[*value];
1175
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((__unused__)),
1176
enum_var_type type __attribute__((__unused__)),
1177
LEX_STRING *base __attribute__((__unused__)))
1179
return (uchar*) enum_names->type_names[global_system_variables.*offset];
1182
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1184
return (get_unsigned(thd, var) ||
1185
(check_func && (*check_func)(thd, var)));
1188
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
1190
uint64_t tmp= var->save_result.uint64_t_value;
603
1192
/* Don't use bigger value than given with --maximum-variable-name=.. */
604
if ((uint32_t) tmp > max_system_variables.*offset)
1193
if ((ulong) tmp > max_system_variables.*offset)
606
throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
1195
throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
607
1196
tmp= max_system_variables.*offset;
610
1199
if (option_limits)
611
tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
612
else if (tmp > UINT32_MAX)
1200
tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1201
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1202
else if (tmp > ULONG_MAX)
615
throw_bounds_warning(session, true, true, getName(), int64_t(var->getInteger()));
1205
throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
618
1209
if (var->type == OPT_GLOBAL)
619
global_system_variables.*offset= (uint32_t) tmp;
1210
global_system_variables.*offset= (ulong) tmp;
621
session->variables.*offset= (uint32_t) tmp;
1212
thd->variables.*offset= (ulong) tmp;
627
void sys_var_session_uint32_t::set_default(Session *session, sql_var_t type)
1218
void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
629
1220
if (type == OPT_GLOBAL)
632
1223
/* We will not come here if option_limits is not set */
633
1224
global_system_variables.*offset=
634
(uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
1225
(ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
635
1226
option_limits, ¬_used);
638
session->variables.*offset= global_system_variables.*offset;
1229
thd->variables.*offset= global_system_variables.*offset;
642
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
1233
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1234
LEX_STRING *base __attribute__((__unused__)))
646
1236
if (type == OPT_GLOBAL)
647
return (unsigned char*) &(global_system_variables.*offset);
648
return (unsigned char*) &(session->variables.*offset);
1237
return (uchar*) &(global_system_variables.*offset);
1238
return (uchar*) &(thd->variables.*offset);
652
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1242
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
654
uint64_t tmp= var->getInteger();
1244
uint64_t tmp= var->save_result.uint64_t_value;
656
1246
/* Don't use bigger value than given with --maximum-variable-name=.. */
657
1247
if ((ha_rows) tmp > max_system_variables.*offset)
658
1248
tmp= max_system_variables.*offset;
660
1250
if (option_limits)
661
tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1251
tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
662
1252
if (var->type == OPT_GLOBAL)
664
1254
/* Lock is needed to make things safe on 32 bit systems */
665
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1255
pthread_mutex_lock(&LOCK_global_system_variables);
666
1256
global_system_variables.*offset= (ha_rows) tmp;
1257
pthread_mutex_unlock(&LOCK_global_system_variables);
670
session->variables.*offset= (ha_rows) tmp;
1260
thd->variables.*offset= (ha_rows) tmp;
677
void sys_var_session_ha_rows::set_default(Session *session, sql_var_t type)
1265
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
679
1267
if (type == OPT_GLOBAL)
682
1270
/* We will not come here if option_limits is not set */
683
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1271
pthread_mutex_lock(&LOCK_global_system_variables);
684
1272
global_system_variables.*offset=
685
1273
(ha_rows) getopt_ull_limit_value((ha_rows) option_limits->def_value,
686
1274
option_limits, ¬_used);
1275
pthread_mutex_unlock(&LOCK_global_system_variables);
690
session->variables.*offset= global_system_variables.*offset;
1278
thd->variables.*offset= global_system_variables.*offset;
695
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
1282
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1283
LEX_STRING *base __attribute__((__unused__)))
699
1285
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();
1286
return (uchar*) &(global_system_variables.*offset);
1287
return (uchar*) &(thd->variables.*offset);
1290
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
1292
return get_unsigned(thd, var);
1295
bool sys_var_thd_uint64_t::update(THD *thd, set_var *var)
1297
uint64_t tmp= var->save_result.uint64_t_value;
714
1299
if (tmp > max_system_variables.*offset)
716
throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
717
1300
tmp= max_system_variables.*offset;
720
1302
if (option_limits)
721
tmp= fix_unsigned(session, tmp, option_limits);
1303
tmp= fix_unsigned(thd, tmp, option_limits);
722
1304
if (var->type == OPT_GLOBAL)
724
1306
/* Lock is needed to make things safe on 32 bit systems */
725
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1307
pthread_mutex_lock(&LOCK_global_system_variables);
726
1308
global_system_variables.*offset= (uint64_t) tmp;
1309
pthread_mutex_unlock(&LOCK_global_system_variables);
730
session->variables.*offset= (uint64_t) tmp;
1312
thd->variables.*offset= (uint64_t) tmp;
737
void sys_var_session_uint64_t::set_default(Session *session, sql_var_t type)
1317
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
739
1319
if (type == OPT_GLOBAL)
742
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
1322
pthread_mutex_lock(&LOCK_global_system_variables);
743
1323
global_system_variables.*offset=
744
1324
getopt_ull_limit_value((uint64_t) option_limits->def_value,
745
1325
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 *,
1326
pthread_mutex_unlock(&LOCK_global_system_variables);
1329
thd->variables.*offset= global_system_variables.*offset;
1333
uchar *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1334
LEX_STRING *base __attribute__((__unused__)))
1336
if (type == OPT_GLOBAL)
1337
return (uchar*) &(global_system_variables.*offset);
1338
return (uchar*) &(thd->variables.*offset);
1342
bool sys_var_thd_bool::update(THD *thd, set_var *var)
1344
if (var->type == OPT_GLOBAL)
1345
global_system_variables.*offset= (my_bool) var->save_result.ulong_value;
1347
thd->variables.*offset= (my_bool) var->save_result.ulong_value;
1352
void sys_var_thd_bool::set_default(THD *thd, enum_var_type type)
1354
if (type == OPT_GLOBAL)
1355
global_system_variables.*offset= (my_bool) option_limits->def_value;
1357
thd->variables.*offset= global_system_variables.*offset;
1361
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1362
LEX_STRING *base __attribute__((__unused__)))
1364
if (type == OPT_GLOBAL)
1365
return (uchar*) &(global_system_variables.*offset);
1366
return (uchar*) &(thd->variables.*offset);
1370
bool sys_var::check_enum(THD *thd __attribute__((__unused__)),
855
1371
set_var *var, const TYPELIB *enum_names)
857
1373
char buff[STRING_BUFFER_USUAL_SIZE];
999
1574
tmp= new Item_null();
1000
1575
tmp->collation.set(system_charset_info, DERIVATION_SYSCONST);
1577
pthread_mutex_unlock(&LOCK_global_system_variables);
1006
my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
1581
my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
1012
bool sys_var_session_enum::update(Session *session, set_var *var)
1587
bool sys_var_thd_enum::update(THD *thd, set_var *var)
1014
1589
if (var->type == OPT_GLOBAL)
1015
global_system_variables.*offset= var->getInteger();
1590
global_system_variables.*offset= var->save_result.ulong_value;
1017
session->variables.*offset= var->getInteger();
1592
thd->variables.*offset= var->save_result.ulong_value;
1022
void sys_var_session_enum::set_default(Session *session, sql_var_t type)
1597
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
1024
1599
if (type == OPT_GLOBAL)
1025
global_system_variables.*offset= (uint32_t) option_limits->def_value;
1600
global_system_variables.*offset= (ulong) option_limits->def_value;
1027
session->variables.*offset= global_system_variables.*offset;
1602
thd->variables.*offset= global_system_variables.*offset;
1031
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1606
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1607
LEX_STRING *base __attribute__((__unused__)))
1035
uint32_t tmp= ((type == OPT_GLOBAL) ?
1609
ulong tmp= ((type == OPT_GLOBAL) ?
1036
1610
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);
1611
thd->variables.*offset);
1612
return (uchar*) enum_names->type_names[tmp];
1615
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1617
return (check_enum(thd, var, &bool_typelib) ||
1618
(check_func && (*check_func)(thd, var)));
1621
bool sys_var_thd_bit::update(THD *thd, set_var *var)
1623
int res= (*update_func)(thd, var);
1054
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t,
1628
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1629
enum_var_type type __attribute__((__unused__)),
1630
LEX_STRING *base __attribute__((__unused__)))
1058
1633
If reverse is 0 (default) return 1 if bit is set.
1059
1634
If reverse is 1, return 0 if bit is set
1061
session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1636
thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ?
1062
1637
!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;
1638
return (uchar*) &thd->sys_var_tmp.my_bool_value;
1642
/** Update a date_time format variable based on given value. */
1644
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
1645
DATE_TIME_FORMAT *new_value)
1647
DATE_TIME_FORMAT *old;
1649
if (type == OPT_GLOBAL)
1651
pthread_mutex_lock(&LOCK_global_system_variables);
1652
old= (global_system_variables.*offset);
1653
(global_system_variables.*offset)= new_value;
1654
pthread_mutex_unlock(&LOCK_global_system_variables);
1658
old= (thd->variables.*offset);
1659
(thd->variables.*offset)= new_value;
1661
my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
1666
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
1668
DATE_TIME_FORMAT *new_value;
1669
/* We must make a copy of the last value to get it into normal memory */
1670
new_value= date_time_format_copy((THD*) 0,
1671
var->save_result.date_time_format);
1673
return 1; // Out of memory
1674
update2(thd, var->type, new_value); // Can't fail
1679
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
1681
char buff[STRING_BUFFER_USUAL_SIZE];
1682
String str(buff,sizeof(buff), system_charset_info), *res;
1683
DATE_TIME_FORMAT *format;
1685
if (!(res=var->value->val_str(&str)))
1686
res= &my_empty_string;
1688
if (!(format= date_time_format_make(date_time_type,
1689
res->ptr(), res->length())))
1691
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
1696
We must copy result to thread space to not get a memory leak if
1699
var->save_result.date_time_format= date_time_format_copy(thd, format);
1700
my_free((char*) format, MYF(0));
1701
return var->save_result.date_time_format == 0;
1705
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
1707
DATE_TIME_FORMAT *res= 0;
1709
if (type == OPT_GLOBAL)
1712
if ((format= opt_date_time_formats[date_time_type]))
1713
res= date_time_format_make(date_time_type, format, strlen(format));
1717
/* Make copy with malloc */
1718
res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
1721
if (res) // Should always be true
1722
update2(thd, type, res);
1726
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1727
LEX_STRING *base __attribute__((__unused__)))
1729
if (type == OPT_GLOBAL)
1733
We do a copy here just to be sure things will work even if someone
1734
is modifying the original string while the copy is accessed
1735
(Can't happen now in SQL SHOW, but this is a good safety for the future)
1737
res= thd->strmake((global_system_variables.*offset)->format.str,
1738
(global_system_variables.*offset)->format.length);
1739
return (uchar*) res;
1741
return (uchar*) (thd->variables.*offset)->format.str;
1745
typedef struct old_names_map_st
1747
const char *old_name;
1748
const char *new_name;
1751
static my_old_conv old_conv[]=
1753
{ "cp1251_koi8" , "cp1251" },
1754
{ "cp1250_latin2" , "cp1250" },
1755
{ "kam_latin2" , "keybcs2" },
1756
{ "mac_latin2" , "MacRoman" },
1757
{ "macce_latin2" , "MacCE" },
1758
{ "pc2_latin2" , "pclatin2" },
1759
{ "vga_latin2" , "pclatin1" },
1760
{ "koi8_cp1251" , "koi8r" },
1761
{ "win1251ukr_koi8_ukr" , "win1251ukr" },
1762
{ "koi8_ukr_win1251ukr" , "koi8u" },
1766
CHARSET_INFO *get_old_charset_by_name(const char *name)
1770
for (conv= old_conv; conv->old_name; conv++)
1772
if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
1773
return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
1779
bool sys_var_collation::check(THD *thd __attribute__((__unused__)),
1071
1784
if (var->value->result_type() == STRING_RESULT)
1074
1787
String str(buff,sizeof(buff), system_charset_info), *res;
1075
1788
if (!(res=var->value->val_str(&str)))
1077
boost::throw_exception(invalid_option_value(var->var->getName()) << invalid_value(std::string("NULL")));
1790
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1080
if (!(tmp=get_charset_by_name(res->c_ptr())))
1793
if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0))))
1082
1795
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
1799
else // INT_RESULT
1089
if (!(tmp=get_charset((int) var->value->val_int())))
1801
if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1092
internal::int10_to_str((int) var->value->val_int(), buf, -10);
1804
int10_to_str((int) var->value->val_int(), buf, -10);
1093
1805
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())));
1809
var->save_result.charset= tmp; // Save for update
1814
bool sys_var_character_set::check(THD *thd __attribute__((__unused__)),
1819
if (var->value->result_type() == STRING_RESULT)
1821
char buff[STRING_BUFFER_USUAL_SIZE];
1822
String str(buff,sizeof(buff), system_charset_info), *res;
1823
if (!(res=var->value->val_str(&str)))
1827
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1832
else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
1833
!(tmp=get_old_charset_by_name(res->c_ptr())))
1835
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
1841
if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1844
int10_to_str((int) var->value->val_int(), buf, -10);
1845
my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf);
1849
var->save_result.charset= tmp; // Save for update
1854
bool sys_var_character_set::update(THD *thd, set_var *var)
1856
ci_ptr(thd,var->type)[0]= var->save_result.charset;
1857
thd->update_charset();
1862
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1863
LEX_STRING *base __attribute__((__unused__)))
1865
CHARSET_INFO *cs= ci_ptr(thd,type)[0];
1866
return cs ? (uchar*) cs->csname : (uchar*) NULL;
1870
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
1872
if (type == OPT_GLOBAL)
1873
global_system_variables.*offset= *global_default;
1876
thd->variables.*offset= global_system_variables.*offset;
1877
thd->update_charset();
1880
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1882
if (type == OPT_GLOBAL)
1883
return &(global_system_variables.*offset);
1885
return &(thd->variables.*offset);
1889
bool sys_var_character_set_client::check(THD *thd, set_var *var)
1891
if (sys_var_character_set_sv::check(thd, var))
1893
/* Currently, UCS-2 cannot be used as a client character set */
1894
if (var->save_result.charset->mbminlen > 1)
1896
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name,
1897
var->save_result.charset->csname);
1904
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1907
if (type == OPT_GLOBAL)
1908
return &global_system_variables.collation_database;
1910
return &thd->variables.collation_database;
1914
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
1916
if (type == OPT_GLOBAL)
1917
global_system_variables.collation_database= default_charset_info;
1920
thd->variables.collation_database= thd->db_charset;
1921
thd->update_charset();
1926
bool sys_var_collation_sv::update(THD *thd, set_var *var)
1098
1928
if (var->type == OPT_GLOBAL)
1099
global_system_variables.*offset= tmp;
1929
global_system_variables.*offset= var->save_result.charset;
1102
session->variables.*offset= tmp;
1932
thd->variables.*offset= var->save_result.charset;
1933
thd->update_charset();
1108
void sys_var_collation_sv::set_default(Session *session, sql_var_t type)
1939
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
1110
1941
if (type == OPT_GLOBAL)
1111
1942
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";
1945
thd->variables.*offset= global_system_variables.*offset;
1946
thd->update_charset();
1951
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1952
LEX_STRING *base __attribute__((__unused__)))
1954
CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1955
global_system_variables.*offset : thd->variables.*offset);
1956
return cs ? (uchar*) cs->name : (uchar*) "NULL";
1960
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1962
static KEY_CACHE zero_key_cache;
1964
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
1966
safe_mutex_assert_owner(&LOCK_global_system_variables);
1967
if (!cache_name || ! cache_name->length)
1968
cache_name= &default_key_cache_base;
1969
return ((KEY_CACHE*) find_named(&key_caches,
1970
cache_name->str, cache_name->length, 0));
1974
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((__unused__)),
1975
enum_var_type type __attribute__((__unused__)),
1976
LEX_STRING *base __attribute__((__unused__)))
1978
KEY_CACHE *key_cache= get_key_cache(base);
1980
key_cache= &zero_key_cache;
1981
return (uchar*) key_cache + offset ;
1985
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1987
uint64_t tmp= var->save_result.uint64_t_value;
1988
LEX_STRING *base_name= &var->base;
1989
KEY_CACHE *key_cache;
1992
/* If no basename, assume it's for the key cache named 'default' */
1993
if (!base_name->length)
1994
base_name= &default_key_cache_base;
1996
pthread_mutex_lock(&LOCK_global_system_variables);
1997
key_cache= get_key_cache(base_name);
2001
/* Key cache didn't exists */
2002
if (!tmp) // Tried to delete cache
2003
goto end; // Ok, nothing to do
2004
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
2012
Abort if some other thread is changing the key cache
2013
TODO: This should be changed so that we wait until the previous
2014
assignment is done and then do the new assign
2016
if (key_cache->in_init)
2019
if (!tmp) // Zero size means delete
2021
if (key_cache == dflt_key_cache)
2023
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2024
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
2025
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
2026
goto end; // Ignore default key cache
2029
if (key_cache->key_cache_inited) // If initied
2032
Move tables using this key cache to the default key cache
2033
and clear the old key cache.
2036
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
2037
base_name->length, &list);
2038
key_cache->in_init= 1;
2039
pthread_mutex_unlock(&LOCK_global_system_variables);
2040
error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
2041
pthread_mutex_lock(&LOCK_global_system_variables);
2042
key_cache->in_init= 0;
2045
We don't delete the key cache as some running threads my still be
2046
in the key cache code with a pointer to the deleted (empty) key cache
2051
key_cache->param_buff_size=
2052
(uint64_t) fix_unsigned(thd, tmp, option_limits);
2054
/* If key cache didn't existed initialize it, else resize it */
2055
key_cache->in_init= 1;
2056
pthread_mutex_unlock(&LOCK_global_system_variables);
2058
if (!key_cache->key_cache_inited)
2059
error= (bool) (ha_init_key_cache("", key_cache));
2061
error= (bool)(ha_resize_key_cache(key_cache));
2063
pthread_mutex_lock(&LOCK_global_system_variables);
2064
key_cache->in_init= 0;
2067
pthread_mutex_unlock(&LOCK_global_system_variables);
2074
Abort if some other thread is changing the key cache.
2075
This should be changed so that we wait until the previous
2076
assignment is done and then do the new assign
2078
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
2080
ulong tmp= (ulong) var->value->val_int();
2081
LEX_STRING *base_name= &var->base;
2084
if (!base_name->length)
2085
base_name= &default_key_cache_base;
2087
pthread_mutex_lock(&LOCK_global_system_variables);
2088
KEY_CACHE *key_cache= get_key_cache(base_name);
2090
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
2091
base_name->length)))
2098
Abort if some other thread is changing the key cache
2099
TODO: This should be changed so that we wait until the previous
2100
assignment is done and then do the new assign
2102
if (key_cache->in_init)
2105
*((ulong*) (((char*) key_cache) + offset))=
2106
(ulong) fix_unsigned(thd, tmp, option_limits);
2109
Don't create a new key cache if it didn't exist
2110
(key_caches are created only when the user sets block_size)
2112
key_cache->in_init= 1;
2114
pthread_mutex_unlock(&LOCK_global_system_variables);
2116
error= (bool) (ha_resize_key_cache(key_cache));
2118
pthread_mutex_lock(&LOCK_global_system_variables);
2119
key_cache->in_init= 0;
2122
pthread_mutex_unlock(&LOCK_global_system_variables);
2127
bool sys_var_log_state::update(THD *thd, set_var *var)
2130
pthread_mutex_lock(&LOCK_global_system_variables);
2131
if (!var->save_result.ulong_value)
2133
logger.deactivate_log_handler(thd, log_type);
2137
res= logger.activate_log_handler(thd, log_type);
2138
pthread_mutex_unlock(&LOCK_global_system_variables);
2142
void sys_var_log_state::set_default(THD *thd,
2143
enum_var_type type __attribute__((__unused__)))
2145
pthread_mutex_lock(&LOCK_global_system_variables);
2146
logger.deactivate_log_handler(thd, log_type);
2147
pthread_mutex_unlock(&LOCK_global_system_variables);
2151
static int sys_check_log_path(THD *thd __attribute__((__unused__)),
2154
char path[FN_REFLEN], buff[FN_REFLEN];
2156
String str(buff, sizeof(buff), system_charset_info), *res;
2157
const char *log_file_str;
2160
if (!(res= var->value->val_str(&str)))
2163
log_file_str= res->c_ptr();
2164
bzero(&f_stat, sizeof(struct stat));
2166
path_length= unpack_filename(path, log_file_str);
2170
/* File name is empty. */
2175
if (!stat(path, &f_stat))
2178
A file system object exists. Check if argument is a file and we have
2182
if (!MY_S_ISREG(f_stat.st_mode) ||
2183
!(f_stat.st_mode & MY_S_IWRITE))
2189
/* Get dirname of the file path. */
2190
(void) dirname_part(path, log_file_str, &path_length);
2192
/* Dirname is empty if file path is relative. */
2197
Check if directory exists and we have permission to create file and
2200
if (my_access(path, (F_OK|W_OK)))
2206
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name,
2207
res ? log_file_str : "NULL");
2212
bool update_sys_var_str_path(THD *thd __attribute__((__unused__)),
2213
sys_var_str *var_str,
2214
set_var *var, const char *log_ext,
2215
bool log_state, uint log_type)
2217
MYSQL_QUERY_LOG *file_log;
2218
char buff[FN_REFLEN];
2219
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2221
uint str_length= (var ? var->value->str_value.length() : 0);
2224
case QUERY_LOG_SLOW:
2225
file_log= logger.get_slow_log_file_handler();
2227
case QUERY_LOG_GENERAL:
2228
file_log= logger.get_log_file_handler();
2231
assert(0); // Impossible
2236
old_value= make_default_log_name(buff, log_ext);
2237
str_length= strlen(old_value);
2239
if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
2245
pthread_mutex_lock(&LOCK_global_system_variables);
2246
logger.lock_exclusive();
2248
if (file_log && log_state)
2250
old_value= var_str->value;
2251
var_str->value= res;
2252
var_str->value_length= str_length;
2253
my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
2254
if (file_log && log_state)
2257
case QUERY_LOG_SLOW:
2258
file_log->open_slow_log(sys_var_slow_log_path.value);
2260
case QUERY_LOG_GENERAL:
2261
file_log->open_query_log(sys_var_general_log_path.value);
2269
pthread_mutex_unlock(&LOCK_global_system_variables);
2276
static bool sys_update_general_log_path(THD *thd, set_var * var)
2278
return update_sys_var_str_path(thd, &sys_var_general_log_path,
2279
var, ".log", opt_log, QUERY_LOG_GENERAL);
2283
static void sys_default_general_log_path(THD *thd,
2284
enum_var_type type __attribute__((__unused__)))
2286
(void) update_sys_var_str_path(thd, &sys_var_general_log_path,
2287
0, ".log", opt_log, QUERY_LOG_GENERAL);
2291
static bool sys_update_slow_log_path(THD *thd, set_var * var)
2293
return update_sys_var_str_path(thd, &sys_var_slow_log_path,
2294
var, "-slow.log", opt_slow_log,
2299
static void sys_default_slow_log_path(THD *thd,
2300
enum_var_type type __attribute__((__unused__)))
2302
(void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
2303
0, "-slow.log", opt_slow_log,
2308
bool sys_var_log_output::update(THD *thd __attribute__((__unused__)),
2311
pthread_mutex_lock(&LOCK_global_system_variables);
2312
logger.lock_exclusive();
2313
logger.init_slow_log(var->save_result.ulong_value);
2314
logger.init_general_log(var->save_result.ulong_value);
2315
*value= var->save_result.ulong_value;
2317
pthread_mutex_unlock(&LOCK_global_system_variables);
2322
void sys_var_log_output::set_default(THD *thd __attribute__((__unused__)),
2323
enum_var_type type __attribute__((__unused__)))
2325
pthread_mutex_lock(&LOCK_global_system_variables);
2326
logger.lock_exclusive();
2327
logger.init_slow_log(LOG_FILE);
2328
logger.init_general_log(LOG_FILE);
2331
pthread_mutex_unlock(&LOCK_global_system_variables);
2335
uchar *sys_var_log_output::value_ptr(THD *thd,
2336
enum_var_type type __attribute__((__unused__)),
2337
LEX_STRING *base __attribute__((__unused__)))
2340
String tmp(buff, sizeof(buff), &my_charset_latin1);
2345
for (uint i= 0; val; val>>= 1, i++)
2349
tmp.append(log_output_typelib.type_names[i],
2350
log_output_typelib.type_lengths[i]);
2355
if ((length= tmp.length()))
2357
return (uchar*) thd->strmake(tmp.ptr(), length);
2361
/*****************************************************************************
2362
Functions to handle SET NAMES and SET CHARACTER SET
2363
*****************************************************************************/
2365
int set_var_collation_client::check(THD *thd __attribute__((__unused__)))
2367
/* Currently, UCS-2 cannot be used as a client character set */
2368
if (character_set_client->mbminlen > 1)
2370
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
2371
character_set_client->csname);
2377
int set_var_collation_client::update(THD *thd)
2379
thd->variables.character_set_client= character_set_client;
2380
thd->variables.character_set_results= character_set_results;
2381
thd->variables.collation_connection= collation_connection;
2382
thd->update_charset();
2383
thd->protocol_text.init(thd);
1129
2387
/****************************************************************************/
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,
2389
bool sys_var_timestamp::update(THD *thd, set_var *var)
2391
thd->set_time((time_t) var->save_result.uint64_t_value);
2396
void sys_var_timestamp::set_default(THD *thd,
2397
enum_var_type type __attribute__((__unused__)))
2403
uchar *sys_var_timestamp::value_ptr(THD *thd,
2404
enum_var_type type __attribute__((__unused__)),
2405
LEX_STRING *base __attribute__((__unused__)))
2407
thd->sys_var_tmp.long_value= (long) thd->start_time;
2408
return (uchar*) &thd->sys_var_tmp.long_value;
2412
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2414
thd->first_successful_insert_id_in_prev_stmt=
2415
var->save_result.uint64_t_value;
2420
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2421
enum_var_type type __attribute__((__unused__)),
2422
LEX_STRING *base __attribute__((__unused__)))
1164
2425
this tmp var makes it robust againt change of type of
1165
2426
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)
2428
thd->sys_var_tmp.uint64_t_value=
2429
thd->read_first_successful_insert_id_in_prev_stmt();
2430
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2434
bool sys_var_insert_id::update(THD *thd, set_var *var)
2436
thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2441
uchar *sys_var_insert_id::value_ptr(THD *thd,
2442
enum_var_type type __attribute__((__unused__)),
2443
LEX_STRING *base __attribute__((__unused__)))
2445
thd->sys_var_tmp.uint64_t_value=
2446
thd->auto_inc_intervals_forced.minimum();
2447
return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2451
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2453
thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2457
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2459
thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2464
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
2466
char buff[MAX_TIME_ZONE_NAME_LENGTH];
2467
String str(buff, sizeof(buff), &my_charset_latin1);
2468
String *res= var->value->val_str(&str);
2470
if (!(var->save_result.time_zone= my_tz_find(thd, res)))
2472
my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2479
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
2481
/* We are using Time_zone object found during check() phase. */
2482
if (var->type == OPT_GLOBAL)
2484
pthread_mutex_lock(&LOCK_global_system_variables);
2485
global_system_variables.time_zone= var->save_result.time_zone;
2486
pthread_mutex_unlock(&LOCK_global_system_variables);
2489
thd->variables.time_zone= var->save_result.time_zone;
2494
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2495
LEX_STRING *base __attribute__((__unused__)))
2498
We can use ptr() instead of c_ptr() here because String contaning
2499
time zone name is guaranteed to be zero ended.
2501
if (type == OPT_GLOBAL)
2502
return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
2506
This is an ugly fix for replication: we don't replicate properly queries
2507
invoking system variables' values to update tables; but
2508
CONVERT_TZ(,,@@session.time_zone) is so popular that we make it
2509
replicable (i.e. we tell the binlog code to store the session
2510
timezone). If it's the global value which was used we can't replicate
2511
(binlog code stores session value only).
2513
thd->time_zone_used= 1;
2514
return (uchar *)(thd->variables.time_zone->get_name()->ptr());
2519
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
2521
pthread_mutex_lock(&LOCK_global_system_variables);
2522
if (type == OPT_GLOBAL)
2524
if (default_tz_name)
2526
String str(default_tz_name, &my_charset_latin1);
2528
We are guaranteed to find this time zone since its existence
2529
is checked during start-up.
2531
global_system_variables.time_zone= my_tz_find(thd, &str);
2534
global_system_variables.time_zone= my_tz_SYSTEM;
2537
thd->variables.time_zone= global_system_variables.time_zone;
2538
pthread_mutex_unlock(&LOCK_global_system_variables);
2542
bool sys_var_max_user_conn::check(THD *thd, set_var *var)
2544
if (var->type == OPT_GLOBAL)
2545
return sys_var_thd::check(thd, var);
2549
Per-session values of max_user_connections can't be set directly.
2550
May be we should have a separate error message for this?
2552
my_error(ER_GLOBAL_VARIABLE, MYF(0), name);
2557
bool sys_var_max_user_conn::update(THD *thd __attribute__((__unused__)),
2560
assert(var->type == OPT_GLOBAL);
2561
pthread_mutex_lock(&LOCK_global_system_variables);
2562
max_user_connections= (uint)var->save_result.uint64_t_value;
2563
pthread_mutex_unlock(&LOCK_global_system_variables);
2568
void sys_var_max_user_conn::set_default(THD *thd __attribute__((__unused__)),
2569
enum_var_type type __attribute__((__unused__)))
2571
assert(type == OPT_GLOBAL);
2572
pthread_mutex_lock(&LOCK_global_system_variables);
2573
max_user_connections= (ulong) option_limits->def_value;
2574
pthread_mutex_unlock(&LOCK_global_system_variables);
2578
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2579
LEX_STRING *base __attribute__((__unused__)))
2581
if (type != OPT_GLOBAL &&
2582
thd->user_connect && thd->user_connect->user_resources.user_conn)
2583
return (uchar*) &(thd->user_connect->user_resources.user_conn);
2584
return (uchar*) &(max_user_connections);
2588
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((__unused__)),
1174
2591
MY_LOCALE *locale_match;
1176
2593
if (var->value->result_type() == INT_RESULT)
1178
if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
2595
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);
2598
int10_to_str((int) var->value->val_int(), buf, -10);
1182
2599
my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1186
2603
else // STRING_RESULT
1189
String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
2606
String str(buff, sizeof(buff), &my_charset_latin1), *res;
1190
2607
if (!(res=var->value->val_str(&str)))
1192
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
2609
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1195
2612
const char *locale_str= res->c_ptr();
1247
2671
microseconds= (int64_t) (num * 1000000.0 + 0.5);
1248
2672
if (var->type == OPT_GLOBAL)
1250
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
2674
pthread_mutex_lock(&LOCK_global_system_variables);
1251
2675
(global_system_variables.*offset)= microseconds;
2676
pthread_mutex_unlock(&LOCK_global_system_variables);
1254
session->variables.*offset= microseconds;
2679
thd->variables.*offset= microseconds;
1259
void sys_var_microseconds::set_default(Session *session, sql_var_t type)
2684
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
1261
2686
int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1262
2687
if (type == OPT_GLOBAL)
1264
boost::mutex::scoped_lock scopedLock(session->catalog().systemVariableLock());
2689
pthread_mutex_lock(&LOCK_global_system_variables);
1265
2690
global_system_variables.*offset= microseconds;
2691
pthread_mutex_unlock(&LOCK_global_system_variables);
1268
session->variables.*offset= microseconds;
2694
thd->variables.*offset= microseconds;
2698
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2699
LEX_STRING *base __attribute__((__unused__)))
2701
thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2702
global_system_variables.*offset :
2703
thd->variables.*offset) / 1000000.0;
2704
return (uchar*) &thd->tmp_double_value;
1272
Functions to update session->options bits
2709
Functions to update thd->options bits
1275
static bool set_option_bit(Session *session, set_var *var)
2712
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;
2714
sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
2715
if ((var->save_result.ulong_value != 0) == sys_var->reverse)
2716
thd->options&= ~sys_var->bit_flag;
1281
session->options|= sys_var->bit_flag;
2718
thd->options|= sys_var->bit_flag;
1286
static bool set_option_autocommit(Session *session, set_var *var)
2723
static bool set_option_autocommit(THD *thd, set_var *var)
1289
2725
/* 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;
2727
uint64_t org_options= thd->options;
1294
if (var->getInteger() != 0)
1295
new_options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2729
if (var->save_result.ulong_value != 0)
2730
thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
1297
new_options|= ((sys_var_session_bit*) var->var)->bit_flag;
2732
thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
1299
if ((org_options ^ new_options) & OPTION_NOT_AUTOCOMMIT)
2734
if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
1301
2736
if ((org_options & OPTION_NOT_AUTOCOMMIT))
1303
success= session->endActiveTransaction();
1304
2738
/* We changed to auto_commit mode */
1305
session->options&= ~(uint64_t) (OPTION_BEGIN);
1306
session->server_status|= SERVER_STATUS_AUTOCOMMIT;
2739
thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2740
thd->transaction.all.modified_non_trans_table= false;
2741
thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
1310
session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2747
thd->transaction.all.modified_non_trans_table= false;
2748
thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1314
if (var->getInteger() != 0)
1315
session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2754
static int check_log_update(THD *thd __attribute__((__unused__)),
2755
set_var *var __attribute__((__unused__)))
2760
static bool set_log_update(THD *thd __attribute__((__unused__)),
2761
set_var *var __attribute__((__unused__)))
2764
The update log is not supported anymore since 5.0.
2765
See sql/mysqld.cc/, comments in function init_server_components() for an
2766
explaination of the different warnings we send below
2769
if (opt_sql_bin_update)
2771
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2772
ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
2773
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;
2776
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
2777
ER_UPDATE_LOG_DEPRECATED_IGNORED,
2778
ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
2779
set_option_bit(thd, var);
2784
static int check_pseudo_thread_id(THD *thd __attribute__((__unused__)),
2787
var->save_result.uint64_t_value= var->value->val_int();
2791
static uchar *get_warning_count(THD *thd)
2793
thd->sys_var_tmp.long_value=
2794
(thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
2795
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] +
2796
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
2797
return (uchar*) &thd->sys_var_tmp.long_value;
2800
static uchar *get_error_count(THD *thd)
2802
thd->sys_var_tmp.long_value=
2803
thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
2804
return (uchar*) &thd->sys_var_tmp.long_value;
2869
Return variable name and length for hashing of variables.
2872
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
2873
my_bool first __attribute__((__unused__)))
2875
*length= var->name_length;
2876
return (uchar*) var->name;
2881
Add variables to the dynamic hash of system variables
2884
mysql_add_sys_var_chain()
2885
first Pointer to first system variable to add
2886
long_opt (optional)command line arguments may be tied for limit checks.
2894
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
2898
/* A write lock should be held on LOCK_system_variables_hash */
2900
for (var= first; var; var= var->next)
2902
var->name_length= strlen(var->name);
2903
/* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2904
if (my_hash_insert(&system_variable_hash, (uchar*) var))
2907
var->option_limits= find_option(long_options, var->name);
2912
for (; first != var; first= first->next)
2913
hash_delete(&system_variable_hash, (uchar*) first);
2919
Remove variables to the dynamic hash of system variables
2922
mysql_del_sys_var_chain()
2923
first Pointer to first system variable to remove
2930
int mysql_del_sys_var_chain(sys_var *first)
2934
/* A write lock should be held on LOCK_system_variables_hash */
2936
for (sys_var *var= first; var; var= var->next)
2937
result|= hash_delete(&system_variable_hash, (uchar*) var);
2943
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
2945
return strcmp(a->name, b->name);
1411
2950
Constructs an array of system variables for display to the user.
1414
2953
enumerate_sys_vars()
1415
session current thread
2955
sorted If TRUE, the system variables should be sorted
1418
pointer Array of drizzle_show_var elements for display
2958
pointer Array of SHOW_VAR elements for display
1422
drizzle_show_var* enumerate_sys_vars(Session *session)
2962
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);
2964
int count= system_variable_hash.records, i;
2965
int fixed_count= fixed_show_vars.elements;
2966
int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2967
SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
1429
drizzle_show_var *show= result;
2971
SHOW_VAR *show= result + fixed_count;
2972
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())
2974
for (i= 0; i < count; i++)
1434
sys_var *var= (*iter).second;
1435
show->name= var->getName().c_str();
2976
sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
2977
show->name= var->name;
1436
2978
show->value= (char*) var;
1437
2979
show->type= SHOW_SYS;
2983
/* sort into order */
2985
my_qsort(result, count + fixed_count, sizeof(SHOW_VAR),
2986
(qsort_cmp) show_cmp);
1442
2988
/* make last element empty */
1443
memset(show, 0, sizeof(drizzle_show_var));
2989
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
2996
Initialize the system variables
1488
3003
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"));
3010
for (sys_var *var=vars.first; var; var= var->next, count++) {};
3012
if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
3013
FIXED_VARS_SIZE + 64, 64))
3016
fixed_show_vars.elements= FIXED_VARS_SIZE;
3017
memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
3019
if (hash_init(&system_variable_hash, system_charset_info, count, 0,
3020
0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
3023
vars.last->next= NULL;
3024
if (mysql_add_sys_var_chain(vars.first, my_long_options))
3029
Needed because MySQL can't find the limits for a variable it it has
3030
a different name than the command line option.
3031
As these variables are deprecated, this code will disappear soon...
3033
sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
3038
fprintf(stderr, "failed to initialize system variables");
3045
hash_free(&system_variable_hash);
3046
delete_dynamic(&fixed_show_vars);
3051
Add elements to the dynamic list of read-only system variables.
3054
mysql_append_static_vars()
3055
show_vars Pointer to start of array
3056
count Number of elements
3062
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
3064
for (; count > 0; count--, show_vars++)
3065
if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
1576
3072
Find a user set-table variable.
1578
@param name Name of system variable to find
3074
@param str Name of system variable to find
3075
@param length Length of variable. zero means that we should use strlen()
3077
@param no_error Refuse to emit an error, even if one occurred.
1581
3080
pointer pointer to variable definitions
1583
3082
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());
3085
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
3090
This function is only called from the sql_plugin.cc.
3091
A lock on LOCK_system_variable_hash should be held
3093
var= (sys_var*) hash_search(&system_variable_hash,
3094
(uchar*) str, length ? length : strlen(str));
3095
if (!(var || no_error))
3096
my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
3103
Execute update of all variables.
3105
First run a check of all variables that all updates will go ok.
3106
If yes, then execute all updates, returning an error if any one failed.
3108
This should ensure that in all normal cases none all or variables are
3111
@param THD Thread id
3112
@param var_list List of variables to update
3117
1 ERROR, message sent (normally no variables was updated)
3119
-1 ERROR, message not sent
3122
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
3125
List_iterator_fast<set_var_base> it(*var_list);
3130
if ((error= var->check(thd)))
3133
if (!(error= test(thd->is_error())))
3137
error|= var->update(thd); // Returns 0, -1 or 1
3141
free_underlaid_joins(thd, &thd->lex->select_lex);
3147
Say if all variables set by a SET support the ONE_SHOT keyword
3148
(currently, only character set and collation do; later timezones
3151
@param var_list List of variables to update
3154
It has a "not_" because it makes faster tests (no need to "!")
3157
0 all variables of the list support ONE_SHOT
3159
1 at least one does not support ONE_SHOT
3162
bool not_all_support_one_shot(List<set_var_base> *var_list)
3164
List_iterator_fast<set_var_base> it(*var_list);
3168
if (var->no_support_one_shot())
3175
/*****************************************************************************
3176
Functions to handle SET mysql_internal_variable=const_expr
3177
*****************************************************************************/
3179
int set_var::check(THD *thd)
3181
if (var->is_readonly())
3183
my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name, "read only");
3186
if (var->check_type(type))
3188
int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
3189
my_error(err, MYF(0), var->name);
3192
/* value is a NULL pointer if we are using SET ... = DEFAULT */
3195
if (var->check_default(type))
3197
my_error(ER_NO_DEFAULT, MYF(0), var->name);
3203
if ((!value->fixed &&
3204
value->fix_fields(thd, &value)) || value->check_cols(1))
3206
if (var->check_update_type(value->result_type()))
3208
my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
3211
return var->check(thd, this) ? -1 : 0;
3217
@param thd thread handler
3218
@returns 0|1 ok or ERROR
3220
@note ERROR can be only due to abnormal operations involving
3221
the server's execution evironment such as
3222
out of memory, hard disk failure or the computer blows up.
3223
Consider set_var::check() method if there is a need to return
3224
an error due to logics.
3226
int set_var::update(THD *thd)
3229
var->set_default(thd, type);
3230
else if (var->update(thd, this))
3231
return -1; // should never happen
3232
if (var->after_update)
3233
(*var->after_update)(thd, type);
3238
/*****************************************************************************
3239
Functions to handle SET @user_variable=const_expr
3240
*****************************************************************************/
3242
int set_var_user::check(THD *thd)
3245
Item_func_set_user_var can't substitute something else on its place =>
3246
0 can be passed as last argument (reference on item)
3248
return (user_var_item->fix_fields(thd, (Item**) 0) ||
3249
user_var_item->check(0)) ? -1 : 0;
3253
int set_var_user::update(THD *thd __attribute__((__unused__)))
3255
if (user_var_item->update())
3257
/* Give an error if it's not given already */
3258
my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0));
1610
3264
/****************************************************************************
1611
3265
Functions to handle table_type
1612
3266
****************************************************************************/
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());
3268
/* Based upon sys_var::check_enum() */
3270
bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
3272
char buff[STRING_BUFFER_USUAL_SIZE];
3274
String str(buff, sizeof(buff), &my_charset_latin1), *res;
3276
var->save_result.plugin= NULL;
3277
if (var->value->result_type() == STRING_RESULT)
3279
LEX_STRING engine_name;
3281
if (!(res=var->value->val_str(&str)) ||
3282
!(engine_name.str= (char *)res->ptr()) ||
3283
!(engine_name.length= res->length()) ||
3284
!(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
3285
!(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
3286
ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
3288
value= res ? res->c_ptr() : "NULL";
3296
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value);
3301
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3302
LEX_STRING *base __attribute__((__unused__)))
3306
LEX_STRING *engine_name;
3307
plugin_ref plugin= thd->variables.*offset;
3308
if (type == OPT_GLOBAL)
3309
plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
3310
hton= plugin_data(plugin, handlerton*);
3311
engine_name= &hton2plugin[hton->slot]->name;
3312
result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
3313
if (type == OPT_GLOBAL)
3314
plugin_unlock(thd, plugin);
1630
void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
3319
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
1632
plugin::StorageEngine *old_value, *new_value, **value;
3321
plugin_ref old_value, new_value, *value;
1633
3322
if (type == OPT_GLOBAL)
1635
3324
value= &(global_system_variables.*offset);
1636
new_value= myisam_engine;
3325
new_value= ha_lock_engine(NULL, myisam_hton);
1640
value= &(session->variables.*offset);
1641
new_value= global_system_variables.*offset;
3329
value= &(thd->variables.*offset);
3330
new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
1643
3332
assert(new_value);
1644
3333
old_value= *value;
1645
3334
*value= new_value;
3335
plugin_unlock(NULL, old_value);
1649
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3339
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);
3341
plugin_ref *value= &(global_system_variables.*offset), old_value;
1683
3342
if (var->type != OPT_GLOBAL)
1684
value= &(session->variables.*offset);
1691
my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name_value);
1695
} /* namespace drizzled */
3343
value= &(thd->variables.*offset);
3345
if (old_value != var->save_result.plugin)
3347
*value= my_plugin_lock(NULL, &var->save_result.plugin);
3348
plugin_unlock(NULL, old_value);
3354
sys_var_thd_optimizer_switch::
3355
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
3357
char buff[STRING_BUFFER_USUAL_SIZE*8];
3358
String tmp(buff, sizeof(buff), &my_charset_latin1);
3362
for (uint i= 0; val; val>>= 1, i++)
3366
tmp.append(optimizer_switch_typelib.type_names[i],
3367
optimizer_switch_typelib.type_lengths[i]);
3373
tmp.length(tmp.length() - 1); /* trim the trailing comma */
3375
rep->str= thd->strmake(tmp.ptr(), tmp.length());
3377
rep->length= rep->str ? tmp.length() : 0;
3379
return rep->length != tmp.length();
3383
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3384
LEX_STRING *base __attribute__((__unused__)))
3387
uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3388
thd->variables.*offset);
3389
(void) symbolic_mode_representation(thd, val, &opts);
3390
return (uchar *) opts.str;
3394
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
3396
if (type == OPT_GLOBAL)
3397
global_system_variables.*offset= 0;
3399
thd->variables.*offset= global_system_variables.*offset;
3403
/****************************************************************************
3405
****************************************************************************/
3407
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
3410
I_List_iterator<NAMED_LIST> it(*list);
3411
NAMED_LIST *element;
3412
while ((element= it++))
3414
if (element->cmp(name, length))
3418
return element->data;
3425
void delete_elements(I_List<NAMED_LIST> *list,
3426
void (*free_element)(const char *name, uchar*))
3428
NAMED_LIST *element;
3429
while ((element= list->get()))
3431
(*free_element)(element->name, element->data);
3438
/* Key cache functions */
3440
static KEY_CACHE *create_key_cache(const char *name, uint length)
3442
KEY_CACHE *key_cache;
3444
if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3445
MYF(MY_ZEROFILL | MY_WME))))
3447
if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
3449
my_free((char*) key_cache, MYF(0));
3455
Set default values for a key cache
3456
The values in dflt_key_cache_var is set by my_getopt() at startup
3458
We don't set 'buff_size' as this is used to enable the key cache
3460
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
3461
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
3462
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
3469
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
3471
LEX_STRING key_cache_name;
3472
KEY_CACHE *key_cache;
3474
key_cache_name.str= (char *) name;
3475
key_cache_name.length= length;
3476
pthread_mutex_lock(&LOCK_global_system_variables);
3477
if (!(key_cache= get_key_cache(&key_cache_name)))
3478
key_cache= create_key_cache(name, length);
3479
pthread_mutex_unlock(&LOCK_global_system_variables);
3484
void free_key_cache(const char *name __attribute__((__unused__)),
3485
KEY_CACHE *key_cache)
3487
ha_end_key_cache(key_cache);
3488
my_free((char*) key_cache, MYF(0));
3492
bool process_key_caches(process_key_cache_t func)
3494
I_List_iterator<NAMED_LIST> it(key_caches);
3495
NAMED_LIST *element;
3497
while ((element= it++))
3499
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3500
func(element->name, key_cache);
3506
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
3510
/* Prevent self dead-lock */
3511
if (thd->locked_tables || thd->active_transaction())
3513
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3517
if (thd->global_read_lock)
3520
This connection already holds the global read lock.
3521
This can be the case with:
3522
- FLUSH TABLES WITH READ LOCK
3523
- SET GLOBAL READ_ONLY = 1
3525
result= sys_var_bool_ptr::update(thd, var);
3530
Perform a 'FLUSH TABLES WITH READ LOCK'.
3531
This is a 3 step process:
3532
- [1] lock_global_read_lock()
3533
- [2] close_cached_tables()
3534
- [3] make_global_read_lock_block_commit()
3535
[1] prevents new connections from obtaining tables locked for write.
3536
[2] waits until all existing connections close their tables.
3537
[3] prevents transactions from being committed.
3540
if (lock_global_read_lock(thd))
3544
This call will be blocked by any connection holding a READ or WRITE lock.
3545
Ideally, we want to wait only for pending WRITE locks, but since:
3546
con 1> LOCK TABLE T FOR READ;
3547
con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3548
con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3549
can cause to wait on a read lock, it's required for the client application
3550
to unlock everything, and acceptable for the server to wait on all locks.
3552
if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
3553
goto end_with_read_lock;
3555
if ((result= make_global_read_lock_block_commit(thd)) == true)
3556
goto end_with_read_lock;
3558
/* Change the opt_readonly system variable, safe because the lock is held */
3559
result= sys_var_bool_ptr::update(thd, var);
3562
/* Release the lock */
3563
unlock_global_read_lock(thd);
3567
/****************************************************************************
3569
****************************************************************************/
3571
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3572
template class List<set_var_base>;
3573
template class List_iterator_fast<set_var_base>;
3574
template class I_List_iterator<NAMED_LIST>;