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);
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",
146
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.
1116
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);
1942
old_value= var_str->value;
1943
var_str->value= res;
1944
var_str->value_length= str_length;
1954
pthread_mutex_unlock(&LOCK_global_system_variables);
1961
/*****************************************************************************
1962
Functions to handle SET NAMES and SET CHARACTER SET
1963
*****************************************************************************/
1965
int set_var_collation_client::check(Session *)
1967
/* Currently, UCS-2 cannot be used as a client character set */
1968
if (character_set_client->mbminlen > 1)
1970
my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
1971
character_set_client->csname);
1977
int set_var_collation_client::update(Session *session)
1979
session->variables.character_set_client= character_set_client;
1980
session->variables.character_set_results= character_set_results;
1981
session->variables.collation_connection= collation_connection;
1982
session->update_charset();
1983
session->protocol_text.init(session);
1119
1987
/****************************************************************************/
1121
1989
bool sys_var_timestamp::update(Session *session, set_var *var)
1864
2805
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1868
2809
unsigned char* result;
1870
plugin::StorageEngine *engine= session->variables.*offset;
1871
if (type == OPT_GLOBAL)
1872
engine= global_system_variables.*offset;
1873
engine_name= engine->getName();
1874
result= (unsigned char *) session->strmake(engine_name.c_str(),
1875
engine_name.size());
2811
LEX_STRING *engine_name;
2812
plugin_ref plugin= session->variables.*offset;
2813
if (type == OPT_GLOBAL)
2814
plugin= my_plugin_lock(session, &(global_system_variables.*offset));
2815
hton= plugin_data(plugin, handlerton*);
2816
engine_name= ha_storage_engine_name(hton);
2817
result= (unsigned char *) session->strmake(engine_name->str, engine_name->length);
2818
if (type == OPT_GLOBAL)
2819
plugin_unlock(session, plugin);
1880
void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
2824
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
1882
plugin::StorageEngine *old_value, *new_value, **value;
2826
plugin_ref old_value, new_value, *value;
1883
2827
if (type == OPT_GLOBAL)
1885
2829
value= &(global_system_variables.*offset);
1886
new_value= myisam_engine;
2830
new_value= ha_lock_engine(NULL, myisam_hton);
1890
2834
value= &(session->variables.*offset);
1891
new_value= global_system_variables.*offset;
2835
new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
1893
2837
assert(new_value);
1894
2838
old_value= *value;
1895
2839
*value= new_value;
2840
plugin_unlock(NULL, old_value);
1899
2844
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1901
plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
2846
plugin_ref *value= &(global_system_variables.*offset), old_value;
1902
2847
if (var->type != OPT_GLOBAL)
1903
2848
value= &(session->variables.*offset);
1904
2849
old_value= *value;
1905
if (old_value != var->save_result.storage_engine)
1907
*value= var->save_result.storage_engine;
1912
} /* namespace drizzled */
2850
if (old_value != var->save_result.plugin)
2852
*value= my_plugin_lock(NULL, &var->save_result.plugin);
2853
plugin_unlock(NULL, old_value);
2859
sys_var_session_optimizer_switch::
2860
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
2862
char buff[STRING_BUFFER_USUAL_SIZE*8];
2863
String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
2867
for (uint32_t i= 0; val; val>>= 1, i++)
2871
tmp.append(optimizer_switch_typelib.type_names[i],
2872
optimizer_switch_typelib.type_lengths[i]);
2878
tmp.length(tmp.length() - 1); /* trim the trailing comma */
2880
rep->str= session->strmake(tmp.ptr(), tmp.length());
2882
rep->length= rep->str ? tmp.length() : 0;
2884
return rep->length != tmp.length();
2888
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
2893
uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
2894
session->variables.*offset);
2895
(void) symbolic_mode_representation(session, val, &opts);
2896
return (unsigned char *) opts.str;
2900
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
2902
if (type == OPT_GLOBAL)
2903
global_system_variables.*offset= 0;
2905
session->variables.*offset= global_system_variables.*offset;
2909
/****************************************************************************
2911
****************************************************************************/
2913
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
2916
I_List_iterator<NAMED_LIST> it(*list);
2917
NAMED_LIST *element;
2918
while ((element= it++))
2920
if (element->cmp(name, length))
2924
return element->data;
2931
void delete_elements(I_List<NAMED_LIST> *list,
2932
void (*free_element)(const char *name, unsigned char*))
2934
NAMED_LIST *element;
2935
while ((element= list->get()))
2937
(*free_element)(element->name, element->data);
2944
/* Key cache functions */
2946
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
2948
KEY_CACHE *key_cache;
2950
if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
2952
memset(key_cache, 0, sizeof(KEY_CACHE));
2953
if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
2955
free((char*) key_cache);
2961
Set default values for a key cache
2962
The values in dflt_key_cache_var is set by my_getopt() at startup
2964
We don't set 'buff_size' as this is used to enable the key cache
2966
key_cache->param_block_size= dflt_key_cache_var.param_block_size;
2967
key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
2968
key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold;
2975
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
2977
LEX_STRING key_cache_name;
2978
KEY_CACHE *key_cache;
2980
key_cache_name.str= (char *) name;
2981
key_cache_name.length= length;
2982
pthread_mutex_lock(&LOCK_global_system_variables);
2983
if (!(key_cache= get_key_cache(&key_cache_name)))
2984
key_cache= create_key_cache(name, length);
2985
pthread_mutex_unlock(&LOCK_global_system_variables);
2990
void free_key_cache(const char *, KEY_CACHE *key_cache)
2992
ha_end_key_cache(key_cache);
2993
free((char*) key_cache);
2997
bool process_key_caches(process_key_cache_t func)
2999
I_List_iterator<NAMED_LIST> it(key_caches);
3000
NAMED_LIST *element;
3002
while ((element= it++))
3004
KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3005
func(element->name, key_cache);
3011
bool sys_var_opt_readonly::update(Session *session, set_var *var)
3015
/* Prevent self dead-lock */
3016
if (session->locked_tables || session->active_transaction())
3018
my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3022
if (session->global_read_lock)
3025
This connection already holds the global read lock.
3026
This can be the case with:
3027
- FLUSH TABLES WITH READ LOCK
3028
- SET GLOBAL READ_ONLY = 1
3030
result= sys_var_bool_ptr::update(session, var);
3035
Perform a 'FLUSH TABLES WITH READ LOCK'.
3036
This is a 3 step process:
3037
- [1] lock_global_read_lock()
3038
- [2] close_cached_tables()
3039
- [3] make_global_read_lock_block_commit()
3040
[1] prevents new connections from obtaining tables locked for write.
3041
[2] waits until all existing connections close their tables.
3042
[3] prevents transactions from being committed.
3045
if (lock_global_read_lock(session))
3049
This call will be blocked by any connection holding a READ or WRITE lock.
3050
Ideally, we want to wait only for pending WRITE locks, but since:
3051
con 1> LOCK TABLE T FOR READ;
3052
con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
3053
con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
3054
can cause to wait on a read lock, it's required for the client application
3055
to unlock everything, and acceptable for the server to wait on all locks.
3057
if ((result= close_cached_tables(session, NULL, false, true, true)) == true)
3058
goto end_with_read_lock;
3060
if ((result= make_global_read_lock_block_commit(session)) == true)
3061
goto end_with_read_lock;
3063
/* Change the opt_readonly system variable, safe because the lock is held */
3064
result= sys_var_bool_ptr::update(session, var);
3067
/* Release the lock */
3068
unlock_global_read_lock(session);
3072
/****************************************************************************
3074
****************************************************************************/
3076
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
3077
template class List<set_var_base>;
3078
template class List_iterator_fast<set_var_base>;
3079
template class I_List_iterator<NAMED_LIST>;