98
78
array_elements(bool_type_names)-1, "", bool_type_names, NULL
81
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
82
TYPELIB delay_key_write_typelib=
84
array_elements(delay_key_write_type_names)-1, "",
85
delay_key_write_type_names, NULL
88
const char *slave_exec_mode_names[]=
89
{ "STRICT", "IDEMPOTENT", NULL };
90
static const unsigned int slave_exec_mode_names_len[]=
91
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
92
TYPELIB slave_exec_mode_typelib=
94
array_elements(slave_exec_mode_names)-1, "",
95
slave_exec_mode_names, (unsigned int *) slave_exec_mode_names_len
98
static bool sys_update_init_connect(Session*, set_var*);
99
static void sys_default_init_connect(Session*, enum_var_type type);
100
static bool sys_update_init_slave(Session*, set_var*);
101
static void sys_default_init_slave(Session*, enum_var_type type);
101
102
static bool set_option_bit(Session *session, set_var *var);
102
103
static bool set_option_autocommit(Session *session, set_var *var);
104
static int check_log_update(Session *session, set_var *var);
103
105
static int check_pseudo_thread_id(Session *session, set_var *var);
106
static void fix_low_priority_updates(Session *session, enum_var_type type);
104
107
static int check_tx_isolation(Session *session, set_var *var);
105
static void fix_tx_isolation(Session *session, sql_var_t type);
108
static void fix_tx_isolation(Session *session, enum_var_type type);
106
109
static int check_completion_type(Session *session, set_var *var);
107
static void fix_completion_type(Session *session, sql_var_t type);
108
static void fix_max_join_size(Session *session, sql_var_t type);
109
static void fix_session_mem_root(Session *session, sql_var_t type);
110
static void fix_server_id(Session *session, sql_var_t type);
111
static bool get_unsigned32(Session *session, set_var *var);
112
static bool get_unsigned64(Session *session, set_var *var);
110
static void fix_completion_type(Session *session, enum_var_type type);
111
static void fix_net_read_timeout(Session *session, enum_var_type type);
112
static void fix_net_write_timeout(Session *session, enum_var_type type);
113
static void fix_net_retry_count(Session *session, enum_var_type type);
114
static void fix_max_join_size(Session *session, enum_var_type type);
115
static void fix_myisam_max_sort_file_size(Session *session, enum_var_type type);
116
static void fix_max_binlog_size(Session *session, enum_var_type type);
117
static void fix_max_relay_log_size(Session *session, enum_var_type type);
118
static void fix_max_connections(Session *session, enum_var_type type);
119
static void fix_session_mem_root(Session *session, enum_var_type type);
120
static void fix_trans_mem_root(Session *session, enum_var_type type);
121
static void fix_server_id(Session *session, enum_var_type type);
122
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
123
static bool get_unsigned(Session *session, set_var *var);
113
124
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
114
const std::string &name, int64_t val);
125
const char *name, int64_t val);
126
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
127
static unsigned char *get_error_count(Session *session);
116
128
static unsigned char *get_warning_count(Session *session);
117
129
static unsigned char *get_tmpdir(Session *session);
125
137
The variables are linked into the list. A variable is added to
126
138
it in the constructor (see sys_var class for details).
128
141
static sys_var_chain vars = { NULL, NULL };
130
static sys_var_session_uint64_t
143
static sys_var_session_uint32_t
131
144
sys_auto_increment_increment(&vars, "auto_increment_increment",
132
&system_variables::auto_increment_increment);
133
static sys_var_session_uint64_t
145
&SV::auto_increment_increment, NULL, NULL,
146
sys_var::SESSION_VARIABLE_IN_BINLOG);
147
static sys_var_session_uint32_t
134
148
sys_auto_increment_offset(&vars, "auto_increment_offset",
135
&system_variables::auto_increment_offset);
149
&SV::auto_increment_offset, NULL, NULL,
150
sys_var::SESSION_VARIABLE_IN_BINLOG);
137
152
static sys_var_const_str sys_basedir(&vars, "basedir", drizzle_home);
153
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
138
155
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
139
&system_variables::bulk_insert_buff_size);
156
&SV::bulk_insert_buff_size);
140
157
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
141
&system_variables::completion_type,
158
&SV::completion_type,
142
159
check_completion_type,
143
160
fix_completion_type);
144
161
static sys_var_collation_sv
145
sys_collation_server(&vars, "collation_server", &system_variables::collation_server, &default_charset_info);
146
static sys_var_const_str sys_datadir(&vars, "datadir", data_home_real);
162
sys_collation_connection(&vars, "collation_connection",
163
&SV::collation_connection, &default_charset_info,
164
sys_var::SESSION_VARIABLE_IN_BINLOG);
165
static sys_var_collation_sv
166
sys_collation_database(&vars, "collation_database", &SV::collation_database,
167
&default_charset_info,
168
sys_var::SESSION_VARIABLE_IN_BINLOG);
169
static sys_var_collation_sv
170
sys_collation_server(&vars, "collation_server", &SV::collation_server,
171
&default_charset_info,
172
sys_var::SESSION_VARIABLE_IN_BINLOG);
173
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
175
static sys_var_const_str sys_datadir(&vars, "datadir", drizzle_real_data_home);
176
static sys_var_enum sys_delay_key_write(&vars, "delay_key_write",
177
&delay_key_write_options,
178
&delay_key_write_typelib,
179
fix_delay_key_write);
181
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
183
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
184
sys_var_str sys_init_connect(&vars, "init_connect", 0,
185
sys_update_init_connect,
186
sys_default_init_connect,0);
187
sys_var_str sys_init_slave(&vars, "init_slave", 0,
188
sys_update_init_slave,
189
sys_default_init_slave,0);
190
static sys_var_session_uint32_t sys_interactive_timeout(&vars, "interactive_timeout",
191
&SV::net_interactive_timeout);
148
192
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
149
&system_variables::join_buff_size);
193
&SV::join_buff_size);
194
static sys_var_key_buffer_size sys_key_buffer_size(&vars, "key_buffer_size");
195
static sys_var_key_cache_long sys_key_cache_block_size(&vars, "key_cache_block_size",
198
static sys_var_key_cache_long sys_key_cache_division_limit(&vars, "key_cache_division_limit",
200
param_division_limit));
201
static sys_var_key_cache_long sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
203
param_age_threshold));
204
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
206
static sys_var_session_bool sys_low_priority_updates(&vars, "low_priority_updates",
207
&SV::low_priority_updates,
208
fix_low_priority_updates);
209
#ifndef TO_BE_DELETED /* Alias for the low_priority_updates */
210
static sys_var_session_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
211
&SV::low_priority_updates,
212
fix_low_priority_updates);
150
214
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
151
&system_variables::max_allowed_packet);
152
static sys_var_uint64_t_ptr sys_max_connect_errors(&vars, "max_connect_errors",
215
&SV::max_allowed_packet);
216
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
217
&max_binlog_cache_size);
218
static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
220
fix_max_binlog_size);
221
static sys_var_long_ptr sys_max_connections(&vars, "max_connections",
223
fix_max_connections);
224
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
153
225
&max_connect_errors);
154
226
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
155
&system_variables::max_error_count);
227
&SV::max_error_count);
156
228
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
157
&system_variables::max_heap_table_size);
229
&SV::max_heap_table_size);
158
230
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
159
&system_variables::pseudo_thread_id,
160
0, check_pseudo_thread_id);
231
&SV::pseudo_thread_id,
232
0, check_pseudo_thread_id,
233
sys_var::SESSION_VARIABLE_IN_BINLOG);
161
234
static sys_var_session_ha_rows sys_max_join_size(&vars, "max_join_size",
162
&system_variables::max_join_size,
163
236
fix_max_join_size);
164
237
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
165
&system_variables::max_seeks_for_key);
238
&SV::max_seeks_for_key);
166
239
static sys_var_session_uint64_t sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
167
&system_variables::max_length_for_sort_data);
168
static sys_var_session_size_t sys_max_sort_length(&vars, "max_sort_length",
169
&system_variables::max_sort_length);
170
static sys_var_uint64_t_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
240
&SV::max_length_for_sort_data);
241
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
243
fix_max_relay_log_size);
244
static sys_var_session_uint64_t sys_max_sort_length(&vars, "max_sort_length",
245
&SV::max_sort_length);
246
static sys_var_session_uint64_t sys_max_tmp_tables(&vars, "max_tmp_tables",
247
&SV::max_tmp_tables);
248
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
171
249
&max_write_lock_count);
172
250
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
173
&system_variables::min_examined_row_limit);
251
&SV::min_examined_row_limit);
252
static sys_var_session_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);
253
static sys_var_session_uint32_t sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
254
static sys_var_session_size_t sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
256
static sys_var_session_enum sys_myisam_stats_method(&vars, "myisam_stats_method",
257
&SV::myisam_stats_method,
258
&myisam_stats_method_typelib,
260
static sys_var_session_uint32_t sys_net_buffer_length(&vars, "net_buffer_length",
261
&SV::net_buffer_length);
262
static sys_var_session_uint32_t sys_net_read_timeout(&vars, "net_read_timeout",
263
&SV::net_read_timeout,
264
0, fix_net_read_timeout);
265
static sys_var_session_uint32_t sys_net_write_timeout(&vars, "net_write_timeout",
266
&SV::net_write_timeout,
267
0, fix_net_write_timeout);
268
static sys_var_session_uint32_t sys_net_retry_count(&vars, "net_retry_count",
269
&SV::net_retry_count,
270
0, fix_net_retry_count);
271
static sys_var_session_bool sys_new_mode(&vars, "new", &SV::new_mode);
272
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
273
&global_system_variables.old_mode);
175
274
/* these two cannot be static */
275
sys_var_session_bool sys_old_alter_table(&vars, "old_alter_table",
276
&SV::old_alter_table);
176
277
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
177
&system_variables::optimizer_prune_level);
278
&SV::optimizer_prune_level);
178
279
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
179
&system_variables::optimizer_search_depth);
280
&SV::optimizer_search_depth);
282
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
283
TYPELIB optimizer_use_mrr_typelib= {
284
array_elements(optimizer_use_mrr_names) - 1, "",
285
optimizer_use_mrr_names, NULL
288
static sys_var_session_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
289
&SV::optimizer_use_mrr,
290
&optimizer_use_mrr_typelib,
181
293
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
182
&system_variables::preload_buff_size);
294
&SV::preload_buff_size);
183
295
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
184
&system_variables::read_buff_size);
296
&SV::read_buff_size);
297
static sys_var_opt_readonly sys_readonly(&vars, "read_only", &opt_readonly);
185
298
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
186
&system_variables::read_rnd_buff_size);
299
&SV::read_rnd_buff_size);
187
300
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
188
&system_variables::div_precincrement);
301
&SV::div_precincrement);
190
303
static sys_var_session_size_t sys_range_alloc_block_size(&vars, "range_alloc_block_size",
191
&system_variables::range_alloc_block_size);
304
&SV::range_alloc_block_size);
192
305
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
193
&system_variables::query_alloc_block_size,
306
&SV::query_alloc_block_size,
194
307
false, fix_session_mem_root);
195
308
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
196
&system_variables::query_prealloc_size,
309
&SV::query_prealloc_size,
197
310
false, fix_session_mem_root);
198
311
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
312
static sys_var_session_uint32_t sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
313
&SV::trans_alloc_block_size,
314
false, fix_trans_mem_root);
315
static sys_var_session_uint32_t sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
316
&SV::trans_prealloc_size,
317
false, fix_trans_mem_root);
200
319
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
201
320
&opt_secure_file_priv);
202
321
static sys_var_uint32_t_ptr sys_server_id(&vars, "server_id", &server_id,
324
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
325
&opt_slave_compressed_protocol);
326
static sys_var_bool_ptr sys_slave_allow_batching(&vars, "slave_allow_batching",
327
&slave_allow_batching);
328
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
205
330
static sys_var_session_size_t sys_sort_buffer(&vars, "sort_buffer_size",
206
&system_variables::sortbuff_size);
333
sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
334
even though it is written to the binlog, the slave ignores the
335
MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
336
master's (see log_event.cc: Query_log_event::do_apply_event()).
338
static sys_var_session_optimizer_switch sys_optimizer_switch(&vars, "optimizer_switch",
339
&SV::optimizer_switch);
208
341
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
209
&system_variables::storage_engine);
210
343
static sys_var_const_str sys_system_time_zone(&vars, "system_time_zone",
211
344
system_time_zone);
212
static sys_var_size_t_ptr sys_table_def_size(&vars, "table_definition_cache",
214
static sys_var_uint64_t_ptr sys_table_cache_size(&vars, "table_open_cache",
345
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
347
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
215
348
&table_cache_size);
216
static sys_var_uint64_t_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
349
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
217
350
&table_lock_wait_timeout);
351
sys_var_long_ptr sys_thread_pool_size(&vars, "thread_pool_size",
218
353
static sys_var_session_enum sys_tx_isolation(&vars, "tx_isolation",
219
&system_variables::tx_isolation,
220
355
&tx_isolation_typelib,
221
356
fix_tx_isolation,
222
357
check_tx_isolation);
223
358
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
224
&system_variables::tmp_table_size);
225
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &internal::timed_mutexes);
226
static sys_var_const_str sys_version(&vars, "version", version().c_str());
359
&SV::tmp_table_size);
360
static sys_var_bool_ptr sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
361
static sys_var_const_str sys_version(&vars, "version", server_version);
228
362
static sys_var_const_str sys_version_comment(&vars, "version_comment",
229
363
COMPILATION_COMMENT);
230
364
static sys_var_const_str sys_version_compile_machine(&vars, "version_compile_machine",
232
366
static sys_var_const_str sys_version_compile_os(&vars, "version_compile_os",
234
static sys_var_const_str sys_version_compile_vendor(&vars, "version_compile_vendor",
368
static sys_var_session_uint32_t sys_net_wait_timeout(&vars, "wait_timeout",
369
&SV::net_wait_timeout);
371
/* Condition pushdown to storage engine */
372
static sys_var_session_bool
373
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
374
&SV::engine_condition_pushdown);
376
/* Time/date/datetime formats */
378
static sys_var_session_date_time_format sys_time_format(&vars, "time_format",
380
DRIZZLE_TIMESTAMP_TIME);
381
static sys_var_session_date_time_format sys_date_format(&vars, "date_format",
383
DRIZZLE_TIMESTAMP_DATE);
384
static sys_var_session_date_time_format sys_datetime_format(&vars, "datetime_format",
385
&SV::datetime_format,
386
DRIZZLE_TIMESTAMP_DATETIME);
237
388
/* Variables that are bits in Session */
243
394
static sys_var_session_bit sys_big_selects(&vars, "sql_big_selects", 0,
245
396
OPTION_BIG_SELECTS);
397
static sys_var_session_bit sys_log_binlog(&vars, "sql_log_bin",
246
401
static sys_var_session_bit sys_sql_warnings(&vars, "sql_warnings", 0,
248
403
OPTION_WARNINGS);
249
404
static sys_var_session_bit sys_sql_notes(&vars, "sql_notes", 0,
251
406
OPTION_SQL_NOTES);
407
static sys_var_session_bit sys_safe_updates(&vars, "sql_safe_updates", 0,
409
OPTION_SAFE_UPDATES);
252
410
static sys_var_session_bit sys_buffer_results(&vars, "sql_buffer_result", 0,
254
412
OPTION_BUFFER_RESULT);
413
static sys_var_session_bit sys_quote_show_create(&vars, "sql_quote_show_create", 0,
415
OPTION_QUOTE_SHOW_CREATE);
255
416
static sys_var_session_bit sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
257
OPTION_NO_FOREIGN_KEY_CHECKS, 1);
418
OPTION_NO_FOREIGN_KEY_CHECKS,
419
1, sys_var::SESSION_VARIABLE_IN_BINLOG);
258
420
static sys_var_session_bit sys_unique_checks(&vars, "unique_checks", 0,
260
OPTION_RELAXED_UNIQUE_CHECKS, 1);
422
OPTION_RELAXED_UNIQUE_CHECKS,
424
sys_var::SESSION_VARIABLE_IN_BINLOG);
261
425
/* Local state variables */
263
427
static sys_var_session_ha_rows sys_select_limit(&vars, "sql_select_limit",
264
&system_variables::select_limit);
265
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
429
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
430
sys_var::SESSION_VARIABLE_IN_BINLOG);
266
431
static sys_var_last_insert_id
267
sys_last_insert_id(&vars, "last_insert_id");
432
sys_last_insert_id(&vars, "last_insert_id",
433
sys_var::SESSION_VARIABLE_IN_BINLOG);
269
435
identity is an alias for last_insert_id(), so that we are compatible
272
static sys_var_last_insert_id sys_identity(&vars, "identity");
438
static sys_var_last_insert_id
439
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
274
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
441
static sys_var_session_lc_time_names
442
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
445
insert_id should *not* be marked as written to the binlog (i.e., it
446
should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
447
because we want any statement that refers to insert_id explicitly to
448
be unsafe. (By "explicitly", we mean using @@session.insert_id,
449
whereas insert_id is used "implicitly" when NULL value is inserted
450
into an auto_increment column).
277
452
We want statements referring explicitly to @@session.insert_id to be
278
453
unsafe, because insert_id is modified internally by the slave sql
279
454
thread when NULL values are inserted in an AUTO_INCREMENT column.
389
668
if (val < 0 || val > 2)
392
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
671
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
399
static void fix_session_mem_root(Session *session, sql_var_t type)
401
if (type != OPT_GLOBAL)
402
session->mem_root->reset_root_defaults(session->variables.query_alloc_block_size,
403
session->variables.query_prealloc_size);
407
static void fix_server_id(Session *, sql_var_t)
679
If we are changing the thread variable, we have to copy it to NET too
682
static void fix_net_read_timeout(Session *session, enum_var_type type)
684
if (type != OPT_GLOBAL)
685
my_net_set_read_timeout(&session->net, session->variables.net_read_timeout);
689
static void fix_net_write_timeout(Session *session, enum_var_type type)
691
if (type != OPT_GLOBAL)
692
my_net_set_write_timeout(&session->net, session->variables.net_write_timeout);
695
static void fix_net_retry_count(Session *session, enum_var_type type)
697
if (type != OPT_GLOBAL)
698
session->net.retry_count=session->variables.net_retry_count;
702
extern void fix_delay_key_write(Session *, enum_var_type)
704
switch ((enum_delay_key_write) delay_key_write_options) {
705
case DELAY_KEY_WRITE_NONE:
706
myisam_delay_key_write=0;
708
case DELAY_KEY_WRITE_ON:
709
myisam_delay_key_write=1;
711
case DELAY_KEY_WRITE_ALL:
712
myisam_delay_key_write=1;
713
ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
718
void fix_slave_exec_mode(enum_var_type)
720
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
721
bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
723
sql_print_error(_("Ambiguous slave modes combination."
724
" STRICT will be used"));
725
bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
727
if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
728
bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
732
static void fix_max_binlog_size(Session *, enum_var_type)
734
drizzle_bin_log.set_max_size(max_binlog_size);
735
if (!max_relay_log_size)
736
active_mi->rli.relay_log.set_max_size(max_binlog_size);
740
static void fix_max_relay_log_size(Session *, enum_var_type)
742
active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
743
max_relay_log_size: max_binlog_size);
747
static void fix_max_connections(Session *, enum_var_type)
749
resize_thr_alarm(max_connections + 10);
753
static void fix_session_mem_root(Session *session, enum_var_type type)
755
if (type != OPT_GLOBAL)
756
reset_root_defaults(session->mem_root,
757
session->variables.query_alloc_block_size,
758
session->variables.query_prealloc_size);
762
static void fix_trans_mem_root(Session *session, enum_var_type type)
764
if (type != OPT_GLOBAL)
765
reset_root_defaults(&session->transaction.mem_root,
766
session->variables.trans_alloc_block_size,
767
session->variables.trans_prealloc_size);
771
static void fix_server_id(Session *session, enum_var_type)
773
server_id_supplied = 1;
774
session->server_id= server_id;
412
778
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
413
const std::string &name, int64_t val)
779
const char *name, int64_t val)
420
internal::ullstr((uint64_t) val, buf);
786
ullstr((uint64_t) val, buf);
422
internal::llstr(val, buf);
424
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
790
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
425
791
ER_TRUNCATED_WRONG_VALUE,
426
ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
792
ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
431
uint64_t fix_unsigned(Session *session, uint64_t num,
432
const struct option *option_limits)
797
static uint64_t fix_unsigned(Session *session, uint64_t num,
798
const struct my_option *option_limits)
434
800
bool fixed= false;
435
801
uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
1115
1728
return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1732
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
1734
static KEY_CACHE zero_key_cache;
1736
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
1738
safe_mutex_assert_owner(&LOCK_global_system_variables);
1739
if (!cache_name || ! cache_name->length)
1740
cache_name= &default_key_cache_base;
1741
return ((KEY_CACHE*) find_named(&key_caches,
1742
cache_name->str, cache_name->length, 0));
1746
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
1749
KEY_CACHE *key_cache= get_key_cache(base);
1751
key_cache= &zero_key_cache;
1752
return (unsigned char*) key_cache + offset ;
1756
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1758
uint64_t tmp= var->save_result.uint64_t_value;
1759
LEX_STRING *base_name= &var->base;
1760
KEY_CACHE *key_cache;
1763
/* If no basename, assume it's for the key cache named 'default' */
1764
if (!base_name->length)
1765
base_name= &default_key_cache_base;
1767
pthread_mutex_lock(&LOCK_global_system_variables);
1768
key_cache= get_key_cache(base_name);
1772
/* Key cache didn't exists */
1773
if (!tmp) // Tried to delete cache
1774
goto end; // Ok, nothing to do
1775
if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
1783
Abort if some other thread is changing the key cache
1784
TODO: This should be changed so that we wait until the previous
1785
assignment is done and then do the new assign
1787
if (key_cache->in_init)
1790
if (!tmp) // Zero size means delete
1792
if (key_cache == dflt_key_cache)
1794
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1795
ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1796
ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1797
goto end; // Ignore default key cache
1800
if (key_cache->key_cache_inited) // If initied
1803
Move tables using this key cache to the default key cache
1804
and clear the old key cache.
1807
key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
1808
base_name->length, &list);
1809
key_cache->in_init= 1;
1810
pthread_mutex_unlock(&LOCK_global_system_variables);
1811
error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1812
pthread_mutex_lock(&LOCK_global_system_variables);
1813
key_cache->in_init= 0;
1816
We don't delete the key cache as some running threads my still be
1817
in the key cache code with a pointer to the deleted (empty) key cache
1822
key_cache->param_buff_size=
1823
(uint64_t) fix_unsigned(session, tmp, option_limits);
1825
/* If key cache didn't existed initialize it, else resize it */
1826
key_cache->in_init= 1;
1827
pthread_mutex_unlock(&LOCK_global_system_variables);
1829
if (!key_cache->key_cache_inited)
1830
error= (bool) (ha_init_key_cache("", key_cache));
1832
error= (bool)(ha_resize_key_cache(key_cache));
1834
pthread_mutex_lock(&LOCK_global_system_variables);
1835
key_cache->in_init= 0;
1838
pthread_mutex_unlock(&LOCK_global_system_variables);
1845
Abort if some other thread is changing the key cache.
1846
This should be changed so that we wait until the previous
1847
assignment is done and then do the new assign
1849
bool sys_var_key_cache_long::update(Session *session, set_var *var)
1851
uint64_t tmp= (uint64_t) var->value->val_int();
1852
LEX_STRING *base_name= &var->base;
1855
if (!base_name->length)
1856
base_name= &default_key_cache_base;
1858
pthread_mutex_lock(&LOCK_global_system_variables);
1859
KEY_CACHE *key_cache= get_key_cache(base_name);
1861
if (!key_cache && !(key_cache= create_key_cache(base_name->str,
1862
base_name->length)))
1869
Abort if some other thread is changing the key cache
1870
TODO: This should be changed so that we wait until the previous
1871
assignment is done and then do the new assign
1873
if (key_cache->in_init)
1876
*((uint64_t*) (((char*) key_cache) + offset))=
1877
(uint64_t) fix_unsigned(session, tmp, option_limits);
1880
Don't create a new key cache if it didn't exist
1881
(key_caches are created only when the user sets block_size)
1883
key_cache->in_init= 1;
1885
pthread_mutex_unlock(&LOCK_global_system_variables);
1887
error= (bool) (ha_resize_key_cache(key_cache));
1889
pthread_mutex_lock(&LOCK_global_system_variables);
1890
key_cache->in_init= 0;
1893
pthread_mutex_unlock(&LOCK_global_system_variables);
1898
bool sys_var_log_state::update(Session *, set_var *var)
1901
pthread_mutex_lock(&LOCK_global_system_variables);
1902
if (!var->save_result.uint32_t_value)
1906
pthread_mutex_unlock(&LOCK_global_system_variables);
1910
void sys_var_log_state::set_default(Session *, enum_var_type)
1915
bool update_sys_var_str_path(Session *, sys_var_str *var_str,
1916
set_var *var, const char *log_ext,
1917
bool log_state, uint32_t log_type)
1919
char buff[FN_REFLEN];
1920
char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
1922
uint32_t str_length= (var ? var->value->str_value.length() : 0);
1926
assert(0); // Impossible
1931
old_value= make_default_log_name(buff, log_ext);
1932
str_length= strlen(old_value);
1934
if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
1940
pthread_mutex_lock(&LOCK_global_system_variables);
1941
logger.lock_exclusive();
1943
old_value= var_str->value;
1944
var_str->value= res;
1945
var_str->value_length= str_length;
1956
pthread_mutex_unlock(&LOCK_global_system_variables);
1963
/*****************************************************************************
1964
Functions to handle SET NAMES and SET CHARACTER SET
1965
*****************************************************************************/
1967
int set_var_collation_client::check(Session *)
1969
/* Currently, UCS-2 cannot be used as a client character set */
1970
if (character_set_client->mbminlen > 1)
1972
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
1973
character_set_client->csname);
1979
int set_var_collation_client::update(Session *session)
1981
session->variables.character_set_client= character_set_client;
1982
session->variables.character_set_results= character_set_results;
1983
session->variables.collation_connection= collation_connection;
1984
session->update_charset();
1985
session->protocol_text.init(session);
1118
1989
/****************************************************************************/
1120
1991
bool sys_var_timestamp::update(Session *session, set_var *var)
2384
Return variable name and length for hashing of variables.
2387
static unsigned char *get_sys_var_length(const sys_var *var, size_t *length,
2390
*length= var->name_length;
2391
return (unsigned char*) var->name;
1477
2396
Add variables to the dynamic hash of system variables
1480
2399
mysql_add_sys_var_chain()
1481
2400
first Pointer to first system variable to add
1482
2401
long_opt (optional)command line arguments may be tied for limit checks.
1486
2405
otherwise FAILURE
1490
int mysql_add_sys_var_chain(sys_var *first, struct option *long_options)
2409
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
1493
2413
/* A write lock should be held on LOCK_system_variables_hash */
1495
for (var= first; var; var= var->getNext())
2415
for (var= first; var; var= var->next)
1498
string lower_name(var->getName());
1499
transform(lower_name.begin(), lower_name.end(),
1500
lower_name.begin(), ::tolower);
1502
/* this fails if there is a conflicting variable name. */
1503
if (system_variable_map.find(lower_name) != system_variable_map.end())
1505
errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1506
var->getName().c_str());
1510
pair<SystemVariableMap::iterator, bool> ret=
1511
system_variable_map.insert(make_pair(lower_name, var));
1512
if (ret.second == false)
1514
errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
1515
var->getName().c_str());
2417
var->name_length= strlen(var->name);
2418
/* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2419
if (my_hash_insert(&system_variable_hash, (unsigned char*) var))
1519
2421
if (long_options)
1520
var->setOptionLimits(find_option(long_options, var->getName().c_str()));
2422
var->option_limits= find_option(long_options, var->name);
2427
for (; first != var; first= first->next)
2428
hash_delete(&system_variable_hash, (unsigned char*) first);
1528
2434
Remove variables to the dynamic hash of system variables
1531
2437
mysql_del_sys_var_chain()
1532
2438
first Pointer to first system variable to remove
1536
2442
otherwise FAILURE
1539
2445
int mysql_del_sys_var_chain(sys_var *first)
1542
2449
/* A write lock should be held on LOCK_system_variables_hash */
1543
for (sys_var *var= first; var; var= var->getNext())
1545
string lower_name(var->getName());
1546
transform(lower_name.begin(), lower_name.end(),
1547
lower_name.begin(), ::tolower);
1548
system_variable_map.erase(lower_name);
2451
for (sys_var *var= first; var; var= var->next)
2452
result|= hash_delete(&system_variable_hash, (unsigned char*) var);
2458
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
2460
return strcmp(a->name, b->name);
1556
2465
Constructs an array of system variables for display to the user.
1559
2468
enumerate_sys_vars()
1560
2469
session current thread
1561
2470
sorted If TRUE, the system variables should be sorted
1564
pointer Array of drizzle_show_var elements for display
2473
pointer Array of SHOW_VAR elements for display
1568
drizzle_show_var* enumerate_sys_vars(Session *session, bool)
2477
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted)
2479
int count= system_variable_hash.records, i;
1570
2480
int fixed_count= fixed_show_vars.elements;
1571
int size= sizeof(drizzle_show_var) * (system_variable_map.size() + fixed_count + 1);
1572
drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
2481
int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2482
SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
1576
drizzle_show_var *show= result + fixed_count;
1577
memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(drizzle_show_var));
2486
SHOW_VAR *show= result + fixed_count;
2487
memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
1579
SystemVariableMap::const_iterator iter= system_variable_map.begin();
1580
while (iter != system_variable_map.end())
2489
for (i= 0; i < count; i++)
1582
sys_var *var= (*iter).second;
1583
show->name= var->getName().c_str();
2491
sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
2492
show->name= var->name;
1584
2493
show->value= (char*) var;
1585
2494
show->type= SHOW_SYS;
2498
/* sort into order */
2500
my_qsort(result, count + fixed_count, sizeof(SHOW_VAR),
2501
(qsort_cmp) show_cmp);
1590
2503
/* make last element empty */
1591
memset(show, 0, sizeof(drizzle_show_var));
2504
memset(show, 0, sizeof(SHOW_VAR));
1863
2807
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1867
2811
unsigned char* result;
1869
plugin::StorageEngine *engine= session->variables.*offset;
1870
if (type == OPT_GLOBAL)
1871
engine= global_system_variables.*offset;
1872
engine_name= engine->getName();
1873
result= (unsigned char *) session->strmake(engine_name.c_str(),
1874
engine_name.size());
2813
LEX_STRING *engine_name;
2814
plugin_ref plugin= session->variables.*offset;
2815
if (type == OPT_GLOBAL)
2816
plugin= my_plugin_lock(session, &(global_system_variables.*offset));
2817
hton= plugin_data(plugin, handlerton*);
2818
engine_name= ha_storage_engine_name(hton);
2819
result= (unsigned char *) session->strmake(engine_name->str, engine_name->length);
2820
if (type == OPT_GLOBAL)
2821
plugin_unlock(session, plugin);
1879
void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
2826
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
1881
plugin::StorageEngine *old_value, *new_value, **value;
2828
plugin_ref old_value, new_value, *value;
1882
2829
if (type == OPT_GLOBAL)
1884
2831
value= &(global_system_variables.*offset);
1885
new_value= myisam_engine;
2832
new_value= ha_lock_engine(NULL, myisam_hton);
1889
2836
value= &(session->variables.*offset);
1890
new_value= global_system_variables.*offset;
2837
new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
1892
2839
assert(new_value);
1893
2840
old_value= *value;
1894
2841
*value= new_value;
2842
plugin_unlock(NULL, old_value);
1898
2846
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1900
plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
2848
plugin_ref *value= &(global_system_variables.*offset), old_value;
1901
2849
if (var->type != OPT_GLOBAL)
1902
2850
value= &(session->variables.*offset);
1903
2851
old_value= *value;
1904
if (old_value != var->save_result.storage_engine)
1906
*value= var->save_result.storage_engine;
1911
} /* namespace drizzled */
2852
if (old_value != var->save_result.plugin)
2854
*value= my_plugin_lock(NULL, &var->save_result.plugin);
2855
plugin_unlock(NULL, old_value);
2861
sys_var_session_optimizer_switch::
2862
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
2864
char buff[STRING_BUFFER_USUAL_SIZE*8];
2865
String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
2869
for (uint32_t i= 0; val; val>>= 1, i++)
2873
tmp.append(optimizer_switch_typelib.type_names[i],
2874
optimizer_switch_typelib.type_lengths[i]);
2880
tmp.length(tmp.length() - 1); /* trim the trailing comma */
2882
rep->str= session->strmake(tmp.ptr(), tmp.length());
2884
rep->length= rep->str ? tmp.length() : 0;
2886
return rep->length != tmp.length();
2890
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
2895
uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
2896
session->variables.*offset);
2897
(void) symbolic_mode_representation(session, val, &opts);
2898
return (unsigned char *) opts.str;
2902
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
2904
if (type == OPT_GLOBAL)
2905
global_system_variables.*offset= 0;
2907
session->variables.*offset= global_system_variables.*offset;
2911
/****************************************************************************
2913
****************************************************************************/
2915
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
2918
I_List_iterator<NAMED_LIST> it(*list);
2919
NAMED_LIST *element;
2920
while ((element= it++))
2922
if (element->cmp(name, length))
2926
return element->data;
2933
void delete_elements(I_List<NAMED_LIST> *list,
2934
void (*free_element)(const char *name, unsigned char*))
2936
NAMED_LIST *element;
2937
while ((element= list->get()))
2939
(*free_element)(element->name, element->data);
2946
/* Key cache functions */
2948
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
2950
KEY_CACHE *key_cache;
2952
if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
2953
MYF(MY_ZEROFILL | MY_WME))))
2955
if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
2957
free((char*) key_cache);
2963
Set default values for a key cache
2964
The values in dflt_key_cache_var is set by my_getopt() at startup
2966
We don't set 'buff_size' as this is used to enable the key cache
2968
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
2969
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
2970
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
2977
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
2979
LEX_STRING key_cache_name;
2980
KEY_CACHE *key_cache;
2982
key_cache_name.str= (char *) name;
2983
key_cache_name.length= length;
2984
pthread_mutex_lock(&LOCK_global_system_variables);
2985
if (!(key_cache= get_key_cache(&key_cache_name)))
2986
key_cache= create_key_cache(name, length);
2987
pthread_mutex_unlock(&LOCK_global_system_variables);
2992
void free_key_cache(const char *, KEY_CACHE *key_cache)
2994
ha_end_key_cache(key_cache);
2995
free((char*) key_cache);
2999
bool process_key_caches(process_key_cache_t func)
3001
I_List_iterator<NAMED_LIST> it(key_caches);
3002
NAMED_LIST *element;
3004
while ((element= it++))
3006
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3007
func(element->name, key_cache);
3013
bool sys_var_opt_readonly::update(Session *session, set_var *var)
3017
/* Prevent self dead-lock */
3018
if (session->locked_tables || session->active_transaction())
3020
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3024
if (session->global_read_lock)
3027
This connection already holds the global read lock.
3028
This can be the case with:
3029
- FLUSH TABLES WITH READ LOCK
3030
- SET GLOBAL READ_ONLY = 1
3032
result= sys_var_bool_ptr::update(session, var);
3037
Perform a 'FLUSH TABLES WITH READ LOCK'.
3038
This is a 3 step process:
3039
- [1] lock_global_read_lock()
3040
- [2] close_cached_tables()
3041
- [3] make_global_read_lock_block_commit()
3042
[1] prevents new connections from obtaining tables locked for write.
3043
[2] waits until all existing connections close their tables.
3044
[3] prevents transactions from being committed.
3047
if (lock_global_read_lock(session))
3051
This call will be blocked by any connection holding a READ or WRITE lock.
3052
Ideally, we want to wait only for pending WRITE locks, but since:
3053
con 1> LOCK TABLE T FOR READ;
3054
con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3055
con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3056
can cause to wait on a read lock, it's required for the client application
3057
to unlock everything, and acceptable for the server to wait on all locks.
3059
if ((result= close_cached_tables(session, NULL, false, true, true)) == true)
3060
goto end_with_read_lock;
3062
if ((result= make_global_read_lock_block_commit(session)) == true)
3063
goto end_with_read_lock;
3065
/* Change the opt_readonly system variable, safe because the lock is held */
3066
result= sys_var_bool_ptr::update(session, var);
3069
/* Release the lock */
3070
unlock_global_read_lock(session);
3074
/****************************************************************************
3076
****************************************************************************/
3078
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3079
template class List<set_var_base>;
3080
template class List_iterator_fast<set_var_base>;
3081
template class I_List_iterator<NAMED_LIST>;