1 /* Copyright (c) 2009, 2021, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 /**
24 @file
25 Definitions of all server's session or global variables.
26
27 How to add new variables:
28
29 1. copy one of the existing variables, and edit the declaration.
30 2. if you need special behavior on assignment or additional checks
31 use ON_CHECK and ON_UPDATE callbacks.
32 3. *Don't* add new Sys_var classes or uncle Occam will come
33 with his razor to haunt you at nights
34
35 Note - all storage engine variables (for example myisam_whatever)
36 should go into the corresponding storage engine sources
37 (for example in storage/myisam/ha_myisam.cc) !
38 */
39
40 #include "sys_vars.h"
41
42 #include "my_aes.h" // my_aes_opmode_names
43 #include "myisam.h" // myisam_flush
44 #include "auth_common.h" // validate_user_plugins
45 #include "binlog.h" // mysql_bin_log
46 #include "connection_handler_impl.h" // Per_thread_connection_handler
47 #include "connection_handler_manager.h" // Connection_handler_manager
48 #include "debug_sync.h" // DEBUG_SYNC
49 #include "derror.h" // read_texts
50 #include "events.h" // Events
51 #include "hostname.h" // host_cache_resize
52 #include "item_timefunc.h" // ISO_FORMAT
53 #include "log_event.h" // MAX_MAX_ALLOWED_PACKET
54 #include "rpl_info_factory.h" // Rpl_info_factory
55 #include "rpl_info_handler.h" // INFO_REPOSITORY_FILE
56 #include "rpl_handler.h" // delegates_set_lock_type
57 #include "rpl_mi.h" // Master_info
58 #include "rpl_msr.h" // channel_map
59 #include "rpl_mts_submode.h" // MTS_PARALLEL_TYPE_DB_NAME
60 #include "rpl_rli.h" // Relay_log_info
61 #include "rpl_slave.h" // SLAVE_THD_TYPE
62 #include "socket_connection.h" // MY_BIND_ALL_ADDRESSES
63 #include "sp_head.h" // SP_PSI_STATEMENT_INFO_COUNT
64 #include "sql_parse.h" // killall_non_super_threads
65 #include "sql_show.h" // opt_ignore_db_dirs
66 #include "sql_tmp_table.h" // internal_tmp_disk_storage_engine
67 #include "sql_time.h" // global_date_format
68 #include "table_cache.h" // Table_cache_manager
69 #include "transaction.h" // trans_commit_stmt
70 #include "rpl_write_set_handler.h" // transaction_write_set_hashing_algorithms
71 #include "rpl_group_replication.h" // is_group_replication_running
72 #ifdef _WIN32
73 #include "named_pipe.h"
74 #endif
75 #include "threadpool.h"
76
77 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
78 #include "../storage/perfschema/pfs_server.h"
79 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
80
81 #define MAX_CONNECTIONS 100000
82
83 TYPELIB bool_typelib={ array_elements(bool_values)-1, "", bool_values, 0 };
84
update_buffer_size(THD * thd,KEY_CACHE * key_cache,ptrdiff_t offset,ulonglong new_value)85 static bool update_buffer_size(THD *thd, KEY_CACHE *key_cache,
86 ptrdiff_t offset, ulonglong new_value)
87 {
88 bool error= false;
89 assert(offset == offsetof(KEY_CACHE, param_buff_size));
90
91 if (new_value == 0)
92 {
93 if (key_cache == dflt_key_cache)
94 {
95 my_error(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE, MYF(0));
96 return true;
97 }
98
99 if (key_cache->key_cache_inited) // If initied
100 {
101 /*
102 Move tables using this key cache to the default key cache
103 and clear the old key cache.
104 */
105 key_cache->in_init= 1;
106 mysql_mutex_unlock(&LOCK_global_system_variables);
107 key_cache->param_buff_size= 0;
108 ha_resize_key_cache(key_cache);
109 ha_change_key_cache(key_cache, dflt_key_cache);
110 /*
111 We don't delete the key cache as some running threads my still be in
112 the key cache code with a pointer to the deleted (empty) key cache
113 */
114 mysql_mutex_lock(&LOCK_global_system_variables);
115 key_cache->in_init= 0;
116 }
117 return error;
118 }
119
120 key_cache->param_buff_size= new_value;
121
122 /* If key cache didn't exist initialize it, else resize it */
123 key_cache->in_init= 1;
124 mysql_mutex_unlock(&LOCK_global_system_variables);
125
126 if (!key_cache->key_cache_inited)
127 error= ha_init_key_cache(0, key_cache);
128 else
129 error= ha_resize_key_cache(key_cache);
130
131 mysql_mutex_lock(&LOCK_global_system_variables);
132 key_cache->in_init= 0;
133
134 return error;
135 }
136
update_keycache_param(THD * thd,KEY_CACHE * key_cache,ptrdiff_t offset,ulonglong new_value)137 static bool update_keycache_param(THD *thd, KEY_CACHE *key_cache,
138 ptrdiff_t offset, ulonglong new_value)
139 {
140 bool error= false;
141 assert(offset != offsetof(KEY_CACHE, param_buff_size));
142
143 keycache_var(key_cache, offset)= new_value;
144
145 key_cache->in_init= 1;
146 mysql_mutex_unlock(&LOCK_global_system_variables);
147 error= ha_resize_key_cache(key_cache);
148
149 mysql_mutex_lock(&LOCK_global_system_variables);
150 key_cache->in_init= 0;
151
152 return error;
153 }
154
155 /*
156 The rule for this file: everything should be 'static'. When a sys_var
157 variable or a function from this file is - in very rare cases - needed
158 elsewhere it should be explicitly declared 'export' here to show that it's
159 not a mistakenly forgotten 'static' keyword.
160 */
161 #define export /* not static */
162
163 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
164 #ifndef EMBEDDED_LIBRARY
165
166 #define PFS_TRAILING_PROPERTIES \
167 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL), \
168 NULL, sys_var::PARSE_EARLY
169
170 static Sys_var_mybool Sys_pfs_enabled(
171 "performance_schema",
172 "Enable the performance schema.",
173 READ_ONLY GLOBAL_VAR(pfs_param.m_enabled),
174 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
175 PFS_TRAILING_PROPERTIES);
176
177 static Sys_var_charptr Sys_pfs_instrument(
178 "performance_schema_instrument",
179 "Default startup value for a performance schema instrument.",
180 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_pfs_instrument),
181 CMD_LINE(OPT_ARG, OPT_PFS_INSTRUMENT),
182 IN_FS_CHARSET,
183 DEFAULT(""),
184 PFS_TRAILING_PROPERTIES);
185
186 static Sys_var_mybool Sys_pfs_consumer_events_stages_current(
187 "performance_schema_consumer_events_stages_current",
188 "Default startup value for the events_stages_current consumer.",
189 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_stages_current_enabled),
190 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
191 PFS_TRAILING_PROPERTIES);
192
193 static Sys_var_mybool Sys_pfs_consumer_events_stages_history(
194 "performance_schema_consumer_events_stages_history",
195 "Default startup value for the events_stages_history consumer.",
196 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_stages_history_enabled),
197 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
198 PFS_TRAILING_PROPERTIES);
199
200 static Sys_var_mybool Sys_pfs_consumer_events_stages_history_long(
201 "performance_schema_consumer_events_stages_history_long",
202 "Default startup value for the events_stages_history_long consumer.",
203 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_stages_history_long_enabled),
204 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
205 PFS_TRAILING_PROPERTIES);
206
207 static Sys_var_mybool Sys_pfs_consumer_events_statements_current(
208 "performance_schema_consumer_events_statements_current",
209 "Default startup value for the events_statements_current consumer.",
210 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_statements_current_enabled),
211 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
212 PFS_TRAILING_PROPERTIES);
213
214 static Sys_var_mybool Sys_pfs_consumer_events_statements_history(
215 "performance_schema_consumer_events_statements_history",
216 "Default startup value for the events_statements_history consumer.",
217 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_statements_history_enabled),
218 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
219 PFS_TRAILING_PROPERTIES);
220
221 static Sys_var_mybool Sys_pfs_consumer_events_statements_history_long(
222 "performance_schema_consumer_events_statements_history_long",
223 "Default startup value for the events_statements_history_long consumer.",
224 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_statements_history_long_enabled),
225 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
226 PFS_TRAILING_PROPERTIES);
227
228 static Sys_var_mybool Sys_pfs_consumer_events_transactions_current(
229 "performance_schema_consumer_events_transactions_current",
230 "Default startup value for the events_transactions_current consumer.",
231 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_transactions_current_enabled),
232 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
233 PFS_TRAILING_PROPERTIES);
234
235 static Sys_var_mybool Sys_pfs_consumer_events_transactions_history(
236 "performance_schema_consumer_events_transactions_history",
237 "Default startup value for the events_transactions_history consumer.",
238 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_transactions_history_enabled),
239 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
240 PFS_TRAILING_PROPERTIES);
241
242 static Sys_var_mybool Sys_pfs_consumer_events_transactions_history_long(
243 "performance_schema_consumer_events_transactions_history_long",
244 "Default startup value for the events_transactions_history_long consumer.",
245 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_transactions_history_long_enabled),
246 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
247 PFS_TRAILING_PROPERTIES);
248
249 static Sys_var_mybool Sys_pfs_consumer_events_waits_current(
250 "performance_schema_consumer_events_waits_current",
251 "Default startup value for the events_waits_current consumer.",
252 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_waits_current_enabled),
253 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
254 PFS_TRAILING_PROPERTIES);
255
256 static Sys_var_mybool Sys_pfs_consumer_events_waits_history(
257 "performance_schema_consumer_events_waits_history",
258 "Default startup value for the events_waits_history consumer.",
259 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_waits_history_enabled),
260 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
261 PFS_TRAILING_PROPERTIES);
262
263 static Sys_var_mybool Sys_pfs_consumer_events_waits_history_long(
264 "performance_schema_consumer_events_waits_history_long",
265 "Default startup value for the events_waits_history_long consumer.",
266 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_waits_history_long_enabled),
267 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
268 PFS_TRAILING_PROPERTIES);
269
270 static Sys_var_mybool Sys_pfs_consumer_global_instrumentation(
271 "performance_schema_consumer_global_instrumentation",
272 "Default startup value for the global_instrumentation consumer.",
273 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_global_instrumentation_enabled),
274 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
275 PFS_TRAILING_PROPERTIES);
276
277 static Sys_var_mybool Sys_pfs_consumer_thread_instrumentation(
278 "performance_schema_consumer_thread_instrumentation",
279 "Default startup value for the thread_instrumentation consumer.",
280 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_thread_instrumentation_enabled),
281 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
282 PFS_TRAILING_PROPERTIES);
283
284 static Sys_var_mybool Sys_pfs_consumer_statement_digest(
285 "performance_schema_consumer_statements_digest",
286 "Default startup value for the statements_digest consumer.",
287 READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_statement_digest_enabled),
288 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
289 PFS_TRAILING_PROPERTIES);
290
291 static Sys_var_long Sys_pfs_events_waits_history_long_size(
292 "performance_schema_events_waits_history_long_size",
293 "Number of rows in EVENTS_WAITS_HISTORY_LONG."
294 " Use 0 to disable, -1 for automated sizing.",
295 READ_ONLY GLOBAL_VAR(pfs_param.m_events_waits_history_long_sizing),
296 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
297 DEFAULT(PFS_AUTOSIZE_VALUE),
298 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
299
300 static Sys_var_long Sys_pfs_events_waits_history_size(
301 "performance_schema_events_waits_history_size",
302 "Number of rows per thread in EVENTS_WAITS_HISTORY."
303 " Use 0 to disable, -1 for automated sizing.",
304 READ_ONLY GLOBAL_VAR(pfs_param.m_events_waits_history_sizing),
305 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024),
306 DEFAULT(PFS_AUTOSIZE_VALUE),
307 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
308
309 static Sys_var_ulong Sys_pfs_max_cond_classes(
310 "performance_schema_max_cond_classes",
311 "Maximum number of condition instruments.",
312 READ_ONLY GLOBAL_VAR(pfs_param.m_cond_class_sizing),
313 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
314 DEFAULT(PFS_MAX_COND_CLASS),
315 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
316
317 static Sys_var_long Sys_pfs_max_cond_instances(
318 "performance_schema_max_cond_instances",
319 "Maximum number of instrumented condition objects."
320 " Use 0 to disable, -1 for automated scaling.",
321 READ_ONLY GLOBAL_VAR(pfs_param.m_cond_sizing),
322 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
323 DEFAULT(PFS_AUTOSCALE_VALUE),
324 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
325
326 static Sys_var_long Sys_pfs_max_program_instances(
327 "performance_schema_max_program_instances",
328 "Maximum number of instrumented programs."
329 " Use 0 to disable, -1 for automated scaling.",
330 READ_ONLY GLOBAL_VAR(pfs_param.m_program_sizing),
331 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
332 DEFAULT(PFS_AUTOSCALE_VALUE),
333 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
334
335 static Sys_var_long Sys_pfs_max_prepared_stmt_instances(
336 "performance_schema_max_prepared_statements_instances",
337 "Maximum number of instrumented prepared statements."
338 " Use 0 to disable, -1 for automated scaling.",
339 READ_ONLY GLOBAL_VAR(pfs_param.m_prepared_stmt_sizing),
340 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
341 DEFAULT(PFS_AUTOSCALE_VALUE),
342 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
343
344 static Sys_var_ulong Sys_pfs_max_file_classes(
345 "performance_schema_max_file_classes",
346 "Maximum number of file instruments.",
347 READ_ONLY GLOBAL_VAR(pfs_param.m_file_class_sizing),
348 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
349 DEFAULT(PFS_MAX_FILE_CLASS),
350 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
351
352 static Sys_var_ulong Sys_pfs_max_file_handles(
353 "performance_schema_max_file_handles",
354 "Maximum number of opened instrumented files.",
355 READ_ONLY GLOBAL_VAR(pfs_param.m_file_handle_sizing),
356 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024),
357 DEFAULT(PFS_MAX_FILE_HANDLE),
358 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
359
360 static Sys_var_long Sys_pfs_max_file_instances(
361 "performance_schema_max_file_instances",
362 "Maximum number of instrumented files."
363 " Use 0 to disable, -1 for automated scaling.",
364 READ_ONLY GLOBAL_VAR(pfs_param.m_file_sizing),
365 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
366 DEFAULT(PFS_AUTOSCALE_VALUE),
367 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
368
369 static Sys_var_long Sys_pfs_max_sockets(
370 "performance_schema_max_socket_instances",
371 "Maximum number of opened instrumented sockets."
372 " Use 0 to disable, -1 for automated scaling.",
373 READ_ONLY GLOBAL_VAR(pfs_param.m_socket_sizing),
374 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
375 DEFAULT(PFS_AUTOSCALE_VALUE),
376 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
377
378 static Sys_var_ulong Sys_pfs_max_socket_classes(
379 "performance_schema_max_socket_classes",
380 "Maximum number of socket instruments.",
381 READ_ONLY GLOBAL_VAR(pfs_param.m_socket_class_sizing),
382 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
383 DEFAULT(PFS_MAX_SOCKET_CLASS),
384 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
385
386 static Sys_var_ulong Sys_pfs_max_mutex_classes(
387 "performance_schema_max_mutex_classes",
388 "Maximum number of mutex instruments.",
389 READ_ONLY GLOBAL_VAR(pfs_param.m_mutex_class_sizing),
390 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
391 DEFAULT(PFS_MAX_MUTEX_CLASS),
392 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
393
394 static Sys_var_long Sys_pfs_max_mutex_instances(
395 "performance_schema_max_mutex_instances",
396 "Maximum number of instrumented MUTEX objects."
397 " Use 0 to disable, -1 for automated scaling.",
398 READ_ONLY GLOBAL_VAR(pfs_param.m_mutex_sizing),
399 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 100*1024*1024),
400 DEFAULT(PFS_AUTOSCALE_VALUE),
401 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
402
403 static Sys_var_ulong Sys_pfs_max_rwlock_classes(
404 "performance_schema_max_rwlock_classes",
405 "Maximum number of rwlock instruments.",
406 READ_ONLY GLOBAL_VAR(pfs_param.m_rwlock_class_sizing),
407 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
408 DEFAULT(PFS_MAX_RWLOCK_CLASS),
409 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
410
411 static Sys_var_long Sys_pfs_max_rwlock_instances(
412 "performance_schema_max_rwlock_instances",
413 "Maximum number of instrumented RWLOCK objects."
414 " Use 0 to disable, -1 for automated scaling.",
415 READ_ONLY GLOBAL_VAR(pfs_param.m_rwlock_sizing),
416 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 100*1024*1024),
417 DEFAULT(PFS_AUTOSCALE_VALUE),
418 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
419
420 static Sys_var_long Sys_pfs_max_table_handles(
421 "performance_schema_max_table_handles",
422 "Maximum number of opened instrumented tables."
423 " Use 0 to disable, -1 for automated scaling.",
424 READ_ONLY GLOBAL_VAR(pfs_param.m_table_sizing),
425 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
426 DEFAULT(PFS_AUTOSCALE_VALUE),
427 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
428
429 static Sys_var_long Sys_pfs_max_table_instances(
430 "performance_schema_max_table_instances",
431 "Maximum number of instrumented tables."
432 " Use 0 to disable, -1 for automated scaling.",
433 READ_ONLY GLOBAL_VAR(pfs_param.m_table_share_sizing),
434 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
435 DEFAULT(PFS_AUTOSCALE_VALUE),
436 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
437
438 static Sys_var_long Sys_pfs_max_table_lock_stat(
439 "performance_schema_max_table_lock_stat",
440 "Maximum number of lock statistics for instrumented tables."
441 " Use 0 to disable, -1 for automated scaling.",
442 READ_ONLY GLOBAL_VAR(pfs_param.m_table_lock_stat_sizing),
443 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
444 DEFAULT(PFS_AUTOSCALE_VALUE),
445 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
446
447 static Sys_var_long Sys_pfs_max_index_stat(
448 "performance_schema_max_index_stat",
449 "Maximum number of index statistics for instrumented tables."
450 " Use 0 to disable, -1 for automated scaling.",
451 READ_ONLY GLOBAL_VAR(pfs_param.m_index_stat_sizing),
452 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
453 DEFAULT(PFS_AUTOSCALE_VALUE),
454 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
455
456 static Sys_var_ulong Sys_pfs_max_thread_classes(
457 "performance_schema_max_thread_classes",
458 "Maximum number of thread instruments.",
459 READ_ONLY GLOBAL_VAR(pfs_param.m_thread_class_sizing),
460 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
461 DEFAULT(PFS_MAX_THREAD_CLASS),
462 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
463
464 static Sys_var_long Sys_pfs_max_thread_instances(
465 "performance_schema_max_thread_instances",
466 "Maximum number of instrumented threads."
467 " Use 0 to disable, -1 for automated scaling.",
468 READ_ONLY GLOBAL_VAR(pfs_param.m_thread_sizing),
469 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
470 DEFAULT(PFS_AUTOSCALE_VALUE),
471 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
472
473 static Sys_var_long Sys_pfs_setup_actors_size(
474 "performance_schema_setup_actors_size",
475 "Maximum number of rows in SETUP_ACTORS."
476 " Use 0 to disable, -1 for automated scaling.",
477 READ_ONLY GLOBAL_VAR(pfs_param.m_setup_actor_sizing),
478 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
479 DEFAULT(PFS_AUTOSCALE_VALUE),
480 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
481
482 static Sys_var_long Sys_pfs_setup_objects_size(
483 "performance_schema_setup_objects_size",
484 "Maximum number of rows in SETUP_OBJECTS."
485 " Use 0 to disable, -1 for automated scaling.",
486 READ_ONLY GLOBAL_VAR(pfs_param.m_setup_object_sizing),
487 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
488 DEFAULT(PFS_AUTOSCALE_VALUE),
489 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
490
491 static Sys_var_long Sys_pfs_accounts_size(
492 "performance_schema_accounts_size",
493 "Maximum number of instrumented user@host accounts."
494 " Use 0 to disable, -1 for automated scaling.",
495 READ_ONLY GLOBAL_VAR(pfs_param.m_account_sizing),
496 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
497 DEFAULT(PFS_AUTOSCALE_VALUE),
498 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
499
500 static Sys_var_long Sys_pfs_hosts_size(
501 "performance_schema_hosts_size",
502 "Maximum number of instrumented hosts."
503 " Use 0 to disable, -1 for automated scaling.",
504 READ_ONLY GLOBAL_VAR(pfs_param.m_host_sizing),
505 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
506 DEFAULT(PFS_AUTOSCALE_VALUE),
507 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
508
509 static Sys_var_long Sys_pfs_users_size(
510 "performance_schema_users_size",
511 "Maximum number of instrumented users."
512 " Use 0 to disable, -1 for automated scaling.",
513 READ_ONLY GLOBAL_VAR(pfs_param.m_user_sizing),
514 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
515 DEFAULT(PFS_AUTOSCALE_VALUE),
516 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
517
518 static Sys_var_ulong Sys_pfs_max_stage_classes(
519 "performance_schema_max_stage_classes",
520 "Maximum number of stage instruments.",
521 READ_ONLY GLOBAL_VAR(pfs_param.m_stage_class_sizing),
522 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
523 DEFAULT(PFS_MAX_STAGE_CLASS),
524 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
525
526 static Sys_var_long Sys_pfs_events_stages_history_long_size(
527 "performance_schema_events_stages_history_long_size",
528 "Number of rows in EVENTS_STAGES_HISTORY_LONG."
529 " Use 0 to disable, -1 for automated sizing.",
530 READ_ONLY GLOBAL_VAR(pfs_param.m_events_stages_history_long_sizing),
531 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
532 DEFAULT(PFS_AUTOSIZE_VALUE),
533 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
534
535 static Sys_var_long Sys_pfs_events_stages_history_size(
536 "performance_schema_events_stages_history_size",
537 "Number of rows per thread in EVENTS_STAGES_HISTORY."
538 " Use 0 to disable, -1 for automated sizing.",
539 READ_ONLY GLOBAL_VAR(pfs_param.m_events_stages_history_sizing),
540 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024),
541 DEFAULT(PFS_AUTOSIZE_VALUE),
542 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
543
544 /**
545 Variable performance_schema_max_statement_classes.
546 The default number of statement classes is the sum of:
547 - COM_END for all regular "statement/com/...",
548 - 1 for "statement/com/new_packet", for unknown enum_server_command
549 - 1 for "statement/com/Error", for invalid enum_server_command
550 - SQLCOM_END for all regular "statement/sql/...",
551 - 1 for "statement/sql/error", for invalid enum_sql_command.
552 - SP_PSI_STATEMENT_INFO_COUNT for "statement/sp/...".
553 - 1 for "statement/rpl/relay_log", for replicated statements.
554 - 1 for "statement/scheduler/event", for scheduled events.
555 */
556 static Sys_var_ulong Sys_pfs_max_statement_classes(
557 "performance_schema_max_statement_classes",
558 "Maximum number of statement instruments.",
559 READ_ONLY GLOBAL_VAR(pfs_param.m_statement_class_sizing),
560 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
561 DEFAULT((ulong) SQLCOM_END + (ulong) COM_END + 5 + SP_PSI_STATEMENT_INFO_COUNT),
562 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
563
564 static Sys_var_long Sys_pfs_events_statements_history_long_size(
565 "performance_schema_events_statements_history_long_size",
566 "Number of rows in EVENTS_STATEMENTS_HISTORY_LONG."
567 " Use 0 to disable, -1 for automated sizing.",
568 READ_ONLY GLOBAL_VAR(pfs_param.m_events_statements_history_long_sizing),
569 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
570 DEFAULT(PFS_AUTOSIZE_VALUE),
571 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
572
573 static Sys_var_long Sys_pfs_events_statements_history_size(
574 "performance_schema_events_statements_history_size",
575 "Number of rows per thread in EVENTS_STATEMENTS_HISTORY."
576 " Use 0 to disable, -1 for automated sizing.",
577 READ_ONLY GLOBAL_VAR(pfs_param.m_events_statements_history_sizing),
578 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024),
579 DEFAULT(PFS_AUTOSIZE_VALUE),
580 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
581
582 static Sys_var_ulong Sys_pfs_statement_stack_size(
583 "performance_schema_max_statement_stack",
584 "Number of rows per thread in EVENTS_STATEMENTS_CURRENT.",
585 READ_ONLY GLOBAL_VAR(pfs_param.m_statement_stack_sizing),
586 CMD_LINE(REQUIRED_ARG), VALID_RANGE(1, 256),
587 DEFAULT(PFS_STATEMENTS_STACK_SIZE),
588 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
589
590 static Sys_var_ulong Sys_pfs_max_memory_classes(
591 "performance_schema_max_memory_classes",
592 "Maximum number of memory pool instruments.",
593 READ_ONLY GLOBAL_VAR(pfs_param.m_memory_class_sizing),
594 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024),
595 DEFAULT(PFS_MAX_MEMORY_CLASS),
596 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
597
598 static Sys_var_long Sys_pfs_digest_size(
599 "performance_schema_digests_size",
600 "Size of the statement digest."
601 " Use 0 to disable, -1 for automated sizing.",
602 READ_ONLY GLOBAL_VAR(pfs_param.m_digest_sizing),
603 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024 * 1024),
604 DEFAULT(PFS_AUTOSIZE_VALUE),
605 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
606
607 static Sys_var_long Sys_pfs_events_transactions_history_long_size(
608 "performance_schema_events_transactions_history_long_size",
609 "Number of rows in EVENTS_TRANSACTIONS_HISTORY_LONG."
610 " Use 0 to disable, -1 for automated sizing.",
611 READ_ONLY GLOBAL_VAR(pfs_param.m_events_transactions_history_long_sizing),
612 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
613 DEFAULT(PFS_AUTOSIZE_VALUE),
614 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
615
616 static Sys_var_long Sys_pfs_events_transactions_history_size(
617 "performance_schema_events_transactions_history_size",
618 "Number of rows per thread in EVENTS_TRANSACTIONS_HISTORY."
619 " Use 0 to disable, -1 for automated sizing.",
620 READ_ONLY GLOBAL_VAR(pfs_param.m_events_transactions_history_sizing),
621 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024),
622 DEFAULT(PFS_AUTOSIZE_VALUE),
623 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
624
625 static Sys_var_long Sys_pfs_max_digest_length(
626 "performance_schema_max_digest_length",
627 "Maximum length considered for digest text, when stored in performance_schema tables.",
628 READ_ONLY GLOBAL_VAR(pfs_param.m_max_digest_length),
629 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024 * 1024),
630 DEFAULT(1024),
631 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
632
633 static Sys_var_long Sys_pfs_connect_attrs_size(
634 "performance_schema_session_connect_attrs_size",
635 "Size of session attribute string buffer per thread."
636 " Use 0 to disable, -1 for automated sizing.",
637 READ_ONLY GLOBAL_VAR(pfs_param.m_session_connect_attrs_sizing),
638 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024 * 1024),
639 DEFAULT(PFS_AUTOSIZE_VALUE),
640 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
641
642 static Sys_var_long Sys_pfs_max_metadata_locks(
643 "performance_schema_max_metadata_locks",
644 "Maximum number of metadata locks."
645 " Use 0 to disable, -1 for automated scaling.",
646 READ_ONLY GLOBAL_VAR(pfs_param.m_metadata_lock_sizing),
647 CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 100*1024*1024),
648 DEFAULT(PFS_AUTOSCALE_VALUE),
649 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
650
651 static Sys_var_long Sys_pfs_max_sql_text_length(
652 "performance_schema_max_sql_text_length",
653 "Maximum length of displayed sql text.",
654 READ_ONLY GLOBAL_VAR(pfs_param.m_max_sql_text_length),
655 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024 * 1024),
656 DEFAULT(1024),
657 BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
658
659 #endif /* EMBEDDED_LIBRARY */
660 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
661
662 static Sys_var_ulong Sys_auto_increment_increment(
663 "auto_increment_increment",
664 "Auto-increment columns are incremented by this",
665 SESSION_VAR(auto_increment_increment),
666 CMD_LINE(OPT_ARG),
667 VALID_RANGE(1, 65535), DEFAULT(1), BLOCK_SIZE(1),
668 NO_MUTEX_GUARD, IN_BINLOG);
669
670 static Sys_var_ulong Sys_auto_increment_offset(
671 "auto_increment_offset",
672 "Offset added to Auto-increment columns. Used when "
673 "auto-increment-increment != 1",
674 SESSION_VAR(auto_increment_offset),
675 CMD_LINE(OPT_ARG),
676 VALID_RANGE(1, 65535), DEFAULT(1), BLOCK_SIZE(1),
677 NO_MUTEX_GUARD, IN_BINLOG);
678
679 static Sys_var_mybool Sys_automatic_sp_privileges(
680 "automatic_sp_privileges",
681 "Creating and dropping stored procedures alters ACLs",
682 GLOBAL_VAR(sp_automatic_privileges),
683 CMD_LINE(OPT_ARG), DEFAULT(TRUE));
684
685 static Sys_var_ulong Sys_back_log(
686 "back_log", "The number of outstanding connection requests "
687 "MySQL can have. This comes into play when the main MySQL thread "
688 "gets very many connection requests in a very short time",
689 READ_ONLY GLOBAL_VAR(back_log), CMD_LINE(REQUIRED_ARG),
690 VALID_RANGE(0, 65535), DEFAULT(0), BLOCK_SIZE(1));
691
692 static Sys_var_charptr Sys_basedir(
693 "basedir", "Path to installation directory. All paths are "
694 "usually resolved relative to this",
695 READ_ONLY GLOBAL_VAR(mysql_home_ptr), CMD_LINE(REQUIRED_ARG, 'b'),
696 IN_FS_CHARSET, DEFAULT(0));
697
698 static Sys_var_charptr Sys_default_authentication_plugin(
699 "default_authentication_plugin", "The default authentication plugin "
700 "used by the server to hash the password.",
701 READ_ONLY GLOBAL_VAR(default_auth_plugin), CMD_LINE(REQUIRED_ARG),
702 IN_FS_CHARSET, DEFAULT("mysql_native_password"));
703
704 static PolyLock_mutex Plock_default_password_lifetime(
705 &LOCK_default_password_lifetime);
706 static Sys_var_uint Sys_default_password_lifetime(
707 "default_password_lifetime", "The number of days after which the "
708 "password will expire.",
709 GLOBAL_VAR(default_password_lifetime), CMD_LINE(REQUIRED_ARG),
710 VALID_RANGE(0, UINT_MAX16), DEFAULT(0), BLOCK_SIZE(1),
711 &Plock_default_password_lifetime);
712
713 #ifndef EMBEDDED_LIBRARY
714 static Sys_var_charptr Sys_my_bind_addr(
715 "bind_address", "IP address to bind to.",
716 READ_ONLY GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG),
717 IN_FS_CHARSET, DEFAULT(MY_BIND_ALL_ADDRESSES));
718 #endif
719
720 static Sys_var_charptr Sys_my_proxy_protocol_networks(
721 "proxy_protocol_networks", "Enable proxy protocol for these source "
722 "networks. The syntax is a comma separated list of IPv4 and IPv6 "
723 "networks. If the network doesn't contain mask, it is considered to be "
724 "a single host. \"*\" represents all networks and must the only "
725 "directive on the line.",
726 READ_ONLY GLOBAL_VAR(my_proxy_protocol_networks),
727 CMD_LINE(REQUIRED_ARG), IN_FS_CHARSET, DEFAULT(""));
728
fix_binlog_cache_size(sys_var * self,THD * thd,enum_var_type type)729 static bool fix_binlog_cache_size(sys_var *self, THD *thd, enum_var_type type)
730 {
731 check_binlog_cache_size(thd);
732 return false;
733 }
734
fix_binlog_stmt_cache_size(sys_var * self,THD * thd,enum_var_type type)735 static bool fix_binlog_stmt_cache_size(sys_var *self, THD *thd, enum_var_type type)
736 {
737 check_binlog_stmt_cache_size(thd);
738 return false;
739 }
740
741 static Sys_var_ulong Sys_binlog_cache_size(
742 "binlog_cache_size", "The size of the transactional cache for "
743 "updates to transactional engines for the binary log. "
744 "If you often use transactions containing many statements, "
745 "you can increase this to get more performance",
746 GLOBAL_VAR(binlog_cache_size),
747 CMD_LINE(REQUIRED_ARG),
748 VALID_RANGE(IO_SIZE, ULONG_MAX), DEFAULT(32768), BLOCK_SIZE(IO_SIZE),
749 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
750 ON_UPDATE(fix_binlog_cache_size));
751
752 static Sys_var_ulong Sys_binlog_stmt_cache_size(
753 "binlog_stmt_cache_size", "The size of the statement cache for "
754 "updates to non-transactional engines for the binary log. "
755 "If you often use statements updating a great number of rows, "
756 "you can increase this to get more performance",
757 GLOBAL_VAR(binlog_stmt_cache_size),
758 CMD_LINE(REQUIRED_ARG),
759 VALID_RANGE(IO_SIZE, ULONG_MAX), DEFAULT(32768), BLOCK_SIZE(IO_SIZE),
760 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
761 ON_UPDATE(fix_binlog_stmt_cache_size));
762
763 static Sys_var_int32 Sys_binlog_max_flush_queue_time(
764 "binlog_max_flush_queue_time",
765 "The maximum time that the binary log group commit will keep reading"
766 " transactions before it flush the transactions to the binary log (and"
767 " optionally sync, depending on the value of sync_binlog).",
768 GLOBAL_VAR(opt_binlog_max_flush_queue_time),
769 CMD_LINE(REQUIRED_ARG, OPT_BINLOG_MAX_FLUSH_QUEUE_TIME),
770 VALID_RANGE(0, 100000), DEFAULT(0), BLOCK_SIZE(1),
771 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
772 DEPRECATED_VAR(""));
773
774 static Sys_var_long Sys_binlog_group_commit_sync_delay(
775 "binlog_group_commit_sync_delay",
776 "The number of microseconds the server waits for the "
777 "binary log group commit sync queue to fill before "
778 "continuing. Default: 0. Min: 0. Max: 1000000.",
779 GLOBAL_VAR(opt_binlog_group_commit_sync_delay),
780 CMD_LINE(REQUIRED_ARG),
781 VALID_RANGE(0, 1000000 /* max 1 sec */), DEFAULT(0), BLOCK_SIZE(1),
782 NO_MUTEX_GUARD, NOT_IN_BINLOG);
783
784 static Sys_var_ulong Sys_binlog_group_commit_sync_no_delay_count(
785 "binlog_group_commit_sync_no_delay_count",
786 "If there are this many transactions in the commit sync "
787 "queue and the server is waiting for more transactions "
788 "to be enqueued (as set using --binlog-group-commit-sync-delay), "
789 "the commit procedure resumes.",
790 GLOBAL_VAR(opt_binlog_group_commit_sync_no_delay_count),
791 CMD_LINE(REQUIRED_ARG),
792 VALID_RANGE(0, 100000 /* max connections */),
793 DEFAULT(0), BLOCK_SIZE(1),
794 NO_MUTEX_GUARD, NOT_IN_BINLOG);
795
check_has_super(sys_var * self,THD * thd,set_var * var)796 static bool check_has_super(sys_var *self, THD *thd, set_var *var)
797 {
798 assert(self->scope() != sys_var::GLOBAL);// don't abuse check_has_super()
799 #ifndef NO_EMBEDDED_ACCESS_CHECKS
800 if (!(thd->security_context()->check_access(SUPER_ACL)))
801 {
802 my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER");
803 return true;
804 }
805 #endif
806 return false;
807 }
808
check_outside_trx(sys_var * self,THD * thd,set_var * var)809 static bool check_outside_trx(sys_var *self, THD *thd, set_var *var)
810 {
811 if (thd->in_active_multi_stmt_transaction())
812 {
813 my_error(ER_VARIABLE_NOT_SETTABLE_IN_TRANSACTION, MYF(0), var->var->name.str);
814 return true;
815 }
816 if (!thd->owned_gtid.is_empty())
817 {
818 char buf[Gtid::MAX_TEXT_LENGTH + 1];
819 if (thd->owned_gtid.sidno > 0)
820 thd->owned_gtid.to_string(thd->owned_sid, buf);
821 else
822 strcpy(buf, "ANONYMOUS");
823 my_error(ER_CANT_SET_VARIABLE_WHEN_OWNING_GTID, MYF(0), var->var->name.str, buf);
824 return true;
825 }
826 return false;
827 }
828
check_super_outside_trx_outside_sf(sys_var * self,THD * thd,set_var * var)829 static bool check_super_outside_trx_outside_sf(sys_var *self, THD *thd, set_var *var)
830 {
831 if (thd->in_sub_stmt)
832 {
833 my_error(ER_VARIABLE_NOT_SETTABLE_IN_SF_OR_TRIGGER, MYF(0), var->var->name.str);
834 return true;
835 }
836 if (check_outside_trx(self, thd, var))
837 return true;
838 if (self->scope() != sys_var::GLOBAL)
839 return check_has_super(self, thd, var);
840 return false;
841 }
842
check_explicit_defaults_for_timestamp(sys_var * self,THD * thd,set_var * var)843 static bool check_explicit_defaults_for_timestamp(sys_var *self, THD *thd, set_var *var)
844 {
845 if (thd->in_sub_stmt)
846 {
847 my_error(ER_VARIABLE_NOT_SETTABLE_IN_SF_OR_TRIGGER, MYF(0), var->var->name.str);
848 return true;
849 }
850 if (thd->in_active_multi_stmt_transaction())
851 {
852 my_error(ER_VARIABLE_NOT_SETTABLE_IN_TRANSACTION, MYF(0), var->var->name.str);
853 return true;
854 }
855 if (self->scope() != sys_var::GLOBAL)
856 return check_has_super(self, thd, var);
857 return false;
858 }
859
860 #ifdef HAVE_REPLICATION
861 /**
862 Check-function to @@GTID_NEXT system variable.
863
864 @param self a pointer to the sys_var, i.e. gtid_next
865 @param thd a reference to THD object
866 @param var a pointer to the set_var created by the parser.
867
868 @return @c false if the change is allowed, otherwise @c true.
869 */
870
check_gtid_next(sys_var * self,THD * thd,set_var * var)871 static bool check_gtid_next(sys_var *self, THD *thd, set_var *var)
872 {
873 bool is_prepared_trx=
874 thd->get_transaction()->xid_state()->has_state(XID_STATE::XA_PREPARED);
875
876 if (thd->in_sub_stmt)
877 {
878 my_error(ER_VARIABLE_NOT_SETTABLE_IN_SF_OR_TRIGGER, MYF(0), var->var->name.str);
879 return true;
880 }
881 if (!is_prepared_trx && thd->in_active_multi_stmt_transaction())
882 {
883 my_error(ER_VARIABLE_NOT_SETTABLE_IN_TRANSACTION, MYF(0), var->var->name.str);
884 return true;
885 }
886 return check_has_super(self, thd, var);
887 }
888 #endif
889
check_super_outside_trx_outside_sf_outside_sp(sys_var * self,THD * thd,set_var * var)890 static bool check_super_outside_trx_outside_sf_outside_sp(sys_var *self, THD *thd, set_var *var)
891 {
892 if (check_super_outside_trx_outside_sf(self, thd, var))
893 return true;
894 if (thd->lex->sphead)
895 {
896 my_error(ER_VARIABLE_NOT_SETTABLE_IN_SP, MYF(0), var->var->name.str);
897 return true;
898 }
899 return false;
900 }
901
binlog_format_check(sys_var * self,THD * thd,set_var * var)902 static bool binlog_format_check(sys_var *self, THD *thd, set_var *var)
903 {
904 if (check_has_super(self, thd, var))
905 return true;
906
907 if (var->type == OPT_GLOBAL)
908 return false;
909
910 /*
911 If RBR and open temporary tables, their CREATE TABLE may not be in the
912 binlog, so we can't toggle to SBR in this connection.
913
914 If binlog_format=MIXED, there are open temporary tables, and an unsafe
915 statement is executed, then subsequent statements are logged in row
916 format and hence changes to temporary tables may be lost. So we forbid
917 switching @@SESSION.binlog_format from MIXED to STATEMENT when there are
918 open temp tables and we are logging in row format.
919 */
920 if (thd->temporary_tables && var->type == OPT_SESSION &&
921 var->save_result.ulonglong_value == BINLOG_FORMAT_STMT &&
922 ((thd->variables.binlog_format == BINLOG_FORMAT_MIXED &&
923 thd->is_current_stmt_binlog_format_row()) ||
924 thd->variables.binlog_format == BINLOG_FORMAT_ROW))
925 {
926 my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
927 return true;
928 }
929
930 /*
931 if in a stored function/trigger, it's too late to change mode
932 */
933 if (thd->in_sub_stmt)
934 {
935 my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
936 return true;
937 }
938 /*
939 Make the session variable 'binlog_format' read-only inside a transaction.
940 */
941 if (thd->in_active_multi_stmt_transaction())
942 {
943 my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
944 return true;
945 }
946
947 return false;
948 }
949
fix_binlog_format_after_update(sys_var * self,THD * thd,enum_var_type type)950 static bool fix_binlog_format_after_update(sys_var *self, THD *thd,
951 enum_var_type type)
952 {
953 if (type == OPT_SESSION)
954 thd->reset_current_stmt_binlog_format_row();
955 return false;
956 }
957
prevent_global_rbr_exec_mode_idempotent(sys_var * self,THD * thd,set_var * var)958 static bool prevent_global_rbr_exec_mode_idempotent(sys_var *self, THD *thd,
959 set_var *var )
960 {
961 if (var->type == OPT_GLOBAL)
962 {
963 my_error(ER_LOCAL_VARIABLE, MYF(0), self->name.str);
964 return true;
965 }
966 return false;
967 }
968
969 static Sys_var_test_flag Sys_core_file(
970 "core_file", "write a core-file on crashes", TEST_CORE_ON_SIGNAL);
971
972 static Sys_var_enum Sys_binlog_format(
973 "binlog_format", "What form of binary logging the master will "
974 "use: either ROW for row-based binary logging, STATEMENT "
975 "for statement-based binary logging, or MIXED. MIXED is statement-"
976 "based binary logging except for those statements where only row-"
977 "based is correct: those which involve user-defined functions (i.e. "
978 "UDFs) or the UUID() function; for those, row-based binary logging is "
979 "automatically used. If NDBCLUSTER is enabled and binlog-format is "
980 "MIXED, the format switches to row-based and back implicitly per each "
981 "query accessing an NDBCLUSTER table",
982 SESSION_VAR(binlog_format), CMD_LINE(REQUIRED_ARG, OPT_BINLOG_FORMAT),
983 binlog_format_names, DEFAULT(BINLOG_FORMAT_ROW),
984 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_format_check),
985 ON_UPDATE(fix_binlog_format_after_update));
986
987 static const char *rbr_exec_mode_names[]=
988 {"STRICT", "IDEMPOTENT", 0};
989 static Sys_var_enum rbr_exec_mode(
990 "rbr_exec_mode",
991 "Modes for how row events should be executed. Legal values "
992 "are STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, "
993 "the server will not throw errors for operations that are idempotent. "
994 "In STRICT mode, server will throw errors for the operations that "
995 "cause a conflict.",
996 SESSION_VAR(rbr_exec_mode_options), NO_CMD_LINE,
997 rbr_exec_mode_names, DEFAULT(RBR_EXEC_MODE_STRICT),
998 NO_MUTEX_GUARD, NOT_IN_BINLOG,
999 ON_CHECK(prevent_global_rbr_exec_mode_idempotent),
1000 ON_UPDATE(NULL));
1001
1002 static Sys_var_mybool Sys_binlog_encryption(
1003 "encrypt_binlog", "Encrypt binary logs (including relay logs)",
1004 READ_ONLY GLOBAL_VAR(encrypt_binlog), CMD_LINE(OPT_ARG),
1005 DEFAULT(FALSE));
1006
1007 static const char *binlog_row_image_names[]= {"MINIMAL", "NOBLOB", "FULL", NullS};
1008 static Sys_var_enum Sys_binlog_row_image(
1009 "binlog_row_image",
1010 "Controls whether rows should be logged in 'FULL', 'NOBLOB' or "
1011 "'MINIMAL' formats. 'FULL', means that all columns in the before "
1012 "and after image are logged. 'NOBLOB', means that mysqld avoids logging "
1013 "blob columns whenever possible (eg, blob column was not changed or "
1014 "is not part of primary key). 'MINIMAL', means that a PK equivalent (PK "
1015 "columns or full row if there is no PK in the table) is logged in the "
1016 "before image, and only changed columns are logged in the after image. "
1017 "(Default: FULL).",
1018 SESSION_VAR(binlog_row_image), CMD_LINE(REQUIRED_ARG),
1019 binlog_row_image_names, DEFAULT(BINLOG_ROW_IMAGE_FULL),
1020 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
1021 ON_UPDATE(NULL));
1022
on_session_track_gtids_update(sys_var * self,THD * thd,enum_var_type type)1023 static bool on_session_track_gtids_update(sys_var *self, THD *thd,
1024 enum_var_type type)
1025 {
1026 thd->session_tracker.get_tracker(SESSION_GTIDS_TRACKER)->update(thd);
1027 return false;
1028 }
1029
1030 static const char *session_track_gtids_names[]=
1031 { "OFF", "OWN_GTID", "ALL_GTIDS", NullS };
1032 static Sys_var_enum Sys_session_track_gtids(
1033 "session_track_gtids",
1034 "Controls the amount of global transaction ids to be "
1035 "included in the response packet sent by the server."
1036 "(Default: OFF).",
1037 SESSION_VAR(session_track_gtids), CMD_LINE(REQUIRED_ARG),
1038 session_track_gtids_names, DEFAULT(OFF),
1039 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_outside_trx),
1040 ON_UPDATE(on_session_track_gtids_update));
1041
binlog_direct_check(sys_var * self,THD * thd,set_var * var)1042 static bool binlog_direct_check(sys_var *self, THD *thd, set_var *var)
1043 {
1044 if (check_has_super(self, thd, var))
1045 return true;
1046
1047 if (var->type == OPT_GLOBAL)
1048 return false;
1049
1050 /*
1051 Makes the session variable 'binlog_direct_non_transactional_updates'
1052 read-only if within a procedure, trigger or function.
1053 */
1054 if (thd->in_sub_stmt)
1055 {
1056 my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0));
1057 return true;
1058 }
1059 /*
1060 Makes the session variable 'binlog_direct_non_transactional_updates'
1061 read-only inside a transaction.
1062 */
1063 if (thd->in_active_multi_stmt_transaction())
1064 {
1065 my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0));
1066 return true;
1067 }
1068
1069 return false;
1070 }
1071
1072 static Sys_var_mybool Sys_binlog_direct(
1073 "binlog_direct_non_transactional_updates",
1074 "Causes updates to non-transactional engines using statement format to "
1075 "be written directly to binary log. Before using this option make sure "
1076 "that there are no dependencies between transactional and "
1077 "non-transactional tables such as in the statement INSERT INTO t_myisam "
1078 "SELECT * FROM t_innodb; otherwise, slaves may diverge from the master.",
1079 SESSION_VAR(binlog_direct_non_trans_update),
1080 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
1081 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_direct_check));
1082
1083 /**
1084 This variable is read only to users. It can be enabled or disabled
1085 only at mysqld startup. This variable is used by User thread and
1086 as well as by replication slave applier thread to apply relay_log.
1087 Slave applier thread enables/disables this option based on
1088 relay_log's from replication master versions. There is possibility of
1089 slave applier thread and User thread to have different setting for
1090 explicit_defaults_for_timestamp, hence this options is defined as
1091 SESSION_VAR rather than GLOBAL_VAR.
1092 */
1093 static Sys_var_mybool Sys_explicit_defaults_for_timestamp(
1094 "explicit_defaults_for_timestamp",
1095 "This option causes CREATE TABLE to create all TIMESTAMP columns "
1096 "as NULL with DEFAULT NULL attribute, Without this option, "
1097 "TIMESTAMP columns are NOT NULL and have implicit DEFAULT clauses. "
1098 "The old behavior is deprecated. "
1099 "The variable can only be set by users having the SUPER privilege.",
1100 SESSION_VAR(explicit_defaults_for_timestamp),
1101 CMD_LINE(OPT_ARG), DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
1102 ON_CHECK(check_explicit_defaults_for_timestamp));
1103
repository_check(sys_var * self,THD * thd,set_var * var,SLAVE_THD_TYPE thread_mask)1104 static bool repository_check(sys_var *self, THD *thd, set_var *var, SLAVE_THD_TYPE thread_mask)
1105 {
1106 bool ret= FALSE;
1107 if (check_super_outside_trx_outside_sf(self, thd, var))
1108 return TRUE;
1109 #ifdef HAVE_REPLICATION
1110 Master_info *mi;
1111 int running= 0;
1112 const char *msg= NULL;
1113 bool rpl_info_option= static_cast<uint>(var->save_result.ulonglong_value);
1114
1115 /* don't convert if the repositories are same */
1116 if (rpl_info_option == (thread_mask== SLAVE_THD_IO ?
1117 opt_mi_repository_id: opt_rli_repository_id))
1118 return FALSE;
1119
1120 channel_map.wrlock();
1121
1122 /* Repository conversion not possible, when multiple channels exist */
1123 if (channel_map.get_num_instances(true) > 1)
1124 {
1125 msg= "Repository conversion is possible when only default channel exists";
1126 my_error(ER_CHANGE_RPL_INFO_REPOSITORY_FAILURE, MYF(0), msg);
1127 channel_map.unlock();
1128 return TRUE;
1129 }
1130
1131 mi= channel_map.get_default_channel_mi();
1132
1133 if (mi != NULL)
1134 {
1135 mi->channel_wrlock();
1136 lock_slave_threads(mi);
1137 init_thread_mask(&running, mi, FALSE);
1138 if(!running)
1139 {
1140 switch (thread_mask)
1141 {
1142 case SLAVE_THD_IO:
1143 if (Rpl_info_factory::
1144 change_mi_repository(mi,
1145 static_cast<uint>(var->save_result.
1146 ulonglong_value),
1147 &msg))
1148 {
1149 ret= TRUE;
1150 my_error(ER_CHANGE_RPL_INFO_REPOSITORY_FAILURE, MYF(0), msg);
1151 }
1152 break;
1153 case SLAVE_THD_SQL:
1154 mts_recovery_groups(mi->rli);
1155 if (!mi->rli->is_mts_recovery())
1156 {
1157 if (Rpl_info_factory::reset_workers(mi->rli) ||
1158 Rpl_info_factory::
1159 change_rli_repository(mi->rli,
1160 static_cast<uint>(var->save_result.
1161 ulonglong_value),
1162 &msg))
1163 {
1164 ret= TRUE;
1165 my_error(ER_CHANGE_RPL_INFO_REPOSITORY_FAILURE, MYF(0), msg);
1166 }
1167 }
1168 else
1169 sql_print_warning("It is not possible to change the type of the "
1170 "relay log's repository because there are workers' "
1171 "repositories with gaps. Please, fix the gaps first "
1172 "before doing such change.");
1173 break;
1174 default:
1175 assert(0);
1176 break;
1177 }
1178 }
1179 else
1180 {
1181 ret= TRUE;
1182 my_error(ER_SLAVE_CHANNEL_MUST_STOP, MYF(0),mi->get_channel());
1183 }
1184 unlock_slave_threads(mi);
1185 mi->channel_unlock();
1186 }
1187 channel_map.unlock();
1188 #endif
1189 return ret;
1190 }
1191
relay_log_info_repository_check(sys_var * self,THD * thd,set_var * var)1192 static bool relay_log_info_repository_check(sys_var *self, THD *thd, set_var *var)
1193 {
1194 return repository_check(self, thd, var, SLAVE_THD_SQL);
1195 }
1196
master_info_repository_check(sys_var * self,THD * thd,set_var * var)1197 static bool master_info_repository_check(sys_var *self, THD *thd, set_var *var)
1198 {
1199 return repository_check(self, thd, var, SLAVE_THD_IO);
1200 }
1201
1202 static const char *repository_names[]=
1203 {
1204 "FILE", "TABLE",
1205 #ifndef NDEBUG
1206 "DUMMY",
1207 #endif
1208 0
1209 };
1210
1211 ulong opt_mi_repository_id= INFO_REPOSITORY_FILE;
1212 static Sys_var_enum Sys_mi_repository(
1213 "master_info_repository",
1214 "Defines the type of the repository for the master information."
1215 ,GLOBAL_VAR(opt_mi_repository_id), CMD_LINE(REQUIRED_ARG),
1216 repository_names, DEFAULT(INFO_REPOSITORY_FILE), NO_MUTEX_GUARD,
1217 NOT_IN_BINLOG, ON_CHECK(master_info_repository_check),
1218 ON_UPDATE(0));
1219
1220 ulong opt_rli_repository_id= INFO_REPOSITORY_FILE;
1221 static Sys_var_enum Sys_rli_repository(
1222 "relay_log_info_repository",
1223 "Defines the type of the repository for the relay log information "
1224 "and associated workers."
1225 ,GLOBAL_VAR(opt_rli_repository_id), CMD_LINE(REQUIRED_ARG),
1226 repository_names, DEFAULT(INFO_REPOSITORY_FILE), NO_MUTEX_GUARD,
1227 NOT_IN_BINLOG, ON_CHECK(relay_log_info_repository_check),
1228 ON_UPDATE(0));
1229
1230 static Sys_var_mybool Sys_binlog_rows_query(
1231 "binlog_rows_query_log_events",
1232 "Allow writing of Rows_query_log events into binary log.",
1233 SESSION_VAR(binlog_rows_query_log_events),
1234 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1235
1236 static Sys_var_mybool Sys_binlog_order_commits(
1237 "binlog_order_commits",
1238 "Issue internal commit calls in the same order as transactions are"
1239 " written to the binary log. Default is to order commits.",
1240 GLOBAL_VAR(opt_binlog_order_commits),
1241 CMD_LINE(OPT_ARG), DEFAULT(TRUE));
1242
1243 static Sys_var_ulong Sys_bulk_insert_buff_size(
1244 "bulk_insert_buffer_size", "Size of tree cache used in bulk "
1245 "insert optimisation. Note that this is a limit per thread!",
1246 SESSION_VAR(bulk_insert_buff_size), CMD_LINE(REQUIRED_ARG),
1247 VALID_RANGE(0, ULONG_MAX), DEFAULT(8192*1024), BLOCK_SIZE(1));
1248
1249 static Sys_var_charptr Sys_character_sets_dir(
1250 "character_sets_dir", "Directory where character sets are",
1251 READ_ONLY GLOBAL_VAR(charsets_dir), CMD_LINE(REQUIRED_ARG),
1252 IN_FS_CHARSET, DEFAULT(0));
1253
check_not_null(sys_var * self,THD * thd,set_var * var)1254 static bool check_not_null(sys_var *self, THD *thd, set_var *var)
1255 {
1256 return var->value && var->value->is_null();
1257 }
1258
1259
1260 /**
1261 Check storage engine is not empty and log warning.
1262
1263 Checks if default_storage_engine or default_tmp_storage_engine is set
1264 empty and return true. This method also logs warning if the
1265 storage engine set is a disabled storage engine specified in
1266 disabled_storage_engines.
1267
1268 @param self pointer to system variable object.
1269 @param thd Connection handle.
1270 @param var pointer to set variable object.
1271
1272 @return true if the set variable is empty.
1273 false if the set variable is not empty.
1274 */
check_storage_engine(sys_var * self,THD * thd,set_var * var)1275 static bool check_storage_engine(sys_var *self, THD *thd, set_var *var)
1276 {
1277 if (check_not_null(self,thd,var))
1278 return true;
1279
1280 if (!opt_bootstrap && !opt_noacl)
1281 {
1282 char buff[STRING_BUFFER_USUAL_SIZE];
1283 String str(buff,sizeof(buff), system_charset_info), *res;
1284 LEX_STRING se_name;
1285
1286 if (var->value)
1287 {
1288 res= var->value->val_str(&str);
1289 lex_string_set(&se_name, res->ptr());
1290 }
1291 else
1292 {
1293 // Use the default value defined by sys_var.
1294 lex_string_set(&se_name,
1295 pointer_cast<const char*>(
1296 down_cast<Sys_var_plugin*>(self)->global_value_ptr(thd, NULL)));
1297 }
1298
1299 plugin_ref plugin;
1300 if ((plugin= ha_resolve_by_name(NULL, &se_name, FALSE)))
1301 {
1302 handlerton *hton= plugin_data<handlerton*>(plugin);
1303 if (ha_is_storage_engine_disabled(hton))
1304 sql_print_warning("%s is set to a disabled storage engine %s.",
1305 self->name.str, se_name.str);
1306 plugin_unlock(NULL, plugin);
1307 }
1308 }
1309 return false;
1310 }
1311
check_charset(sys_var * self,THD * thd,set_var * var)1312 static bool check_charset(sys_var *self, THD *thd, set_var *var)
1313 {
1314 if (!var->value)
1315 return false;
1316
1317 char buff[STRING_BUFFER_USUAL_SIZE];
1318 if (var->value->result_type() == STRING_RESULT)
1319 {
1320 String str(buff, sizeof(buff), system_charset_info), *res;
1321 if (!(res= var->value->val_str(&str)))
1322 var->save_result.ptr= NULL;
1323 else
1324 {
1325 ErrConvString err(res); /* Get utf8 '\0' terminated string */
1326 if (!(var->save_result.ptr= get_charset_by_csname(err.ptr(),
1327 MY_CS_PRIMARY,
1328 MYF(0))) &&
1329 !(var->save_result.ptr= get_old_charset_by_name(err.ptr())))
1330 {
1331 my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), err.ptr());
1332 return true;
1333 }
1334 }
1335 }
1336 else // INT_RESULT
1337 {
1338 int csno= (int)var->value->val_int();
1339 if (!(var->save_result.ptr= get_charset(csno, MYF(0))))
1340 {
1341 my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), llstr(csno, buff));
1342 return true;
1343 }
1344 }
1345 return false;
1346 }
check_charset_not_null(sys_var * self,THD * thd,set_var * var)1347 static bool check_charset_not_null(sys_var *self, THD *thd, set_var *var)
1348 {
1349 return check_charset(self, thd, var) || check_not_null(self, thd, var);
1350 }
1351 static Sys_var_struct Sys_character_set_system(
1352 "character_set_system", "The character set used by the server "
1353 "for storing identifiers",
1354 READ_ONLY GLOBAL_VAR(system_charset_info), NO_CMD_LINE,
1355 offsetof(CHARSET_INFO, csname), DEFAULT(0));
1356
1357 static Sys_var_struct Sys_character_set_server(
1358 "character_set_server", "The default character set",
1359 SESSION_VAR(collation_server), NO_CMD_LINE,
1360 offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1361 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_not_null));
1362
check_charset_db(sys_var * self,THD * thd,set_var * var)1363 static bool check_charset_db(sys_var *self, THD *thd, set_var *var)
1364 {
1365 if (check_charset_not_null(self, thd, var))
1366 return true;
1367 if (!var->value) // = DEFAULT
1368 var->save_result.ptr= thd->db_charset;
1369 return false;
1370 }
update_deprecated(sys_var * self,THD * thd,enum_var_type type)1371 static bool update_deprecated(sys_var *self, THD *thd, enum_var_type type)
1372 {
1373 push_warning_printf(thd, Sql_condition::SL_WARNING,
1374 ER_WARN_DEPRECATED_SYNTAX_NO_REPLACEMENT,
1375 ER_THD(thd, ER_WARN_DEPRECATED_SYSVAR_UPDATE),
1376 self->name.str);
1377 return false;
1378 }
1379 static Sys_var_struct Sys_character_set_database(
1380 "character_set_database",
1381 " The character set used by the default database",
1382 SESSION_VAR(collation_database), NO_CMD_LINE,
1383 offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1384 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_db),
1385 ON_UPDATE(update_deprecated));
1386
check_cs_client(sys_var * self,THD * thd,set_var * var)1387 static bool check_cs_client(sys_var *self, THD *thd, set_var *var)
1388 {
1389 if (check_charset_not_null(self, thd, var))
1390 return true;
1391
1392 // Currently, UCS-2 cannot be used as a client character set
1393 if (((CHARSET_INFO *)(var->save_result.ptr))->mbminlen > 1)
1394 return true;
1395
1396 return false;
1397 }
fix_thd_charset(sys_var * self,THD * thd,enum_var_type type)1398 static bool fix_thd_charset(sys_var *self, THD *thd, enum_var_type type)
1399 {
1400 if (type == OPT_SESSION)
1401 thd->update_charset();
1402 return false;
1403 }
1404 static Sys_var_struct Sys_character_set_client(
1405 "character_set_client", "The character set for statements "
1406 "that arrive from the client",
1407 SESSION_VAR(character_set_client), NO_CMD_LINE,
1408 offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1409 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_cs_client),
1410 ON_UPDATE(fix_thd_charset));
1411
1412 static Sys_var_struct Sys_character_set_connection(
1413 "character_set_connection", "The character set used for "
1414 "literals that do not have a character set introducer and for "
1415 "number-to-string conversion",
1416 SESSION_VAR(collation_connection), NO_CMD_LINE,
1417 offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1418 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_not_null),
1419 ON_UPDATE(fix_thd_charset));
1420
1421 static Sys_var_struct Sys_character_set_results(
1422 "character_set_results", "The character set used for returning "
1423 "query results to the client",
1424 SESSION_VAR(character_set_results), NO_CMD_LINE,
1425 offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1426 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_charset));
1427
1428 static Sys_var_struct Sys_character_set_filesystem(
1429 "character_set_filesystem", "The filesystem character set",
1430 SESSION_VAR(character_set_filesystem), NO_CMD_LINE,
1431 offsetof(CHARSET_INFO, csname), DEFAULT(&character_set_filesystem),
1432 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_charset_not_null),
1433 ON_UPDATE(fix_thd_charset));
1434
1435 static const char *completion_type_names[]= {"NO_CHAIN", "CHAIN", "RELEASE", 0};
1436 static Sys_var_enum Sys_completion_type(
1437 "completion_type", "The transaction completion type, one of "
1438 "NO_CHAIN, CHAIN, RELEASE",
1439 SESSION_VAR(completion_type), CMD_LINE(REQUIRED_ARG),
1440 completion_type_names, DEFAULT(0));
1441
check_collation_not_null(sys_var * self,THD * thd,set_var * var)1442 static bool check_collation_not_null(sys_var *self, THD *thd, set_var *var)
1443 {
1444 if (!var->value)
1445 return false;
1446
1447 char buff[STRING_BUFFER_USUAL_SIZE];
1448 if (var->value->result_type() == STRING_RESULT)
1449 {
1450 String str(buff, sizeof(buff), system_charset_info), *res;
1451 if (!(res= var->value->val_str(&str)))
1452 var->save_result.ptr= NULL;
1453 else
1454 {
1455 ErrConvString err(res); /* Get utf8 '\0'-terminated string */
1456 if (!(var->save_result.ptr= get_charset_by_name(err.ptr(), MYF(0))))
1457 {
1458 my_error(ER_UNKNOWN_COLLATION, MYF(0), err.ptr());
1459 return true;
1460 }
1461 }
1462 }
1463 else // INT_RESULT
1464 {
1465 int csno= (int)var->value->val_int();
1466 if (!(var->save_result.ptr= get_charset(csno, MYF(0))))
1467 {
1468 my_error(ER_UNKNOWN_COLLATION, MYF(0), llstr(csno, buff));
1469 return true;
1470 }
1471 }
1472 return check_not_null(self, thd, var);
1473 }
1474 static Sys_var_struct Sys_collation_connection(
1475 "collation_connection", "The collation of the connection "
1476 "character set",
1477 SESSION_VAR(collation_connection), NO_CMD_LINE,
1478 offsetof(CHARSET_INFO, name), DEFAULT(&default_charset_info),
1479 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_collation_not_null),
1480 ON_UPDATE(fix_thd_charset));
1481
check_collation_db(sys_var * self,THD * thd,set_var * var)1482 static bool check_collation_db(sys_var *self, THD *thd, set_var *var)
1483 {
1484 if (check_collation_not_null(self, thd, var))
1485 return true;
1486 if (!var->value) // = DEFAULT
1487 var->save_result.ptr= thd->db_charset;
1488 return false;
1489 }
1490 static Sys_var_struct Sys_collation_database(
1491 "collation_database", "The collation of the database "
1492 "character set",
1493 SESSION_VAR(collation_database), NO_CMD_LINE,
1494 offsetof(CHARSET_INFO, name), DEFAULT(&default_charset_info),
1495 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_collation_db),
1496 ON_UPDATE(update_deprecated));
1497
1498 static Sys_var_struct Sys_collation_server(
1499 "collation_server", "The server default collation",
1500 SESSION_VAR(collation_server), NO_CMD_LINE,
1501 offsetof(CHARSET_INFO, name), DEFAULT(&default_charset_info),
1502 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_collation_not_null));
1503
1504 static const char *concurrent_insert_names[]= {"NEVER", "AUTO", "ALWAYS", 0};
1505 static Sys_var_enum Sys_concurrent_insert(
1506 "concurrent_insert", "Use concurrent insert with MyISAM. Possible "
1507 "values are NEVER, AUTO, ALWAYS",
1508 GLOBAL_VAR(myisam_concurrent_insert), CMD_LINE(OPT_ARG),
1509 concurrent_insert_names, DEFAULT(1));
1510
1511 static Sys_var_ulong Sys_connect_timeout(
1512 "connect_timeout",
1513 "The number of seconds the mysqld server is waiting for a connect "
1514 "packet before responding with 'Bad handshake'",
1515 GLOBAL_VAR(connect_timeout), CMD_LINE(REQUIRED_ARG),
1516 VALID_RANGE(2, LONG_TIMEOUT), DEFAULT(CONNECT_TIMEOUT), BLOCK_SIZE(1));
1517
1518 static Sys_var_charptr Sys_datadir(
1519 "datadir", "Path to the database root directory",
1520 READ_ONLY GLOBAL_VAR(mysql_real_data_home_ptr),
1521 CMD_LINE(REQUIRED_ARG, 'h'), IN_FS_CHARSET, DEFAULT(mysql_real_data_home));
1522
1523 #ifndef NDEBUG
1524 static Sys_var_dbug Sys_dbug(
1525 "debug", "Debug log", sys_var::SESSION,
1526 CMD_LINE(OPT_ARG, '#'), DEFAULT(""), NO_MUTEX_GUARD, NOT_IN_BINLOG,
1527 ON_CHECK(check_has_super));
1528 #endif
1529
1530 /**
1531 @todo
1532 When updating myisam_delay_key_write, we should do a 'flush tables'
1533 of all MyISAM tables to ensure that they are reopen with the
1534 new attribute.
1535 */
fix_delay_key_write(sys_var * self,THD * thd,enum_var_type type)1536 export bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type)
1537 {
1538 switch (delay_key_write_options) {
1539 case DELAY_KEY_WRITE_NONE:
1540 myisam_delay_key_write=0;
1541 break;
1542 case DELAY_KEY_WRITE_ON:
1543 myisam_delay_key_write=1;
1544 break;
1545 case DELAY_KEY_WRITE_ALL:
1546 myisam_delay_key_write=1;
1547 ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
1548 break;
1549 }
1550 return false;
1551 }
1552
1553 /**
1554 Make sure we don't have an active TABLE FOR BACKUP lock when setting
1555 delay_key_writes=ALL dynamically.
1556 */
check_delay_key_write(sys_var * self,THD * thd,set_var * var)1557 static bool check_delay_key_write(sys_var *self, THD *thd, set_var *var)
1558 {
1559 assert(delay_key_write_options != DELAY_KEY_WRITE_ALL ||
1560 !thd->backup_tables_lock.is_acquired());
1561
1562 if (var->save_result.ulonglong_value == DELAY_KEY_WRITE_ALL)
1563 {
1564 const ulong timeout= thd->variables.lock_wait_timeout;
1565
1566 if (thd->backup_tables_lock.abort_if_acquired() ||
1567 thd->backup_tables_lock.acquire_protection(thd, MDL_STATEMENT, timeout))
1568 return true;
1569 }
1570
1571 return false;
1572 }
1573
1574 static const char *delay_key_write_names[]= { "OFF", "ON", "ALL", NullS };
1575 static Sys_var_enum Sys_delay_key_write(
1576 "delay_key_write", "Type of DELAY_KEY_WRITE",
1577 GLOBAL_VAR(delay_key_write_options), CMD_LINE(OPT_ARG),
1578 delay_key_write_names, DEFAULT(DELAY_KEY_WRITE_ON),
1579 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_delay_key_write),
1580 ON_UPDATE(fix_delay_key_write));
1581
1582 static Sys_var_ulong Sys_delayed_insert_limit(
1583 "delayed_insert_limit",
1584 "After inserting delayed_insert_limit rows, the INSERT DELAYED "
1585 "handler will check if there are any SELECT statements pending. "
1586 "If so, it allows these to execute before continuing. "
1587 "This variable is deprecated along with INSERT DELAYED.",
1588 GLOBAL_VAR(delayed_insert_limit), CMD_LINE(REQUIRED_ARG),
1589 VALID_RANGE(1, ULONG_MAX), DEFAULT(DELAYED_LIMIT), BLOCK_SIZE(1),
1590 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
1591 DEPRECATED_VAR(""));
1592
1593 static Sys_var_ulong Sys_delayed_insert_timeout(
1594 "delayed_insert_timeout",
1595 "How long a INSERT DELAYED thread should wait for INSERT statements "
1596 "before terminating. "
1597 "This variable is deprecated along with INSERT DELAYED.",
1598 GLOBAL_VAR(delayed_insert_timeout), CMD_LINE(REQUIRED_ARG),
1599 VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(DELAYED_WAIT_TIMEOUT),
1600 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1601 ON_UPDATE(0), DEPRECATED_VAR(""));
1602
1603 static Sys_var_ulong Sys_delayed_queue_size(
1604 "delayed_queue_size",
1605 "What size queue (in rows) should be allocated for handling INSERT "
1606 "DELAYED. If the queue becomes full, any client that does INSERT "
1607 "DELAYED will wait until there is room in the queue again. "
1608 "This variable is deprecated along with INSERT DELAYED.",
1609 GLOBAL_VAR(delayed_queue_size), CMD_LINE(REQUIRED_ARG),
1610 VALID_RANGE(1, ULONG_MAX), DEFAULT(DELAYED_QUEUE_SIZE), BLOCK_SIZE(1),
1611 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
1612 DEPRECATED_VAR(""));
1613
1614 #ifndef EMBEDDED_LIBRARY
1615 static const char *event_scheduler_names[]= { "OFF", "ON", "DISABLED", NullS };
event_scheduler_check(sys_var * self,THD * thd,set_var * var)1616 static bool event_scheduler_check(sys_var *self, THD *thd, set_var *var)
1617 {
1618 /* DISABLED is only accepted on the command line */
1619 if (var->save_result.ulonglong_value == Events::EVENTS_DISABLED)
1620 return true;
1621 /*
1622 If the scheduler was disabled because there are no/bad
1623 system tables, produce a more meaningful error message
1624 than ER_OPTION_PREVENTS_STATEMENT
1625 */
1626 if (Events::check_if_system_tables_error())
1627 return true;
1628 if (Events::opt_event_scheduler == Events::EVENTS_DISABLED)
1629 {
1630 my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
1631 "--event-scheduler=DISABLED or --skip-grant-tables");
1632 return true;
1633 }
1634 return false;
1635 }
event_scheduler_update(sys_var * self,THD * thd,enum_var_type type)1636 static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type)
1637 {
1638 int err_no= 0;
1639 ulong opt_event_scheduler_value= Events::opt_event_scheduler;
1640 mysql_mutex_unlock(&LOCK_global_system_variables);
1641 /*
1642 Events::start() is heavyweight. In particular it creates a new THD,
1643 which takes LOCK_global_system_variables internally.
1644 Thus we have to release it here.
1645 We need to re-take it before returning, though.
1646
1647 Note that since we release LOCK_global_system_variables before calling
1648 start/stop, there is a possibility that the server variable
1649 can become out of sync with the real event scheduler state.
1650
1651 This can happen with two concurrent statments if the first gets
1652 interrupted after start/stop but before retaking
1653 LOCK_global_system_variables. However, this problem should be quite
1654 rare and it's difficult to avoid it without opening up possibilities
1655 for deadlocks. See bug#51160.
1656 */
1657 bool ret= opt_event_scheduler_value == Events::EVENTS_ON
1658 ? Events::start(&err_no)
1659 : Events::stop();
1660 mysql_mutex_lock(&LOCK_global_system_variables);
1661 if (ret)
1662 {
1663 Events::opt_event_scheduler= Events::EVENTS_OFF;
1664 my_error(ER_EVENT_SET_VAR_ERROR, MYF(0), err_no);
1665 }
1666 return ret;
1667 }
1668
1669 static Sys_var_enum Sys_event_scheduler(
1670 "event_scheduler", "Enable the event scheduler. Possible values are "
1671 "ON, OFF, and DISABLED (keep the event scheduler completely "
1672 "deactivated, it cannot be activated run-time)",
1673 GLOBAL_VAR(Events::opt_event_scheduler), CMD_LINE(OPT_ARG),
1674 event_scheduler_names, DEFAULT(Events::EVENTS_OFF),
1675 NO_MUTEX_GUARD, NOT_IN_BINLOG,
1676 ON_CHECK(event_scheduler_check), ON_UPDATE(event_scheduler_update));
1677 #endif
1678
1679 static Sys_var_mybool Sys_expand_fast_index_creation(
1680 "expand_fast_index_creation",
1681 "Enable/disable improvements to the InnoDB fast index creation "
1682 "functionality. Has no effect when fast index creation is disabled with "
1683 "the fast-index-creation option",
1684 SESSION_VAR(expand_fast_index_creation), CMD_LINE(OPT_ARG),
1685 DEFAULT(FALSE));
1686
1687 static Sys_var_ulong Sys_expire_logs_days(
1688 "expire_logs_days",
1689 "If non-zero, binary logs will be purged after expire_logs_days "
1690 "days; possible purges happen at startup and at binary log rotation",
1691 GLOBAL_VAR(expire_logs_days),
1692 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 99), DEFAULT(0), BLOCK_SIZE(1));
1693
1694 static Sys_var_ulonglong Sys_binlog_space_limit(
1695 "binlog_space_limit", "Maximum space to use for all binary logs. "
1696 "Default is 0, this feature is disabled.",
1697 READ_ONLY GLOBAL_VAR(binlog_space_limit), CMD_LINE(REQUIRED_ARG),
1698 VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
1699
1700 static Sys_var_ulong Sys_max_binlog_files(
1701 "max_binlog_files",
1702 "Maximum number of binlog files. Used with --max-binlog-size this can "
1703 "be used to limit the total amount of disk space used for the binlog. "
1704 "Default is 0, don't limit. "
1705 "This variable is deprecated and will be removed in a future release.",
1706 GLOBAL_VAR(max_binlog_files),
1707 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 102400), DEFAULT(0),
1708 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1709 ON_UPDATE(0), DEPRECATED_VAR(""));
1710
1711 static Sys_var_ulong Sys_max_slowlog_size(
1712 "max_slowlog_size",
1713 "Slow query log will be rotated automatically when the size exceeds "
1714 "this value. The default is 0, don't limit the size.",
1715 GLOBAL_VAR(max_slowlog_size), CMD_LINE(REQUIRED_ARG),
1716 VALID_RANGE(0, 1024*1024L*1024L), DEFAULT(0L),
1717 BLOCK_SIZE(IO_SIZE));
1718
1719 static Sys_var_ulong Sys_max_slowlog_files(
1720 "max_slowlog_files",
1721 "Maximum number of slow query log files. Used with --max-slowlog-size "
1722 "this can be used to limit the total amount of disk space used for the "
1723 "slow query log. "
1724 "Default is 0, don't limit.",
1725 GLOBAL_VAR(max_slowlog_files),
1726 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 102400),
1727 DEFAULT(0), BLOCK_SIZE(1));
1728
1729 static Sys_var_mybool Sys_flush(
1730 "flush", "Flush MyISAM tables to disk between SQL commands",
1731 GLOBAL_VAR(myisam_flush),
1732 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1733
1734 static Sys_var_ulong Sys_flush_time(
1735 "flush_time",
1736 "A dedicated thread is created to flush all tables at the "
1737 "given interval",
1738 GLOBAL_VAR(flush_time),
1739 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, LONG_TIMEOUT),
1740 DEFAULT(0), BLOCK_SIZE(1));
1741
check_ftb_syntax(sys_var * self,THD * thd,set_var * var)1742 static bool check_ftb_syntax(sys_var *self, THD *thd, set_var *var)
1743 {
1744 return ft_boolean_check_syntax_string((uchar*)
1745 (var->save_result.string_value.str));
1746 }
query_cache_flush(sys_var * self,THD * thd,enum_var_type type)1747 static bool query_cache_flush(sys_var *self, THD *thd, enum_var_type type)
1748 {
1749 query_cache.flush();
1750 return false;
1751 }
1752 /// @todo make SESSION_VAR (usability enhancement and a fix for a race condition)
1753 static Sys_var_charptr Sys_ft_boolean_syntax(
1754 "ft_boolean_syntax", "List of operators for "
1755 "MATCH ... AGAINST ( ... IN BOOLEAN MODE)",
1756 GLOBAL_VAR(ft_boolean_syntax),
1757 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
1758 DEFAULT(DEFAULT_FTB_SYNTAX), NO_MUTEX_GUARD,
1759 NOT_IN_BINLOG, ON_CHECK(check_ftb_syntax), ON_UPDATE(query_cache_flush));
1760
1761 static Sys_var_ulong Sys_ft_max_word_len(
1762 "ft_max_word_len",
1763 "The maximum length of the word to be included in a FULLTEXT index. "
1764 "Note: FULLTEXT indexes must be rebuilt after changing this variable",
1765 READ_ONLY GLOBAL_VAR(ft_max_word_len), CMD_LINE(REQUIRED_ARG),
1766 VALID_RANGE(10, HA_FT_MAXCHARLEN), DEFAULT(HA_FT_MAXCHARLEN),
1767 BLOCK_SIZE(1));
1768
1769 static Sys_var_ulong Sys_ft_min_word_len(
1770 "ft_min_word_len",
1771 "The minimum length of the word to be included in a FULLTEXT index. "
1772 "Note: FULLTEXT indexes must be rebuilt after changing this variable",
1773 READ_ONLY GLOBAL_VAR(ft_min_word_len), CMD_LINE(REQUIRED_ARG),
1774 VALID_RANGE(1, HA_FT_MAXCHARLEN), DEFAULT(4), BLOCK_SIZE(1));
1775
1776 /// @todo make it an updatable SESSION_VAR
1777 static Sys_var_ulong Sys_ft_query_expansion_limit(
1778 "ft_query_expansion_limit",
1779 "Number of best matches to use for query expansion",
1780 READ_ONLY GLOBAL_VAR(ft_query_expansion_limit),
1781 CMD_LINE(REQUIRED_ARG),
1782 VALID_RANGE(0, 1000), DEFAULT(20), BLOCK_SIZE(1));
1783
1784 static Sys_var_charptr Sys_ft_stopword_file(
1785 "ft_stopword_file",
1786 "Use stopwords from this file instead of built-in list",
1787 READ_ONLY GLOBAL_VAR(ft_stopword_file), CMD_LINE(REQUIRED_ARG),
1788 IN_FS_CHARSET, DEFAULT(0));
1789
1790 static Sys_var_mybool Sys_ft_query_extra_word_chars(
1791 "ft_query_extra_word_chars",
1792 "If enabled, all non-whitespace characters are considered word symbols "
1793 "for full text search queries",
1794 SESSION_VAR(ft_query_extra_word_chars), CMD_LINE(OPT_ARG),
1795 DEFAULT(FALSE));
1796
1797 static Sys_var_mybool Sys_ignore_builtin_innodb(
1798 "ignore_builtin_innodb",
1799 "IGNORED. This option will be removed in future releases. "
1800 "Disable initialization of builtin InnoDB plugin",
1801 READ_ONLY GLOBAL_VAR(opt_ignore_builtin_innodb),
1802 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1803
check_init_string(sys_var * self,THD * thd,set_var * var)1804 static bool check_init_string(sys_var *self, THD *thd, set_var *var)
1805 {
1806 if (var->save_result.string_value.str == 0)
1807 {
1808 var->save_result.string_value.str= const_cast<char*>("");
1809 var->save_result.string_value.length= 0;
1810 }
1811 return false;
1812 }
1813 static PolyLock_rwlock PLock_sys_init_connect(&LOCK_sys_init_connect);
1814 static Sys_var_lexstring Sys_init_connect(
1815 "init_connect", "Command(s) that are executed for each "
1816 "new connection", GLOBAL_VAR(opt_init_connect),
1817 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
1818 DEFAULT(""), &PLock_sys_init_connect, NOT_IN_BINLOG,
1819 ON_CHECK(check_init_string));
1820
1821 static Sys_var_charptr Sys_init_file(
1822 "init_file", "Read SQL commands from this file at startup",
1823 READ_ONLY GLOBAL_VAR(opt_init_file),
1824 CMD_LINE(REQUIRED_ARG),
1825 IN_FS_CHARSET, DEFAULT(0));
1826
1827 static PolyLock_rwlock PLock_sys_init_slave(&LOCK_sys_init_slave);
1828 static Sys_var_lexstring Sys_init_slave(
1829 "init_slave", "Command(s) that are executed by a slave server "
1830 "each time the SQL thread starts", GLOBAL_VAR(opt_init_slave),
1831 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
1832 DEFAULT(""), &PLock_sys_init_slave,
1833 NOT_IN_BINLOG, ON_CHECK(check_init_string));
1834
1835 static Sys_var_ulong Sys_interactive_timeout(
1836 "interactive_timeout",
1837 "The number of seconds the server waits for activity on an interactive "
1838 "connection before closing it",
1839 SESSION_VAR(net_interactive_timeout),
1840 CMD_LINE(REQUIRED_ARG),
1841 VALID_RANGE(1, INT_MAX32/1000), DEFAULT(NET_WAIT_TIMEOUT), BLOCK_SIZE(1));
1842
1843 static Sys_var_ulong Sys_join_buffer_size(
1844 "join_buffer_size",
1845 "The size of the buffer that is used for full joins",
1846 SESSION_VAR(join_buff_size), CMD_LINE(REQUIRED_ARG),
1847 VALID_RANGE(128, ULONG_MAX), DEFAULT(256 * 1024), BLOCK_SIZE(128));
1848
1849 static Sys_var_keycache Sys_key_buffer_size(
1850 "key_buffer_size", "The size of the buffer used for "
1851 "index blocks for MyISAM tables. Increase this to get better index "
1852 "handling (for all reads and multiple writes) to as much as you can "
1853 "afford",
1854 KEYCACHE_VAR(param_buff_size),
1855 CMD_LINE(REQUIRED_ARG, OPT_KEY_BUFFER_SIZE),
1856 VALID_RANGE(0, SIZE_T_MAX), DEFAULT(KEY_CACHE_SIZE),
1857 BLOCK_SIZE(IO_SIZE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1858 ON_UPDATE(update_buffer_size));
1859
1860 static Sys_var_keycache Sys_key_cache_block_size(
1861 "key_cache_block_size", "The default size of key cache blocks",
1862 KEYCACHE_VAR(param_block_size),
1863 CMD_LINE(REQUIRED_ARG, OPT_KEY_CACHE_BLOCK_SIZE),
1864 VALID_RANGE(512, 1024*16), DEFAULT(KEY_CACHE_BLOCK_SIZE),
1865 BLOCK_SIZE(512), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1866 ON_UPDATE(update_keycache_param));
1867
1868 static Sys_var_keycache Sys_key_cache_division_limit(
1869 "key_cache_division_limit",
1870 "The minimum percentage of warm blocks in key cache",
1871 KEYCACHE_VAR(param_division_limit),
1872 CMD_LINE(REQUIRED_ARG, OPT_KEY_CACHE_DIVISION_LIMIT),
1873 VALID_RANGE(1, 100), DEFAULT(100),
1874 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1875 ON_UPDATE(update_keycache_param));
1876
1877 static Sys_var_keycache Sys_key_cache_age_threshold(
1878 "key_cache_age_threshold", "This characterizes the number of "
1879 "hits a hot block has to be untouched until it is considered aged "
1880 "enough to be downgraded to a warm block. This specifies the "
1881 "percentage ratio of that number of hits to the total number of "
1882 "blocks in key cache",
1883 KEYCACHE_VAR(param_age_threshold),
1884 CMD_LINE(REQUIRED_ARG, OPT_KEY_CACHE_AGE_THRESHOLD),
1885 VALID_RANGE(100, ULONG_MAX), DEFAULT(300),
1886 BLOCK_SIZE(100), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1887 ON_UPDATE(update_keycache_param));
1888
1889 static Sys_var_mybool Sys_large_files_support(
1890 "large_files_support",
1891 "Whether mysqld was compiled with options for large file support",
1892 READ_ONLY GLOBAL_VAR(opt_large_files),
1893 NO_CMD_LINE, DEFAULT(sizeof(my_off_t) > 4));
1894
1895 static Sys_var_uint Sys_large_page_size(
1896 "large_page_size",
1897 "If large page support is enabled, this shows the size of memory pages",
1898 READ_ONLY GLOBAL_VAR(opt_large_page_size), NO_CMD_LINE,
1899 VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
1900
1901 static Sys_var_mybool Sys_large_pages(
1902 "large_pages", "Enable support for large pages",
1903 READ_ONLY GLOBAL_VAR(opt_large_pages),
1904 IF_WIN(NO_CMD_LINE, CMD_LINE(OPT_ARG)), DEFAULT(FALSE));
1905
1906 static Sys_var_charptr Sys_language(
1907 "lc_messages_dir", "Directory where error messages are",
1908 READ_ONLY GLOBAL_VAR(lc_messages_dir_ptr),
1909 CMD_LINE(REQUIRED_ARG, OPT_LC_MESSAGES_DIRECTORY),
1910 IN_FS_CHARSET, DEFAULT(0));
1911
1912 static Sys_var_mybool Sys_local_infile(
1913 "local_infile", "Enable LOAD DATA LOCAL INFILE",
1914 GLOBAL_VAR(opt_local_infile), CMD_LINE(OPT_ARG), DEFAULT(TRUE));
1915
1916 static Sys_var_ulong Sys_lock_wait_timeout(
1917 "lock_wait_timeout",
1918 "Timeout in seconds to wait for a lock before returning an error.",
1919 SESSION_VAR(lock_wait_timeout), CMD_LINE(REQUIRED_ARG),
1920 VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(LONG_TIMEOUT), BLOCK_SIZE(1));
1921
1922 #ifdef HAVE_MLOCKALL
1923 static Sys_var_mybool Sys_locked_in_memory(
1924 "locked_in_memory",
1925 "Whether mysqld was locked in memory with --memlock",
1926 READ_ONLY GLOBAL_VAR(locked_in_memory), NO_CMD_LINE, DEFAULT(FALSE));
1927 #endif
1928
1929 /* this says NO_CMD_LINE, as command-line option takes a string, not a bool */
1930 static Sys_var_mybool Sys_log_bin(
1931 "log_bin", "Whether the binary log is enabled",
1932 READ_ONLY GLOBAL_VAR(opt_bin_log), NO_CMD_LINE, DEFAULT(FALSE));
1933
transaction_write_set_check(sys_var * self,THD * thd,set_var * var)1934 static bool transaction_write_set_check(sys_var *self, THD *thd, set_var *var)
1935 {
1936 #ifdef HAVE_REPLICATION
1937 // Can't change the algorithm when group replication is enabled.
1938 if (is_group_replication_running())
1939 {
1940 my_message(ER_GROUP_REPLICATION_RUNNING,
1941 "The write set algorithm cannot be changed when Group replication"
1942 " is running.", MYF(0));
1943 return true;
1944 }
1945 #endif
1946
1947 if (var->type == OPT_GLOBAL &&
1948 global_system_variables.binlog_format != BINLOG_FORMAT_ROW)
1949 {
1950 my_error(ER_PREVENTS_VARIABLE_WITHOUT_RBR, MYF(0), var->var->name.str);
1951 return true;
1952 }
1953
1954 if (var->type == OPT_SESSION &&
1955 thd->variables.binlog_format != BINLOG_FORMAT_ROW)
1956 {
1957 my_error(ER_PREVENTS_VARIABLE_WITHOUT_RBR, MYF(0), var->var->name.str);
1958 return true;
1959 }
1960 /*
1961 if in a stored function/trigger, it's too late to change
1962 */
1963 if (thd->in_sub_stmt)
1964 {
1965 my_error(ER_VARIABLE_NOT_SETTABLE_IN_TRANSACTION, MYF(0),
1966 var->var->name.str);
1967 return true;
1968 }
1969 /*
1970 Make the session variable 'transaction_write_set_extraction' read-only inside a transaction.
1971 */
1972 if (thd->in_active_multi_stmt_transaction())
1973 {
1974 my_error(ER_VARIABLE_NOT_SETTABLE_IN_TRANSACTION, MYF(0),
1975 var->var->name.str);
1976 return true;
1977 }
1978 /*
1979 Disallow changing variable 'transaction_write_set_extraction' while
1980 binlog_transaction_dependency_tracking is different from COMMIT_ORDER.
1981 */
1982 if (mysql_bin_log.m_dependency_tracker.m_opt_tracking_mode
1983 != DEPENDENCY_TRACKING_COMMIT_ORDER)
1984 {
1985 my_error(ER_WRONG_USAGE, MYF(0),
1986 "transaction_write_set_extraction (changed)",
1987 "binlog_transaction_dependency_tracking (!= COMMIT_ORDER)");
1988 return true;
1989 }
1990 return false;
1991 }
1992
1993 static Sys_var_enum Sys_extract_write_set(
1994 "transaction_write_set_extraction",
1995 "This option is used to let the server know when to "
1996 "extract the write set which will be used for various purposes. ",
1997 SESSION_VAR(transaction_write_set_extraction), CMD_LINE(OPT_ARG),
1998 transaction_write_set_hashing_algorithms,
1999 DEFAULT(HASH_ALGORITHM_OFF), NO_MUTEX_GUARD, NOT_IN_BINLOG,
2000 ON_CHECK(transaction_write_set_check),
2001 ON_UPDATE(NULL));
2002
2003 static Sys_var_ulong Sys_rpl_stop_slave_timeout(
2004 "rpl_stop_slave_timeout",
2005 "Timeout in seconds to wait for slave to stop before returning a "
2006 "warning.",
2007 GLOBAL_VAR(rpl_stop_slave_timeout), CMD_LINE(REQUIRED_ARG),
2008 VALID_RANGE(2, LONG_TIMEOUT), DEFAULT(LONG_TIMEOUT), BLOCK_SIZE(1));
2009
2010 static Sys_var_enum Sys_binlog_error_action(
2011 "binlog_error_action",
2012 "When statements cannot be written to the binary log due to a fatal "
2013 "error, the server can either ignore the error and let the master "
2014 "continue, or abort.", GLOBAL_VAR(binlog_error_action),
2015 CMD_LINE(REQUIRED_ARG), binlog_error_action_list, DEFAULT(ABORT_SERVER));
2016
2017 static Sys_var_mybool Sys_binlog_skip_flush_commands(
2018 "binlog_skip_flush_commands",
2019 "If set to TRUE, FLUSH <XXX> commands will not be be written "
2020 "to the binary log",
2021 GLOBAL_VAR(opt_binlog_skip_flush_commands),
2022 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2023
2024 static Sys_var_mybool Sys_trust_function_creators(
2025 "log_bin_trust_function_creators",
2026 "If set to FALSE (the default), then when --log-bin is used, creation "
2027 "of a stored function (or trigger) is allowed only to users having the "
2028 "SUPER privilege and only if this stored function (trigger) may not "
2029 "break binary logging. Note that if ALL connections to this server "
2030 "ALWAYS use row-based binary logging, the security issues do not "
2031 "exist and the binary logging cannot break, so you can safely set "
2032 "this to TRUE",
2033 GLOBAL_VAR(trust_function_creators),
2034 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2035
2036 static Sys_var_mybool Sys_check_proxy_users(
2037 "check_proxy_users",
2038 "If set to FALSE (the default), then proxy user identity will not be "
2039 "mapped for authentication plugins which support mapping from grant "
2040 "tables. When set to TRUE, users associated with authentication "
2041 "plugins which signal proxy user mapping should be done according to "
2042 "GRANT PROXY privilege definition.",
2043 GLOBAL_VAR(check_proxy_users),
2044 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2045
2046 static Sys_var_mybool Sys_mysql_native_password_proxy_users(
2047 "mysql_native_password_proxy_users",
2048 "If set to FALSE (the default), then the mysql_native_password "
2049 "plugin will not signal for authenticated users to be checked for mapping "
2050 "to proxy users. When set to TRUE, the plugin will flag associated "
2051 "authenticated accounts to be mapped to proxy users when the server option "
2052 "check_proxy_users is enabled.",
2053 GLOBAL_VAR(mysql_native_password_proxy_users),
2054 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2055
2056 static Sys_var_mybool Sys_sha256_password_proxy_users(
2057 "sha256_password_proxy_users",
2058 "If set to FALSE (the default), then the sha256_password authentication "
2059 "plugin will not signal for authenticated users to be checked for mapping "
2060 "to proxy users. When set to TRUE, the plugin will flag associated "
2061 "authenticated accounts to be mapped to proxy users when the server option "
2062 "check_proxy_users is enabled.",
2063 GLOBAL_VAR(sha256_password_proxy_users),
2064 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2065
2066 static Sys_var_mybool Sys_use_v1_row_events(
2067 "log_bin_use_v1_row_events",
2068 "If equal to 1 then version 1 row events are written to a row based "
2069 "binary log. If equal to 0, then the latest version of events are "
2070 "written. "
2071 "This option is useful during some upgrades.",
2072 GLOBAL_VAR(log_bin_use_v1_row_events),
2073 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2074
2075 static Sys_var_charptr Sys_log_error(
2076 "log_error", "Error log file",
2077 READ_ONLY GLOBAL_VAR(log_error_dest),
2078 CMD_LINE(OPT_ARG, OPT_LOG_ERROR),
2079 IN_FS_CHARSET, DEFAULT(disabled_my_option), NO_MUTEX_GUARD,
2080 NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
2081 NULL, sys_var::PARSE_EARLY);
2082
2083 static Sys_var_mybool Sys_log_queries_not_using_indexes(
2084 "log_queries_not_using_indexes",
2085 "Log queries that are executed without benefit of any index to the "
2086 "slow log if it is open",
2087 GLOBAL_VAR(opt_log_queries_not_using_indexes),
2088 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2089
2090 static Sys_var_mybool Sys_log_slow_admin_statements(
2091 "log_slow_admin_statements",
2092 "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to "
2093 "the slow log if it is open.",
2094 GLOBAL_VAR(opt_log_slow_admin_statements),
2095 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2096
2097 static Sys_var_mybool Sys_log_slow_slave_statements(
2098 "log_slow_slave_statements",
2099 "Log slow statements executed by slave thread to the slow log if it is open.",
2100 GLOBAL_VAR(opt_log_slow_slave_statements),
2101 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2102
update_log_throttle_queries_not_using_indexes(sys_var * self,THD * thd,enum_var_type type)2103 static bool update_log_throttle_queries_not_using_indexes(sys_var *self,
2104 THD *thd,
2105 enum_var_type type)
2106 {
2107 // Check if we should print a summary of any suppressed lines to the slow log
2108 // now since opt_log_throttle_queries_not_using_indexes was changed.
2109 log_throttle_qni.flush(thd);
2110 return false;
2111 }
2112
2113 static Sys_var_ulong Sys_log_throttle_queries_not_using_indexes(
2114 "log_throttle_queries_not_using_indexes",
2115 "Log at most this many 'not using index' warnings per minute to the "
2116 "slow log. Any further warnings will be condensed into a single "
2117 "summary line. A value of 0 disables throttling. "
2118 "Option has no effect unless --log_queries_not_using_indexes is set.",
2119 GLOBAL_VAR(opt_log_throttle_queries_not_using_indexes),
2120 CMD_LINE(REQUIRED_ARG),
2121 VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1),
2122 NO_MUTEX_GUARD, NOT_IN_BINLOG,
2123 ON_CHECK(0),
2124 ON_UPDATE(update_log_throttle_queries_not_using_indexes));
2125
update_log_warnings(sys_var * self,THD * thd,enum_var_type type)2126 static bool update_log_warnings(sys_var *self, THD *thd, enum_var_type type)
2127 {
2128 // log_warnings is deprecated, but for now, we'll set the
2129 // new log_error_verbosity from it for backward compatibility.
2130 log_error_verbosity= std::min(3UL, 1UL + log_warnings);
2131 return false;
2132 }
2133
2134 static Sys_var_ulong Sys_log_warnings(
2135 "log_warnings",
2136 "Log some not critical warnings to the log file",
2137 GLOBAL_VAR(log_warnings),
2138 CMD_LINE(OPT_ARG, 'W'),
2139 VALID_RANGE(0, 2), DEFAULT(2), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2140 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(update_log_warnings),
2141 DEPRECATED_VAR("log_error_verbosity"));
2142
update_log_error_verbosity(sys_var * self,THD * thd,enum_var_type type)2143 static bool update_log_error_verbosity(sys_var *self, THD *thd,
2144 enum_var_type type)
2145 {
2146 // log_warnings is deprecated, but for now, we'll set it from
2147 // the new log_error_verbosity for backward compatibility.
2148 log_warnings= log_error_verbosity - 1;
2149 return false;
2150 }
2151
2152 static Sys_var_ulong Sys_log_error_verbosity(
2153 "log_error_verbosity",
2154 "How detailed the error log should be. "
2155 "1, log errors only. "
2156 "2, log errors and warnings. "
2157 "3, log errors, warnings, and notes. "
2158 "Messages sent to the client are unaffected by this setting.",
2159 GLOBAL_VAR(log_error_verbosity),
2160 CMD_LINE(REQUIRED_ARG),
2161 VALID_RANGE(1, 3), DEFAULT(3), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2162 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(update_log_error_verbosity));
2163
2164 static Sys_var_enum Sys_log_timestamps(
2165 "log_timestamps",
2166 "UTC to timestamp log files in zulu time, for more concise timestamps "
2167 "and easier correlation of logs from servers from multiple time zones, "
2168 "or SYSTEM to use the system's local time. "
2169 "This affects only log files, not log tables, as the timestamp columns "
2170 "of the latter can be converted at will.",
2171 GLOBAL_VAR(opt_log_timestamps),
2172 CMD_LINE(REQUIRED_ARG),
2173 timestamp_type_names, DEFAULT(0),
2174 NO_MUTEX_GUARD, NOT_IN_BINLOG);
2175
2176 static Sys_var_mybool Sys_log_statements_unsafe_for_binlog(
2177 "log_statements_unsafe_for_binlog",
2178 "Log statements considered unsafe when using statement based binary logging.",
2179 GLOBAL_VAR(opt_log_unsafe_statements),
2180 CMD_LINE(OPT_ARG), DEFAULT(TRUE));
2181
2182 /* logging to host OS's syslog */
2183
fix_syslog(sys_var * self,THD * thd,enum_var_type type)2184 static bool fix_syslog(sys_var *self, THD *thd, enum_var_type type)
2185 {
2186 return log_syslog_update_settings();
2187 }
2188
check_syslog_tag(sys_var * self,THD * THD,set_var * var)2189 static bool check_syslog_tag(sys_var *self, THD *THD, set_var *var)
2190 {
2191 return ((var->save_result.string_value.str != NULL) &&
2192 (strchr(var->save_result.string_value.str, FN_LIBCHAR) != NULL));
2193 }
2194
2195 static Sys_var_mybool Sys_log_syslog_enable(
2196 "log_syslog",
2197 "Errors, warnings, and similar issues eligible for MySQL's error log "
2198 "file may additionally be sent to the host operating system's system "
2199 "log (\"syslog\").",
2200 GLOBAL_VAR(opt_log_syslog_enable),
2201 CMD_LINE(OPT_ARG),
2202 // preserve current defaults for both platforms:
2203 #ifndef _WIN32
2204 DEFAULT(FALSE),
2205 #else
2206 DEFAULT(TRUE),
2207 #endif
2208 NO_MUTEX_GUARD, NOT_IN_BINLOG,
2209 ON_CHECK(0), ON_UPDATE(fix_syslog));
2210
2211
2212 static Sys_var_charptr Sys_log_syslog_tag(
2213 "log_syslog_tag",
2214 "When logging issues using the host operating system's syslog, "
2215 "tag the entries from this particular MySQL server with this ident. "
2216 "This will help distinguish entries from MySQL servers co-existing "
2217 "on the same host machine. A non-empty tag will be appended to the "
2218 "default ident of 'mysqld', connected by a hyphen.",
2219 GLOBAL_VAR(opt_log_syslog_tag), CMD_LINE(REQUIRED_ARG),
2220 IN_SYSTEM_CHARSET, DEFAULT(""), NO_MUTEX_GUARD, NOT_IN_BINLOG,
2221 ON_CHECK(check_syslog_tag), ON_UPDATE(fix_syslog));
2222
2223
2224 #ifndef _WIN32
2225
check_syslog_facility(sys_var * self,THD * THD,set_var * var)2226 static bool check_syslog_facility(sys_var *self, THD *THD, set_var *var)
2227 {
2228 SYSLOG_FACILITY rsf;
2229
2230 if (var->value &&
2231 log_syslog_find_facility(var->save_result.string_value.str, &rsf))
2232 return true;
2233 return false;
2234 }
2235
fix_syslog_facility(sys_var * self,THD * thd,enum_var_type type)2236 static bool fix_syslog_facility(sys_var *self, THD *thd, enum_var_type type)
2237 {
2238 if (opt_log_syslog_facility == NULL)
2239 return true;
2240
2241 return log_syslog_update_settings();
2242 }
2243
2244 static Sys_var_charptr Sys_log_syslog_facility(
2245 "log_syslog_facility",
2246 "When logging issues using the host operating system's syslog, "
2247 "identify as a facility of the given type (to aid in log filtering).",
2248 GLOBAL_VAR(opt_log_syslog_facility), CMD_LINE(REQUIRED_ARG),
2249 IN_SYSTEM_CHARSET, DEFAULT("daemon"), NO_MUTEX_GUARD, NOT_IN_BINLOG,
2250 ON_CHECK(check_syslog_facility), ON_UPDATE(fix_syslog_facility));
2251
2252 static Sys_var_mybool Sys_log_syslog_log_pid(
2253 "log_syslog_include_pid",
2254 "When logging issues using the host operating system's syslog, "
2255 "include this MySQL server's process ID (PID). This setting does "
2256 "not affect MySQL's own error log file.",
2257 GLOBAL_VAR(opt_log_syslog_include_pid),
2258 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
2259 NO_MUTEX_GUARD, NOT_IN_BINLOG,
2260 ON_CHECK(0), ON_UPDATE(fix_syslog));
2261
2262 #endif
2263
update_cached_long_query_time(sys_var * self,THD * thd,enum_var_type type)2264 static bool update_cached_long_query_time(sys_var *self, THD *thd,
2265 enum_var_type type)
2266 {
2267 if (type == OPT_SESSION)
2268 thd->variables.long_query_time=
2269 double2ulonglong(thd->variables.long_query_time_double * 1e6);
2270 else
2271 global_system_variables.long_query_time=
2272 double2ulonglong(global_system_variables.long_query_time_double * 1e6);
2273 return false;
2274 }
2275
2276 static Sys_var_double Sys_long_query_time(
2277 "long_query_time",
2278 "Log all queries that have taken more than long_query_time seconds "
2279 "to execute to file. The argument will be treated as a decimal value "
2280 "with microsecond precision",
2281 SESSION_VAR(long_query_time_double),
2282 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(10),
2283 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2284 ON_UPDATE(update_cached_long_query_time));
2285
2286 #ifndef NDEBUG
update_cached_query_exec_time(sys_var * self,THD * thd,enum_var_type type)2287 static bool update_cached_query_exec_time(sys_var *self, THD *thd,
2288 enum_var_type type)
2289 {
2290 if (type == OPT_SESSION)
2291 thd->variables.query_exec_time=
2292 double2ulonglong(thd->variables.query_exec_time_double * 1e6);
2293 else
2294 global_system_variables.query_exec_time=
2295 double2ulonglong(global_system_variables.query_exec_time_double * 1e6);
2296 return false;
2297 }
2298
2299 static Sys_var_double Sys_query_exec_time(
2300 "query_exec_time",
2301 "Pretend queries take this many seconds. When 0 (the default) use the "
2302 "actual execution time. Used only for debugging.",
2303 SESSION_VAR(query_exec_time_double),
2304 NO_CMD_LINE, VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(0),
2305 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
2306 ON_UPDATE(update_cached_query_exec_time));
2307 #endif
2308
fix_low_prio_updates(sys_var * self,THD * thd,enum_var_type type)2309 static bool fix_low_prio_updates(sys_var *self, THD *thd, enum_var_type type)
2310 {
2311 if (type == OPT_SESSION)
2312 {
2313 thd->update_lock_default= (thd->variables.low_priority_updates ?
2314 TL_WRITE_LOW_PRIORITY : TL_WRITE);
2315 thd->insert_lock_default= (thd->variables.low_priority_updates ?
2316 TL_WRITE_LOW_PRIORITY : TL_WRITE_CONCURRENT_INSERT);
2317 }
2318 else
2319 thr_upgraded_concurrent_insert_lock=
2320 (global_system_variables.low_priority_updates ?
2321 TL_WRITE_LOW_PRIORITY : TL_WRITE);
2322 return false;
2323 }
2324 static Sys_var_mybool Sys_low_priority_updates(
2325 "low_priority_updates",
2326 "INSERT/DELETE/UPDATE has lower priority than selects",
2327 SESSION_VAR(low_priority_updates),
2328 CMD_LINE(OPT_ARG),
2329 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2330 ON_UPDATE(fix_low_prio_updates));
2331
2332 static Sys_var_mybool Sys_lower_case_file_system(
2333 "lower_case_file_system",
2334 "Case sensitivity of file names on the file system where the "
2335 "data directory is located",
2336 READ_ONLY GLOBAL_VAR(lower_case_file_system), NO_CMD_LINE,
2337 DEFAULT(FALSE));
2338
2339 static Sys_var_uint Sys_lower_case_table_names(
2340 "lower_case_table_names",
2341 "If set to 1 table names are stored in lowercase on disk and table "
2342 "names will be case-insensitive. Should be set to 2 if you are using "
2343 "a case insensitive file system",
2344 READ_ONLY GLOBAL_VAR(lower_case_table_names),
2345 CMD_LINE(OPT_ARG, OPT_LOWER_CASE_TABLE_NAMES),
2346 VALID_RANGE(0, 2),
2347 #ifdef FN_NO_CASE_SENSE
2348 DEFAULT(1),
2349 #else
2350 DEFAULT(0),
2351 #endif
2352 BLOCK_SIZE(1));
2353
session_readonly(sys_var * self,THD * thd,set_var * var)2354 static bool session_readonly(sys_var *self, THD *thd, set_var *var)
2355 {
2356 if (var->type == OPT_GLOBAL)
2357 return false;
2358 my_error(ER_VARIABLE_IS_READONLY, MYF(0), "SESSION",
2359 self->name.str, "GLOBAL");
2360 return true;
2361 }
2362
2363 static bool
check_max_allowed_packet(sys_var * self,THD * thd,set_var * var)2364 check_max_allowed_packet(sys_var *self, THD *thd, set_var *var)
2365 {
2366 longlong val;
2367 if (session_readonly(self, thd, var))
2368 return true;
2369
2370 val= var->save_result.ulonglong_value;
2371 if (val < (longlong) global_system_variables.net_buffer_length)
2372 {
2373 push_warning_printf(thd, Sql_condition::SL_WARNING,
2374 WARN_OPTION_BELOW_LIMIT, ER(WARN_OPTION_BELOW_LIMIT),
2375 "max_allowed_packet", "net_buffer_length");
2376 }
2377 return false;
2378 }
2379
2380
2381 static Sys_var_ulong Sys_max_allowed_packet(
2382 "max_allowed_packet",
2383 "Max packet length to send to or receive from the server",
2384 SESSION_VAR(max_allowed_packet), CMD_LINE(REQUIRED_ARG),
2385 VALID_RANGE(1024, 1024 * 1024 * 1024), DEFAULT(4096 * 1024),
2386 BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG,
2387 ON_CHECK(check_max_allowed_packet));
2388
2389 static Sys_var_ulong Sys_slave_max_allowed_packet(
2390 "slave_max_allowed_packet",
2391 "The maximum packet length to sent successfully from the master to slave.",
2392 GLOBAL_VAR(slave_max_allowed_packet), CMD_LINE(REQUIRED_ARG),
2393 VALID_RANGE(1024, MAX_MAX_ALLOWED_PACKET),
2394 DEFAULT(MAX_MAX_ALLOWED_PACKET),
2395 BLOCK_SIZE(1024));
2396
2397 static Sys_var_ulonglong Sys_max_binlog_cache_size(
2398 "max_binlog_cache_size",
2399 "Sets the total size of the transactional cache",
2400 GLOBAL_VAR(max_binlog_cache_size), CMD_LINE(REQUIRED_ARG),
2401 VALID_RANGE(IO_SIZE, ULLONG_MAX),
2402 DEFAULT((ULLONG_MAX/IO_SIZE)*IO_SIZE),
2403 BLOCK_SIZE(IO_SIZE),
2404 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2405 ON_UPDATE(fix_binlog_cache_size));
2406
2407 static Sys_var_ulonglong Sys_max_binlog_stmt_cache_size(
2408 "max_binlog_stmt_cache_size",
2409 "Sets the total size of the statement cache",
2410 GLOBAL_VAR(max_binlog_stmt_cache_size), CMD_LINE(REQUIRED_ARG),
2411 VALID_RANGE(IO_SIZE, ULLONG_MAX),
2412 DEFAULT((ULLONG_MAX/IO_SIZE)*IO_SIZE),
2413 BLOCK_SIZE(IO_SIZE),
2414 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2415 ON_UPDATE(fix_binlog_stmt_cache_size));
2416
fix_max_binlog_size(sys_var * self,THD * thd,enum_var_type type)2417 static bool fix_max_binlog_size(sys_var *self, THD *thd, enum_var_type type)
2418 {
2419 mysql_bin_log.set_max_size(max_binlog_size);
2420 #ifdef HAVE_REPLICATION
2421 /*
2422 For multisource replication, this max size is set to all relay logs
2423 per channel. So, run through them
2424 */
2425 if (!max_relay_log_size)
2426 {
2427 Master_info *mi =NULL;
2428
2429 channel_map.wrlock();
2430 for (mi_map::iterator it= channel_map.begin(); it!= channel_map.end(); it++)
2431 {
2432 mi= it->second;
2433 if (mi!= NULL)
2434 mi->rli->relay_log.set_max_size(max_binlog_size);
2435 }
2436 channel_map.unlock();
2437 }
2438 #endif
2439 return false;
2440 }
2441 static Sys_var_ulong Sys_max_binlog_size(
2442 "max_binlog_size",
2443 "Binary log will be rotated automatically when the size exceeds this "
2444 "value. Will also apply to relay logs if max_relay_log_size is 0",
2445 GLOBAL_VAR(max_binlog_size), CMD_LINE(REQUIRED_ARG),
2446 VALID_RANGE(IO_SIZE, 1024*1024L*1024L), DEFAULT(1024*1024L*1024L),
2447 BLOCK_SIZE(IO_SIZE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2448 ON_UPDATE(fix_max_binlog_size));
2449
2450 static Sys_var_ulong Sys_max_connections(
2451 "max_connections", "The number of simultaneous clients allowed",
2452 GLOBAL_VAR(max_connections), CMD_LINE(REQUIRED_ARG),
2453 VALID_RANGE(1, MAX_CONNECTIONS),
2454 DEFAULT(MAX_CONNECTIONS_DEFAULT),
2455 BLOCK_SIZE(1),
2456 NO_MUTEX_GUARD,
2457 NOT_IN_BINLOG,
2458 ON_CHECK(0),
2459 ON_UPDATE(0),
2460 NULL,
2461 /* max_connections is used as a sizing hint by the performance schema. */
2462 sys_var::PARSE_EARLY);
2463
2464 static Sys_var_ulong Sys_max_connect_errors(
2465 "max_connect_errors",
2466 "If there is more than this number of interrupted connections from "
2467 "a host this host will be blocked from further connections",
2468 GLOBAL_VAR(max_connect_errors), CMD_LINE(REQUIRED_ARG),
2469 VALID_RANGE(1, ULONG_MAX), DEFAULT(100),
2470 BLOCK_SIZE(1));
2471
2472 static Sys_var_uint Sys_extra_port(
2473 "extra_port",
2474 "Extra port number to use for tcp connections in a "
2475 "one-thread-per-connection manner. 0 means don't use another port",
2476 READ_ONLY GLOBAL_VAR(mysqld_extra_port), CMD_LINE(REQUIRED_ARG),
2477 VALID_RANGE(0, UINT_MAX32), DEFAULT(0), BLOCK_SIZE(1));
2478
2479 static Sys_var_ulong Sys_extra_max_connections(
2480 "extra_max_connections", "The number of connections on extra-port",
2481 GLOBAL_VAR(extra_max_connections), CMD_LINE(REQUIRED_ARG),
2482 VALID_RANGE(1, MAX_CONNECTIONS), DEFAULT(1), BLOCK_SIZE(1),
2483 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0));
2484
2485 static Sys_var_long Sys_max_digest_length(
2486 "max_digest_length",
2487 "Maximum length considered for digest text.",
2488 READ_ONLY GLOBAL_VAR(max_digest_length),
2489 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024 * 1024),
2490 DEFAULT(1024),
2491 BLOCK_SIZE(1));
2492
check_max_delayed_threads(sys_var * self,THD * thd,set_var * var)2493 static bool check_max_delayed_threads(sys_var *self, THD *thd, set_var *var)
2494 {
2495 return var->type != OPT_GLOBAL &&
2496 var->save_result.ulonglong_value != 0 &&
2497 var->save_result.ulonglong_value !=
2498 global_system_variables.max_insert_delayed_threads;
2499 }
2500
2501 // Alias for max_delayed_threads
2502 static Sys_var_ulong Sys_max_insert_delayed_threads(
2503 "max_insert_delayed_threads",
2504 "Don't start more than this number of threads to handle INSERT "
2505 "DELAYED statements. If set to zero INSERT DELAYED will be not used. "
2506 "This variable is deprecated along with INSERT DELAYED.",
2507 SESSION_VAR(max_insert_delayed_threads),
2508 NO_CMD_LINE, VALID_RANGE(0, 16384), DEFAULT(20),
2509 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG,
2510 ON_CHECK(check_max_delayed_threads), ON_UPDATE(0),
2511 DEPRECATED_VAR(""));
2512
2513 static Sys_var_ulong Sys_max_delayed_threads(
2514 "max_delayed_threads",
2515 "Don't start more than this number of threads to handle INSERT "
2516 "DELAYED statements. If set to zero INSERT DELAYED will be not used. "
2517 "This variable is deprecated along with INSERT DELAYED.",
2518 SESSION_VAR(max_insert_delayed_threads),
2519 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 16384), DEFAULT(20),
2520 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG,
2521 ON_CHECK(check_max_delayed_threads), ON_UPDATE(0),
2522 DEPRECATED_VAR(""));
2523
2524 static Sys_var_ulong Sys_max_error_count(
2525 "max_error_count",
2526 "Max number of errors/warnings to store for a statement",
2527 SESSION_VAR(max_error_count), CMD_LINE(REQUIRED_ARG),
2528 VALID_RANGE(0, 65535), DEFAULT(DEFAULT_ERROR_COUNT), BLOCK_SIZE(1));
2529
2530 static Sys_var_ulonglong Sys_max_heap_table_size(
2531 "max_heap_table_size",
2532 "Don't allow creation of heap tables bigger than this",
2533 SESSION_VAR(max_heap_table_size), CMD_LINE(REQUIRED_ARG),
2534 VALID_RANGE(16384, (ulonglong)~(intptr)0), DEFAULT(16*1024*1024),
2535 BLOCK_SIZE(1024));
2536
2537 static ulong mdl_locks_cache_size_unused;
2538 static Sys_var_ulong Sys_metadata_locks_cache_size(
2539 "metadata_locks_cache_size", "Has no effect, deprecated",
2540 READ_ONLY GLOBAL_VAR(mdl_locks_cache_size_unused),
2541 CMD_LINE(REQUIRED_ARG, OPT_MDL_CACHE_SIZE),
2542 VALID_RANGE(1, 1024*1024), DEFAULT(1024), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2543 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED_VAR(""));
2544
2545 static ulong mdl_locks_hash_partitions_unused;
2546 static Sys_var_ulong Sys_metadata_locks_hash_instances(
2547 "metadata_locks_hash_instances", "Has no effect, deprecated",
2548 READ_ONLY GLOBAL_VAR(mdl_locks_hash_partitions_unused),
2549 CMD_LINE(REQUIRED_ARG, OPT_MDL_HASH_INSTANCES),
2550 VALID_RANGE(1, 1024), DEFAULT(8), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2551 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED_VAR(""));
2552
2553 // relies on assert(sizeof(my_thread_id) == 4);
2554 static Sys_var_uint Sys_pseudo_thread_id(
2555 "pseudo_thread_id",
2556 "This variable is for internal server use",
2557 SESSION_ONLY(pseudo_thread_id),
2558 NO_CMD_LINE, VALID_RANGE(0, UINT_MAX32), DEFAULT(0),
2559 BLOCK_SIZE(1), NO_MUTEX_GUARD, IN_BINLOG,
2560 ON_CHECK(check_has_super));
2561
fix_pseudo_server_id(sys_var * self,THD * thd,enum_var_type type)2562 static bool fix_pseudo_server_id(sys_var *self, THD *thd, enum_var_type type)
2563 {
2564 thd->server_id= thd->variables.pseudo_server_id != 0 ?
2565 thd->variables.pseudo_server_id : server_id;
2566 return false;
2567 }
2568
2569 static Sys_var_ulong Sys_pseudo_server_id(
2570 "pseudo_server_id",
2571 "Override server_id for currrent session",
2572 SESSION_ONLY(pseudo_server_id),
2573 NO_CMD_LINE, VALID_RANGE(0, ULONG_MAX), DEFAULT(0),
2574 BLOCK_SIZE(1), NO_MUTEX_GUARD, IN_BINLOG,
2575 ON_CHECK(check_has_super), ON_UPDATE(fix_pseudo_server_id));
2576
fix_max_join_size(sys_var * self,THD * thd,enum_var_type type)2577 static bool fix_max_join_size(sys_var *self, THD *thd, enum_var_type type)
2578 {
2579 SV *sv= type == OPT_GLOBAL ? &global_system_variables : &thd->variables;
2580 if (sv->max_join_size == HA_POS_ERROR)
2581 sv->option_bits|= OPTION_BIG_SELECTS;
2582 else
2583 sv->option_bits&= ~OPTION_BIG_SELECTS;
2584 return false;
2585 }
2586 static Sys_var_harows Sys_max_join_size(
2587 "max_join_size",
2588 "Joins that are probably going to read more than max_join_size "
2589 "records return an error",
2590 SESSION_VAR(max_join_size), CMD_LINE(REQUIRED_ARG),
2591 VALID_RANGE(1, HA_POS_ERROR), DEFAULT(HA_POS_ERROR), BLOCK_SIZE(1),
2592 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2593 ON_UPDATE(fix_max_join_size));
2594
2595 static Sys_var_ulong Sys_max_seeks_for_key(
2596 "max_seeks_for_key",
2597 "Limit assumed max number of seeks when looking up rows based on a key",
2598 SESSION_VAR(max_seeks_for_key), CMD_LINE(REQUIRED_ARG),
2599 VALID_RANGE(1, ULONG_MAX), DEFAULT(ULONG_MAX), BLOCK_SIZE(1));
2600
2601 static Sys_var_ulong Sys_max_length_for_sort_data(
2602 "max_length_for_sort_data",
2603 "Max number of bytes in sorted records",
2604 SESSION_VAR(max_length_for_sort_data), CMD_LINE(REQUIRED_ARG),
2605 VALID_RANGE(4, 8192*1024L), DEFAULT(1024), BLOCK_SIZE(1));
2606
2607 static Sys_var_ulong Sys_max_points_in_geometry(
2608 "max_points_in_geometry",
2609 "Maximum number of points in a geometry",
2610 SESSION_VAR(max_points_in_geometry), CMD_LINE(OPT_ARG),
2611 VALID_RANGE(3, 1024*1024L), DEFAULT(64*1024), BLOCK_SIZE(1));
2612
2613 static PolyLock_mutex PLock_prepared_stmt_count(&LOCK_prepared_stmt_count);
2614
2615 static Sys_var_ulong Sys_max_prepared_stmt_count(
2616 "max_prepared_stmt_count",
2617 "Maximum number of prepared statements in the server",
2618 GLOBAL_VAR(max_prepared_stmt_count), CMD_LINE(REQUIRED_ARG),
2619 VALID_RANGE(0, 1024*1024), DEFAULT(16382), BLOCK_SIZE(1),
2620 &PLock_prepared_stmt_count, NOT_IN_BINLOG, ON_CHECK(NULL),
2621 ON_UPDATE(NULL), NULL,
2622 /* max_prepared_stmt_count is used as a sizing hint by the performance schema. */
2623 sys_var::PARSE_EARLY);
2624
fix_max_relay_log_size(sys_var * self,THD * thd,enum_var_type type)2625 static bool fix_max_relay_log_size(sys_var *self, THD *thd, enum_var_type type)
2626 {
2627 #ifdef HAVE_REPLICATION
2628 Master_info *mi= NULL;
2629
2630 channel_map.wrlock();
2631 for (mi_map::iterator it= channel_map.begin(); it!=channel_map.end(); it++)
2632 {
2633 mi= it->second;
2634
2635 if (mi != NULL)
2636 mi->rli->relay_log.set_max_size(max_relay_log_size ?
2637 max_relay_log_size: max_binlog_size);
2638 }
2639 channel_map.unlock();
2640 #endif
2641 return false;
2642 }
2643 static Sys_var_ulong Sys_max_relay_log_size(
2644 "max_relay_log_size",
2645 "If non-zero: relay log will be rotated automatically when the "
2646 "size exceeds this value; if zero: when the size "
2647 "exceeds max_binlog_size",
2648 GLOBAL_VAR(max_relay_log_size), CMD_LINE(REQUIRED_ARG),
2649 VALID_RANGE(0, 1024L*1024*1024), DEFAULT(0), BLOCK_SIZE(IO_SIZE),
2650 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2651 ON_UPDATE(fix_max_relay_log_size));
2652
2653 static Sys_var_ulong Sys_max_sort_length(
2654 "max_sort_length",
2655 "The number of bytes to use when sorting BLOB or TEXT values (only "
2656 "the first max_sort_length bytes of each value are used; the rest "
2657 "are ignored)",
2658 SESSION_VAR(max_sort_length), CMD_LINE(REQUIRED_ARG),
2659 VALID_RANGE(4, 8192*1024L), DEFAULT(1024), BLOCK_SIZE(1));
2660
2661 static Sys_var_ulong Sys_max_sp_recursion_depth(
2662 "max_sp_recursion_depth",
2663 "Maximum stored procedure recursion depth",
2664 SESSION_VAR(max_sp_recursion_depth), CMD_LINE(OPT_ARG),
2665 VALID_RANGE(0, 255), DEFAULT(0), BLOCK_SIZE(1));
2666
2667 // non-standard session_value_ptr() here
2668 static Sys_var_max_user_conn Sys_max_user_connections(
2669 "max_user_connections",
2670 "The maximum number of active connections for a single user "
2671 "(0 = no limit)",
2672 SESSION_VAR(max_user_connections), CMD_LINE(REQUIRED_ARG),
2673 VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2674 NOT_IN_BINLOG, ON_CHECK(session_readonly));
2675
2676 static Sys_var_ulong Sys_max_tmp_tables(
2677 "max_tmp_tables",
2678 "Maximum number of temporary tables a client can keep open at a time",
2679 SESSION_VAR(max_tmp_tables), CMD_LINE(REQUIRED_ARG),
2680 VALID_RANGE(1, ULONG_MAX), DEFAULT(32), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2681 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED_VAR(""));
2682
2683 static Sys_var_ulong Sys_max_write_lock_count(
2684 "max_write_lock_count",
2685 "After this many write locks, allow some read locks to run in between",
2686 GLOBAL_VAR(max_write_lock_count), CMD_LINE(REQUIRED_ARG),
2687 VALID_RANGE(1, ULONG_MAX), DEFAULT(ULONG_MAX), BLOCK_SIZE(1));
2688
2689 static Sys_var_ulong Sys_min_examined_row_limit(
2690 "min_examined_row_limit",
2691 "Don't write queries to slow log that examine fewer rows "
2692 "than that",
2693 SESSION_VAR(min_examined_row_limit), CMD_LINE(REQUIRED_ARG),
2694 VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
2695
2696 #ifdef _WIN32
2697 static Sys_var_mybool Sys_named_pipe(
2698 "named_pipe", "Enable the named pipe (NT)",
2699 READ_ONLY GLOBAL_VAR(opt_enable_named_pipe), CMD_LINE(OPT_ARG),
2700 DEFAULT(FALSE));
2701 #ifndef EMBEDDED_LIBRARY
2702
2703 static PolyLock_rwlock PLock_named_pipe_full_access_group(
2704 &LOCK_named_pipe_full_access_group);
check_named_pipe_full_access_group(sys_var * self,THD * thd,set_var * var)2705 static bool check_named_pipe_full_access_group(sys_var *self, THD *thd,
2706 set_var *var)
2707 {
2708 if (!var->value) return false; // DEFAULT is ok
2709
2710 if (!is_valid_named_pipe_full_access_group(
2711 var->save_result.string_value.str))
2712 {
2713 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), self->name.str,
2714 var->save_result.string_value.str);
2715 return true;
2716 }
2717 return false;
2718 }
fix_named_pipe_full_access_group(sys_var *,THD *,enum_var_type)2719 static bool fix_named_pipe_full_access_group(sys_var *, THD *, enum_var_type) {
2720 return update_named_pipe_full_access_group(named_pipe_full_access_group);
2721 }
2722 static Sys_var_charptr Sys_named_pipe_full_access_group(
2723 "named_pipe_full_access_group",
2724 "Name of Windows group granted full access to the named pipe",
2725 GLOBAL_VAR(named_pipe_full_access_group),
2726 CMD_LINE(REQUIRED_ARG, OPT_NAMED_PIPE_FULL_ACCESS_GROUP), IN_FS_CHARSET,
2727 DEFAULT(DEFAULT_NAMED_PIPE_FULL_ACCESS_GROUP),
2728 &PLock_named_pipe_full_access_group, NOT_IN_BINLOG,
2729 ON_CHECK(check_named_pipe_full_access_group),
2730 ON_UPDATE(fix_named_pipe_full_access_group));
2731
2732 #endif /* EMBEDDED_LIBRARY */
2733 #endif /* _WIN32 */
2734
2735
2736 static bool
check_net_buffer_length(sys_var * self,THD * thd,set_var * var)2737 check_net_buffer_length(sys_var *self, THD *thd, set_var *var)
2738 {
2739 longlong val;
2740 if (session_readonly(self, thd, var))
2741 return true;
2742
2743 val= var->save_result.ulonglong_value;
2744 if (val > (longlong) global_system_variables.max_allowed_packet)
2745 {
2746 push_warning_printf(thd, Sql_condition::SL_WARNING,
2747 WARN_OPTION_BELOW_LIMIT, ER(WARN_OPTION_BELOW_LIMIT),
2748 "max_allowed_packet", "net_buffer_length");
2749 }
2750 return false;
2751 }
2752 static Sys_var_ulong Sys_net_buffer_length(
2753 "net_buffer_length",
2754 "Buffer length for TCP/IP and socket communication",
2755 SESSION_VAR(net_buffer_length), CMD_LINE(REQUIRED_ARG),
2756 VALID_RANGE(1024, 1024*1024), DEFAULT(16384), BLOCK_SIZE(1024),
2757 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_net_buffer_length));
2758
fix_net_read_timeout(sys_var * self,THD * thd,enum_var_type type)2759 static bool fix_net_read_timeout(sys_var *self, THD *thd, enum_var_type type)
2760 {
2761 if (type != OPT_GLOBAL)
2762 {
2763 // net_buffer_length is a specific property for the classic protocols
2764 if (!thd->is_classic_protocol())
2765 {
2766 my_error(ER_PLUGGABLE_PROTOCOL_COMMAND_NOT_SUPPORTED, MYF(0));
2767 return true;
2768 }
2769 my_net_set_read_timeout(thd->get_protocol_classic()->get_net(),
2770 thd->variables.net_read_timeout);
2771 }
2772 return false;
2773 }
2774 static Sys_var_ulong Sys_net_read_timeout(
2775 "net_read_timeout",
2776 "Number of seconds to wait for more data from a connection before "
2777 "aborting the read",
2778 SESSION_VAR(net_read_timeout), CMD_LINE(REQUIRED_ARG),
2779 VALID_RANGE(1, INT_MAX32/1000), DEFAULT(NET_READ_TIMEOUT), BLOCK_SIZE(1),
2780 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2781 ON_UPDATE(fix_net_read_timeout));
2782
fix_net_write_timeout(sys_var * self,THD * thd,enum_var_type type)2783 static bool fix_net_write_timeout(sys_var *self, THD *thd, enum_var_type type)
2784 {
2785 if (type != OPT_GLOBAL)
2786 {
2787 // net_read_timeout is a specific property for the classic protocols
2788 if (!thd->is_classic_protocol())
2789 {
2790 my_error(ER_PLUGGABLE_PROTOCOL_COMMAND_NOT_SUPPORTED, MYF(0));
2791 return true;
2792 }
2793 my_net_set_write_timeout(thd->get_protocol_classic()->get_net(),
2794 thd->variables.net_write_timeout);
2795 }
2796 return false;
2797 }
2798 static Sys_var_ulong Sys_net_write_timeout(
2799 "net_write_timeout",
2800 "Number of seconds to wait for a block to be written to a connection "
2801 "before aborting the write",
2802 SESSION_VAR(net_write_timeout), CMD_LINE(REQUIRED_ARG),
2803 VALID_RANGE(1, INT_MAX32/1000), DEFAULT(NET_WRITE_TIMEOUT), BLOCK_SIZE(1),
2804 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2805 ON_UPDATE(fix_net_write_timeout));
2806
2807 // Sync kill_idle_transaction and innodb_kill_idle_transaction values
2808 extern long srv_kill_idle_transaction;
2809
fix_kill_idle_transaction(sys_var * self,THD * thd,enum_var_type type)2810 static bool fix_kill_idle_transaction(sys_var *self, THD *thd,
2811 enum_var_type type)
2812 {
2813 srv_kill_idle_transaction= kill_idle_transaction_timeout;
2814 return false;
2815 }
2816
2817 static Sys_var_ulong Sys_kill_idle_transaction(
2818 "kill_idle_transaction",
2819 "If non-zero, number of seconds to wait before killing idle "
2820 "connections that have open transactions",
2821 GLOBAL_VAR(kill_idle_transaction_timeout), CMD_LINE(REQUIRED_ARG),
2822 VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(0), BLOCK_SIZE(1),
2823 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2824 ON_UPDATE(fix_kill_idle_transaction));
2825
fix_net_retry_count(sys_var * self,THD * thd,enum_var_type type)2826 static bool fix_net_retry_count(sys_var *self, THD *thd, enum_var_type type)
2827 {
2828 if (type != OPT_GLOBAL)
2829 {
2830 // net_write_timeout is a specific property for the classic protocols
2831 if (!thd->is_classic_protocol())
2832 {
2833 my_error(ER_PLUGGABLE_PROTOCOL_COMMAND_NOT_SUPPORTED, MYF(0));
2834 return true;
2835 }
2836 thd->get_protocol_classic()->get_net()->retry_count=
2837 thd->variables.net_retry_count;
2838 }
2839 return false;
2840 }
2841 static Sys_var_ulong Sys_net_retry_count(
2842 "net_retry_count",
2843 "If a read on a communication port is interrupted, retry this "
2844 "many times before giving up",
2845 SESSION_VAR(net_retry_count), CMD_LINE(REQUIRED_ARG),
2846 VALID_RANGE(1, ULONG_MAX), DEFAULT(MYSQLD_NET_RETRY_COUNT),
2847 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2848 ON_UPDATE(fix_net_retry_count));
2849
2850 static Sys_var_mybool Sys_new_mode(
2851 "new", "Use very new possible \"unsafe\" functions",
2852 SESSION_VAR(new_mode), CMD_LINE(OPT_ARG, 'n'), DEFAULT(FALSE));
2853
2854 static Sys_var_mybool Sys_old_mode(
2855 "old", "Use compatible behavior",
2856 READ_ONLY GLOBAL_VAR(old_mode), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2857
2858 #ifndef EMBEDDED_LIBRARY
2859 static Sys_var_mybool Sys_show_compatibility_56(
2860 "show_compatibility_56",
2861 "SHOW commands / INFORMATION_SCHEMA tables compatible with MySQL 5.6",
2862 GLOBAL_VAR(show_compatibility_56), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2863 #endif /* EMBEDDED_LIBRARY */
2864
2865 static Sys_var_mybool Sys_old_alter_table(
2866 "old_alter_table", "Use old, non-optimized alter table",
2867 SESSION_VAR(old_alter_table), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2868
old_passwords_check(sys_var * self MY_ATTRIBUTE ((unused)),THD * thd MY_ATTRIBUTE ((unused)),set_var * var)2869 static bool old_passwords_check(sys_var *self MY_ATTRIBUTE((unused)),
2870 THD *thd MY_ATTRIBUTE((unused)),
2871 set_var *var)
2872 {
2873 push_deprecated_warn_no_replacement(current_thd, "old_passwords");
2874 /* 1 used to be old passwords */
2875 return var->save_result.ulonglong_value == 1;
2876 }
2877
2878 static Sys_var_uint Sys_old_passwords(
2879 "old_passwords",
2880 "Determine which hash algorithm to use when generating passwords using "
2881 "the PASSWORD() function",
2882 SESSION_VAR(old_passwords), CMD_LINE(REQUIRED_ARG),
2883 VALID_RANGE(0, 2), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2884 NOT_IN_BINLOG, ON_CHECK(old_passwords_check));
2885
2886 static Sys_var_ulong Sys_open_files_limit(
2887 "open_files_limit",
2888 "If this is not 0, then mysqld will use this value to reserve file "
2889 "descriptors to use with setrlimit(). If this value is 0 then mysqld "
2890 "will reserve max_connections*5 or max_connections + table_open_cache*2 "
2891 "(whichever is larger) number of file descriptors",
2892 READ_ONLY GLOBAL_VAR(open_files_limit), CMD_LINE(REQUIRED_ARG),
2893 VALID_RANGE(0, OS_FILE_LIMIT), DEFAULT(0), BLOCK_SIZE(1),
2894 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
2895 NULL,
2896 /* open_files_limit is used as a sizing hint by the performance schema. */
2897 sys_var::PARSE_EARLY);
2898
2899 /// @todo change to enum
2900 static Sys_var_ulong Sys_optimizer_prune_level(
2901 "optimizer_prune_level",
2902 "Controls the heuristic(s) applied during query optimization to prune "
2903 "less-promising partial plans from the optimizer search space. "
2904 "Meaning: 0 - do not apply any heuristic, thus perform exhaustive "
2905 "search; 1 - prune plans based on number of retrieved rows",
2906 SESSION_VAR(optimizer_prune_level), CMD_LINE(REQUIRED_ARG),
2907 VALID_RANGE(0, 1), DEFAULT(1), BLOCK_SIZE(1));
2908
2909 static Sys_var_ulong Sys_optimizer_search_depth(
2910 "optimizer_search_depth",
2911 "Maximum depth of search performed by the query optimizer. Values "
2912 "larger than the number of relations in a query result in better "
2913 "query plans, but take longer to compile a query. Values smaller "
2914 "than the number of tables in a relation result in faster "
2915 "optimization, but may produce very bad query plans. If set to 0, "
2916 "the system will automatically pick a reasonable value",
2917 SESSION_VAR(optimizer_search_depth), CMD_LINE(REQUIRED_ARG),
2918 VALID_RANGE(0, MAX_TABLES+1), DEFAULT(MAX_TABLES+1), BLOCK_SIZE(1));
2919
2920 static Sys_var_ulong Sys_range_optimizer_max_mem_size(
2921 "range_optimizer_max_mem_size",
2922 "Maximum amount of memory used by the range optimizer "
2923 "to allocate predicates during range analysis. "
2924 "The larger the number, more memory may be consumed during "
2925 "range analysis. If the value is too low to completed range "
2926 "optimization of a query, index range scan will not be "
2927 "considered for this query. A value of 0 means range optimizer "
2928 "does not have any cap on memory. ",
2929 SESSION_VAR(range_optimizer_max_mem_size),
2930 CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, ULONG_MAX),
2931 DEFAULT(8388608),
2932 BLOCK_SIZE(1));
2933
2934 static bool
limit_parser_max_mem_size(sys_var * self,THD * thd,set_var * var)2935 limit_parser_max_mem_size(sys_var *self, THD *thd, set_var *var)
2936 {
2937 if (var->type == OPT_GLOBAL)
2938 return false;
2939 ulonglong val= var->save_result.ulonglong_value;
2940 if (val > global_system_variables.parser_max_mem_size)
2941 {
2942 if (thd->security_context()->check_access(SUPER_ACL))
2943 return false;
2944 var->save_result.ulonglong_value=
2945 global_system_variables.parser_max_mem_size;
2946 return throw_bounds_warning(thd, "parser_max_mem_size",
2947 true, // fixed
2948 true, // is_unsigned
2949 val);
2950 }
2951 return false;
2952 }
2953
2954 // Similar to what we do for the intptr typedef.
2955 #if SIZEOF_CHARP == SIZEOF_INT
2956 static unsigned int max_mem_sz = ~0;
2957 #elif SIZEOF_CHARP == SIZEOF_LONG
2958 static unsigned long max_mem_sz = ~0;
2959 #elif SIZEOF_CHARP == SIZEOF_LONG_LONG
2960 static unsigned long long max_mem_sz = ~0;
2961 #endif
2962
2963 /*
2964 Need at least 400Kb to get through bootstrap.
2965 Need at least 8Mb to get through mtr check testcase, which does
2966 SELECT * FROM INFORMATION_SCHEMA.VIEWS
2967 */
2968 static Sys_var_ulonglong Sys_parser_max_mem_size(
2969 "parser_max_mem_size",
2970 "Maximum amount of memory available to the parser",
2971 SESSION_VAR(parser_max_mem_size),
2972 CMD_LINE(REQUIRED_ARG),
2973 VALID_RANGE(10 * 1000 * 1000, max_mem_sz),
2974 DEFAULT(max_mem_sz),
2975 BLOCK_SIZE(1),
2976 NO_MUTEX_GUARD, NOT_IN_BINLOG,
2977 ON_CHECK(limit_parser_max_mem_size),
2978 ON_UPDATE(NULL));
2979
2980 /*
2981 There is no call on Sys_var_integer::do_check() for 'set xxx=default';
2982 The predefined default for parser_max_mem_size is "infinite".
2983 Update it in case we have seen option maximum-parser-max-mem-size
2984 Also update global_system_variables, so 'SELECT parser_max_mem_size'
2985 reports correct data.
2986 */
update_parser_max_mem_size()2987 export void update_parser_max_mem_size()
2988 {
2989 /*
2990 As "max_system_variables" table is no longer used because of the
2991 custom Percona Server "Expanded Program Option Modifiers",
2992 we need to get the value of the specified "--maximum-parser-max-mem-size"
2993 option via "getopt_constraint_get_max_value()" call.
2994 */
2995 const void* max_max_ptr =
2996 getopt_constraint_get_max_value("parser_max_mem_size", 0, FALSE);
2997 if (max_max_ptr == 0)
2998 return;
2999 const ulonglong max_max= *(const ulonglong*)max_max_ptr;
3000 if (max_max == max_mem_sz)
3001 return;
3002 // In case parser-max-mem-size is also set:
3003 const ulonglong new_val=
3004 std::min(max_max, global_system_variables.parser_max_mem_size);
3005 Sys_parser_max_mem_size.update_default(new_val);
3006 global_system_variables.parser_max_mem_size= new_val;
3007 }
3008
3009 static const char *optimizer_switch_names[]=
3010 {
3011 "index_merge", "index_merge_union", "index_merge_sort_union",
3012 "index_merge_intersection", "engine_condition_pushdown",
3013 "index_condition_pushdown" , "mrr", "mrr_cost_based",
3014 "block_nested_loop", "batched_key_access",
3015 "materialization", "semijoin", "loosescan", "firstmatch", "duplicateweedout",
3016 "subquery_materialization_cost_based",
3017 "use_index_extensions", "condition_fanout_filter", "derived_merge",
3018 "prefer_ordering_index", "favor_range_scan", "default", NullS
3019 };
3020 static Sys_var_flagset Sys_optimizer_switch(
3021 "optimizer_switch",
3022 "optimizer_switch=option=val[,option=val...], where option is one of "
3023 "{index_merge, index_merge_union, index_merge_sort_union, "
3024 "index_merge_intersection, engine_condition_pushdown, "
3025 "index_condition_pushdown, mrr, mrr_cost_based"
3026 ", materialization, semijoin, loosescan, firstmatch, duplicateweedout,"
3027 " subquery_materialization_cost_based"
3028 ", block_nested_loop, batched_key_access, use_index_extensions,"
3029 " condition_fanout_filter, derived_merge, prefer_ordering_index,"
3030 " favor_range_scan} and val is one of {on, off, default}",
3031 SESSION_VAR(optimizer_switch), CMD_LINE(REQUIRED_ARG),
3032 optimizer_switch_names, DEFAULT(OPTIMIZER_SWITCH_DEFAULT),
3033 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL));
3034
3035 static Sys_var_mybool Sys_var_end_markers_in_json(
3036 "end_markers_in_json",
3037 "In JSON output (\"EXPLAIN FORMAT=JSON\" and optimizer trace), "
3038 "if variable is set to 1, repeats the structure's key (if it has one) "
3039 "near the closing bracket",
3040 SESSION_VAR(end_markers_in_json), CMD_LINE(OPT_ARG),
3041 DEFAULT(FALSE));
3042
3043 #ifdef OPTIMIZER_TRACE
3044
3045 static Sys_var_flagset Sys_optimizer_trace(
3046 "optimizer_trace",
3047 "Controls tracing of the Optimizer:"
3048 " optimizer_trace=option=val[,option=val...], where option is one of"
3049 " {enabled, one_line}"
3050 " and val is one of {on, default}",
3051 SESSION_VAR(optimizer_trace), CMD_LINE(REQUIRED_ARG),
3052 Opt_trace_context::flag_names,
3053 DEFAULT(Opt_trace_context::FLAG_DEFAULT));
3054 // @see set_var::is_var_optimizer_trace()
3055 export sys_var *Sys_optimizer_trace_ptr= &Sys_optimizer_trace;
3056
3057 /**
3058 Note how "misc" is not here: it is not accessible to the user; disabling
3059 "misc" would disable the top object, which would make an empty trace.
3060 */
3061 static Sys_var_flagset Sys_optimizer_trace_features(
3062 "optimizer_trace_features",
3063 "Enables/disables tracing of selected features of the Optimizer:"
3064 " optimizer_trace_features=option=val[,option=val...], where option is one of"
3065 " {greedy_search, range_optimizer, dynamic_range, repeated_subselect}"
3066 " and val is one of {on, off, default}",
3067 SESSION_VAR(optimizer_trace_features), CMD_LINE(REQUIRED_ARG),
3068 Opt_trace_context::feature_names,
3069 DEFAULT(Opt_trace_context::default_features));
3070
3071 /** Delete all old optimizer traces */
optimizer_trace_update(sys_var * self,THD * thd,enum_var_type type)3072 static bool optimizer_trace_update(sys_var *self, THD *thd,
3073 enum_var_type type)
3074 {
3075 thd->opt_trace.reset();
3076 return false;
3077 }
3078
3079 static Sys_var_long Sys_optimizer_trace_offset(
3080 "optimizer_trace_offset",
3081 "Offset of first optimizer trace to show; see manual",
3082 SESSION_VAR(optimizer_trace_offset), CMD_LINE(REQUIRED_ARG),
3083 VALID_RANGE(LONG_MIN, LONG_MAX), DEFAULT(-1), BLOCK_SIZE(1),
3084 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
3085 ON_UPDATE(optimizer_trace_update));
3086
3087 static Sys_var_long Sys_optimizer_trace_limit(
3088 "optimizer_trace_limit",
3089 "Maximum number of shown optimizer traces",
3090 SESSION_VAR(optimizer_trace_limit), CMD_LINE(REQUIRED_ARG),
3091 VALID_RANGE(0, LONG_MAX), DEFAULT(1), BLOCK_SIZE(1),
3092 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
3093 ON_UPDATE(optimizer_trace_update));
3094
3095 static Sys_var_ulong Sys_optimizer_trace_max_mem_size(
3096 "optimizer_trace_max_mem_size",
3097 "Maximum allowed cumulated size of stored optimizer traces",
3098 SESSION_VAR(optimizer_trace_max_mem_size), CMD_LINE(REQUIRED_ARG),
3099 VALID_RANGE(0, ULONG_MAX), DEFAULT(1024*16), BLOCK_SIZE(1));
3100
3101 #endif
3102
3103 static Sys_var_charptr Sys_pid_file(
3104 "pid_file", "Pid file used by safe_mysqld",
3105 READ_ONLY GLOBAL_VAR(pidfile_name_ptr), CMD_LINE(REQUIRED_ARG),
3106 IN_FS_CHARSET, DEFAULT(0));
3107
3108 static Sys_var_charptr Sys_plugin_dir(
3109 "plugin_dir", "Directory for plugins",
3110 READ_ONLY GLOBAL_VAR(opt_plugin_dir_ptr), CMD_LINE(REQUIRED_ARG),
3111 IN_FS_CHARSET, DEFAULT(0));
3112
3113 static Sys_var_uint Sys_port(
3114 "port",
3115 "Port number to use for connection or 0 to default to, "
3116 "my.cnf, $MYSQL_TCP_PORT, "
3117 #if MYSQL_PORT_DEFAULT == 0
3118 "/etc/services, "
3119 #endif
3120 "built-in default (" STRINGIFY_ARG(MYSQL_PORT) "), whatever comes first",
3121 READ_ONLY GLOBAL_VAR(mysqld_port), CMD_LINE(REQUIRED_ARG, 'P'),
3122 VALID_RANGE(0, 65535), DEFAULT(0), BLOCK_SIZE(1));
3123
3124 static Sys_var_ulong Sys_preload_buff_size(
3125 "preload_buffer_size",
3126 "The size of the buffer that is allocated when preloading indexes",
3127 SESSION_VAR(preload_buff_size), CMD_LINE(REQUIRED_ARG),
3128 VALID_RANGE(1024, 1024*1024*1024), DEFAULT(32768), BLOCK_SIZE(1));
3129
3130 static Sys_var_uint Sys_protocol_version(
3131 "protocol_version",
3132 "The version of the client/server protocol used by the MySQL server",
3133 READ_ONLY GLOBAL_VAR(protocol_version), NO_CMD_LINE,
3134 VALID_RANGE(0, ~0), DEFAULT(PROTOCOL_VERSION), BLOCK_SIZE(1));
3135
3136 static Sys_var_proxy_user Sys_proxy_user(
3137 "proxy_user", "The proxy user account name used when logging in",
3138 IN_SYSTEM_CHARSET);
3139
3140 static Sys_var_external_user Sys_external_user(
3141 "external_user", "The external user account used when logging in",
3142 IN_SYSTEM_CHARSET);
3143
3144 static Sys_var_ulong Sys_read_buff_size(
3145 "read_buffer_size",
3146 "Each thread that does a sequential scan allocates a buffer of "
3147 "this size for each table it scans. If you do many sequential scans, "
3148 "you may want to increase this value",
3149 SESSION_VAR(read_buff_size), CMD_LINE(REQUIRED_ARG),
3150 VALID_RANGE(IO_SIZE*2, INT_MAX32), DEFAULT(128*1024),
3151 BLOCK_SIZE(IO_SIZE));
3152
check_read_only(sys_var * self,THD * thd,set_var * var)3153 static bool check_read_only(sys_var *self, THD *thd, set_var *var)
3154 {
3155 /* Prevent self dead-lock */
3156 if (thd->locked_tables_mode || thd->in_active_multi_stmt_transaction())
3157 {
3158 my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3159 return true;
3160 }
3161 return false;
3162 }
3163
3164 #if !defined(EMBEDDED_LIBRARY)
3165
check_require_secure_transport(sys_var * self,THD * thd,set_var * var)3166 static bool check_require_secure_transport(sys_var *self, THD *thd, set_var *var)
3167 {
3168
3169 #if !defined (_WIN32)
3170 /*
3171 always allow require_secure_transport to be enabled on
3172 Linux, as socket is secure.
3173 */
3174 return false;
3175 #else
3176 /*
3177 check whether SSL or shared memory transports are enabled before
3178 turning require_secure_transport ON, otherwise no connections will
3179 be allowed on Windows.
3180 */
3181
3182 if (!var->save_result.ulonglong_value)
3183 return false;
3184 if ((have_ssl == SHOW_OPTION_YES) || opt_enable_shared_memory)
3185 return false;
3186 /* reject if SSL and shared memory are both disabled: */
3187 my_error(ER_NO_SECURE_TRANSPORTS_CONFIGURED, MYF(0));
3188 return true;
3189
3190 #endif
3191 }
3192
3193 #endif
3194
fix_read_only(sys_var * self,THD * thd,enum_var_type type)3195 static bool fix_read_only(sys_var *self, THD *thd, enum_var_type type)
3196 {
3197 bool result= true;
3198 my_bool new_read_only= read_only; // make a copy before releasing a mutex
3199 DBUG_ENTER("sys_var_opt_readonly::update");
3200
3201 if (read_only == FALSE || read_only == opt_readonly)
3202 {
3203 if (opt_super_readonly && !read_only)
3204 {
3205 opt_super_readonly= FALSE;
3206 super_read_only= FALSE;
3207 }
3208 opt_readonly= read_only;
3209 DBUG_RETURN(false);
3210 }
3211
3212 if (check_read_only(self, thd, 0)) // just in case
3213 goto end;
3214
3215 if (thd->global_read_lock.is_acquired())
3216 {
3217 /*
3218 This connection already holds the global read lock.
3219 This can be the case with:
3220 - FLUSH TABLES WITH READ LOCK
3221 - SET GLOBAL READ_ONLY = 1
3222 */
3223 if (opt_super_readonly && !read_only)
3224 {
3225 opt_super_readonly= FALSE;
3226 super_read_only= FALSE;
3227 }
3228 opt_readonly= read_only;
3229 DBUG_RETURN(false);
3230 }
3231
3232 /*
3233 READ_ONLY=1 prevents write locks from being taken on tables and
3234 blocks transactions from committing. We therefore should make sure
3235 that no such events occur while setting the read_only variable.
3236 This is a 2 step process:
3237 [1] lock_global_read_lock()
3238 Prevents connections from obtaining new write locks on
3239 tables. Note that we can still have active rw transactions.
3240 [2] make_global_read_lock_block_commit()
3241 Prevents transactions from committing.
3242 */
3243
3244 read_only= opt_readonly;
3245 mysql_mutex_unlock(&LOCK_global_system_variables);
3246
3247 if (thd->global_read_lock.lock_global_read_lock(thd))
3248 goto end_with_mutex_unlock;
3249
3250 if ((result= thd->global_read_lock.make_global_read_lock_block_commit(thd)))
3251 goto end_with_read_lock;
3252
3253 /* Change the opt_readonly system variable, safe because the lock is held */
3254 opt_readonly= new_read_only;
3255
3256 result= false;
3257
3258 end_with_read_lock:
3259 /* Release the lock */
3260 thd->global_read_lock.unlock_global_read_lock(thd);
3261 end_with_mutex_unlock:
3262 mysql_mutex_lock(&LOCK_global_system_variables);
3263 end:
3264 read_only= opt_readonly;
3265 DBUG_RETURN(result);
3266 }
3267
fix_super_read_only(sys_var * self,THD * thd,enum_var_type type)3268 static bool fix_super_read_only(sys_var *self, THD *thd, enum_var_type type)
3269 {
3270 DBUG_ENTER("sys_var_opt_super_readonly::update");
3271
3272 /* return if no changes: */
3273 if (super_read_only == opt_super_readonly)
3274 DBUG_RETURN(false);
3275
3276 /* return immediately if turning super_read_only OFF: */
3277 if (super_read_only == FALSE)
3278 {
3279 opt_super_readonly= FALSE;
3280 DBUG_RETURN(false);
3281 }
3282 bool result= true;
3283 my_bool new_super_read_only = super_read_only; /* make a copy before releasing a mutex */
3284
3285 /* set read_only to ON if it is OFF, letting fix_read_only()
3286 handle its own locking needs
3287 */
3288 if (!opt_readonly)
3289 {
3290 read_only= TRUE;
3291 if ((result = fix_read_only(NULL, thd, type)))
3292 goto end;
3293 }
3294
3295 /* if we already have global read lock, set super_read_only
3296 and return immediately:
3297 */
3298 if (thd->global_read_lock.is_acquired())
3299 {
3300 opt_super_readonly= super_read_only;
3301 DBUG_RETURN(false);
3302 }
3303
3304 /* now we're turning ON super_read_only: */
3305 super_read_only = opt_super_readonly;
3306 mysql_mutex_unlock(&LOCK_global_system_variables);
3307
3308 if (thd->global_read_lock.lock_global_read_lock(thd))
3309 goto end_with_mutex_unlock;
3310
3311 if ((result = thd->global_read_lock.make_global_read_lock_block_commit(thd)))
3312 goto end_with_read_lock;
3313 opt_super_readonly= new_super_read_only;
3314 result= false;
3315
3316 end_with_read_lock:
3317 /* Release the lock */
3318 thd->global_read_lock.unlock_global_read_lock(thd);
3319 end_with_mutex_unlock:
3320 mysql_mutex_lock(&LOCK_global_system_variables);
3321 end:
3322 super_read_only= opt_super_readonly;
3323 DBUG_RETURN(result);
3324 }
3325
3326 #if !defined(EMBEDDED_LIBRARY)
3327
3328 static Sys_var_mybool Sys_require_secure_transport(
3329 "require_secure_transport",
3330 "When this option is enabled, connections attempted using insecure "
3331 "transport will be rejected. Secure transports are SSL/TLS, "
3332 "Unix socket or Shared Memory (on Windows).",
3333 GLOBAL_VAR(opt_require_secure_transport),
3334 CMD_LINE(OPT_ARG),
3335 DEFAULT(FALSE),
3336 NO_MUTEX_GUARD, NOT_IN_BINLOG,
3337 ON_CHECK(check_require_secure_transport), ON_UPDATE(0));
3338
3339 #endif
3340
3341 /**
3342 The read_only boolean is always equal to the opt_readonly boolean except
3343 during fix_read_only(); when that function is entered, opt_readonly is
3344 the pre-update value and read_only is the post-update value.
3345 fix_read_only() compares them and runs needed operations for the
3346 transition (especially when transitioning from false to true) and
3347 synchronizes both booleans in the end.
3348 */
3349 static Sys_var_mybool Sys_readonly(
3350 "read_only",
3351 "Make all non-temporary tables read-only, with the exception for "
3352 "replication (slave) threads and users with the SUPER privilege",
3353 GLOBAL_VAR(read_only), CMD_LINE(OPT_ARG), DEFAULT(FALSE),
3354 NO_MUTEX_GUARD, NOT_IN_BINLOG,
3355 ON_CHECK(check_read_only), ON_UPDATE(fix_read_only));
3356
3357 static Sys_var_mybool Sys_userstat(
3358 "userstat",
3359 "Control USER_STATISTICS, CLIENT_STATISTICS, THREAD_STATISTICS, "
3360 "INDEX_STATISTICS and TABLE_STATISTICS running",
3361 GLOBAL_VAR(opt_userstat), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
3362
3363 static Sys_var_mybool Sys_thread_statistics(
3364 "thread_statistics",
3365 "Control TABLE_STATISTICS running, when userstat is enabled",
3366 GLOBAL_VAR(opt_thread_statistics), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
3367
3368 /**
3369 Setting super_read_only to ON triggers read_only to also be set to ON.
3370 */
3371 static Sys_var_mybool Sys_super_readonly(
3372 "super_read_only",
3373 "Make all non-temporary tables read-only, with the exception for "
3374 "replication (slave) threads. Users with the SUPER privilege are "
3375 "affected, unlike read_only. Setting super_read_only to ON "
3376 "also sets read_only to ON.",
3377 GLOBAL_VAR(super_read_only), CMD_LINE(OPT_ARG), DEFAULT(FALSE),
3378 NO_MUTEX_GUARD, NOT_IN_BINLOG,
3379 ON_CHECK(0), ON_UPDATE(fix_super_read_only));
3380
3381
3382
3383 // Small lower limit to be able to test MRR
3384 static Sys_var_ulong Sys_read_rnd_buff_size(
3385 "read_rnd_buffer_size",
3386 "When reading rows in sorted order after a sort, the rows are read "
3387 "through this buffer to avoid a disk seeks",
3388 SESSION_VAR(read_rnd_buff_size), CMD_LINE(REQUIRED_ARG),
3389 VALID_RANGE(1, INT_MAX32), DEFAULT(256*1024), BLOCK_SIZE(1));
3390
3391 static Sys_var_ulong Sys_div_precincrement(
3392 "div_precision_increment", "Precision of the result of '/' "
3393 "operator will be increased on that value",
3394 SESSION_VAR(div_precincrement), CMD_LINE(REQUIRED_ARG),
3395 VALID_RANGE(0, DECIMAL_MAX_SCALE), DEFAULT(4), BLOCK_SIZE(1));
3396
3397 static Sys_var_uint Sys_eq_range_index_dive_limit(
3398 "eq_range_index_dive_limit",
3399 "The optimizer will use existing index statistics instead of "
3400 "doing index dives for equality ranges if the number of equality "
3401 "ranges for the index is larger than or equal to this number. "
3402 "If set to 0, index dives are always used.",
3403 SESSION_VAR(eq_range_index_dive_limit), CMD_LINE(REQUIRED_ARG),
3404 VALID_RANGE(0, UINT_MAX32), DEFAULT(200), BLOCK_SIZE(1));
3405
3406 static Sys_var_ulong Sys_range_alloc_block_size(
3407 "range_alloc_block_size",
3408 "Allocation block size for storing ranges during optimization",
3409 SESSION_VAR(range_alloc_block_size), CMD_LINE(REQUIRED_ARG),
3410 VALID_RANGE(RANGE_ALLOC_BLOCK_SIZE, UINT32_MAX),
3411 DEFAULT(RANGE_ALLOC_BLOCK_SIZE), BLOCK_SIZE(1024));
3412
3413 static Sys_var_ulong Sys_multi_range_count(
3414 "multi_range_count",
3415 "Number of key ranges to request at once. "
3416 "This variable has no effect, and is deprecated. "
3417 "It will be removed in a future release.",
3418 SESSION_VAR(multi_range_count), CMD_LINE(REQUIRED_ARG),
3419 VALID_RANGE(1, ULONG_MAX), DEFAULT(256), BLOCK_SIZE(1),
3420 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
3421 DEPRECATED_VAR(""));
3422
fix_thd_mem_root(sys_var * self,THD * thd,enum_var_type type)3423 static bool fix_thd_mem_root(sys_var *self, THD *thd, enum_var_type type)
3424 {
3425 if (type != OPT_GLOBAL)
3426 reset_root_defaults(thd->mem_root,
3427 thd->variables.query_alloc_block_size,
3428 thd->variables.query_prealloc_size);
3429 return false;
3430 }
3431 static Sys_var_ulong Sys_query_alloc_block_size(
3432 "query_alloc_block_size",
3433 "Allocation block size for query parsing and execution",
3434 SESSION_VAR(query_alloc_block_size), CMD_LINE(REQUIRED_ARG),
3435 VALID_RANGE(1024, UINT_MAX32), DEFAULT(QUERY_ALLOC_BLOCK_SIZE),
3436 BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3437 ON_UPDATE(fix_thd_mem_root));
3438
3439 static Sys_var_ulong Sys_query_prealloc_size(
3440 "query_prealloc_size",
3441 "Persistent buffer for query parsing and execution",
3442 SESSION_VAR(query_prealloc_size), CMD_LINE(REQUIRED_ARG),
3443 VALID_RANGE(QUERY_ALLOC_PREALLOC_SIZE, ULONG_MAX),
3444 DEFAULT(QUERY_ALLOC_PREALLOC_SIZE),
3445 BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3446 ON_UPDATE(fix_thd_mem_root));
3447
3448 #if defined (_WIN32) && !defined (EMBEDDED_LIBRARY)
3449 static Sys_var_mybool Sys_shared_memory(
3450 "shared_memory", "Enable the shared memory",
3451 READ_ONLY GLOBAL_VAR(opt_enable_shared_memory), CMD_LINE(OPT_ARG),
3452 DEFAULT(FALSE));
3453
3454 static Sys_var_charptr Sys_shared_memory_base_name(
3455 "shared_memory_base_name", "Base name of shared memory",
3456 READ_ONLY GLOBAL_VAR(shared_memory_base_name), CMD_LINE(REQUIRED_ARG),
3457 IN_FS_CHARSET, DEFAULT(0));
3458 #endif
3459
3460 // this has to be NO_CMD_LINE as the command-line option has a different name
3461 static Sys_var_mybool Sys_skip_external_locking(
3462 "skip_external_locking", "Don't use system (external) locking",
3463 READ_ONLY GLOBAL_VAR(my_disable_locking), NO_CMD_LINE, DEFAULT(TRUE));
3464
3465 static Sys_var_mybool Sys_skip_networking(
3466 "skip_networking", "Don't allow connection with TCP/IP",
3467 READ_ONLY GLOBAL_VAR(opt_disable_networking), CMD_LINE(OPT_ARG),
3468 DEFAULT(FALSE));
3469
3470 static Sys_var_mybool Sys_skip_name_resolve(
3471 "skip_name_resolve",
3472 "Don't resolve hostnames. All hostnames are IP's or 'localhost'.",
3473 READ_ONLY GLOBAL_VAR(opt_skip_name_resolve),
3474 CMD_LINE(OPT_ARG, OPT_SKIP_RESOLVE),
3475 DEFAULT(FALSE));
3476
3477 static Sys_var_mybool Sys_skip_show_database(
3478 "skip_show_database", "Don't allow 'SHOW DATABASE' commands",
3479 READ_ONLY GLOBAL_VAR(opt_skip_show_db), CMD_LINE(OPT_ARG),
3480 DEFAULT(FALSE));
3481
3482 static Sys_var_charptr Sys_socket(
3483 "socket", "Socket file to use for connection",
3484 READ_ONLY GLOBAL_VAR(mysqld_unix_port), CMD_LINE(REQUIRED_ARG),
3485 IN_FS_CHARSET, DEFAULT(0));
3486
3487 static Sys_var_ulong Sys_thread_stack(
3488 "thread_stack", "The stack size for each thread",
3489 READ_ONLY GLOBAL_VAR(my_thread_stack_size), CMD_LINE(REQUIRED_ARG),
3490 VALID_RANGE(128*1024, ULONG_MAX), DEFAULT(DEFAULT_THREAD_STACK),
3491 BLOCK_SIZE(1024));
3492
3493 static Sys_var_charptr Sys_tmpdir(
3494 "tmpdir", "Path for temporary files. Several paths may "
3495 "be specified, separated by a "
3496 #if defined(_WIN32)
3497 "semicolon (;)"
3498 #else
3499 "colon (:)"
3500 #endif
3501 ", in this case they are used in a round-robin fashion",
3502 READ_ONLY GLOBAL_VAR(opt_mysql_tmpdir), CMD_LINE(REQUIRED_ARG, 't'),
3503 IN_FS_CHARSET, DEFAULT(0));
3504
fix_trans_mem_root(sys_var * self,THD * thd,enum_var_type type)3505 static bool fix_trans_mem_root(sys_var *self, THD *thd, enum_var_type type)
3506 {
3507 if (type != OPT_GLOBAL)
3508 thd->get_transaction()->init_mem_root_defaults(
3509 thd->variables.trans_alloc_block_size,
3510 thd->variables.trans_prealloc_size);
3511 return false;
3512 }
3513 static Sys_var_ulong Sys_trans_alloc_block_size(
3514 "transaction_alloc_block_size",
3515 "Allocation block size for transactions to be stored in binary log",
3516 SESSION_VAR(trans_alloc_block_size), CMD_LINE(REQUIRED_ARG),
3517 VALID_RANGE(1024, 128 * 1024), DEFAULT(QUERY_ALLOC_BLOCK_SIZE),
3518 BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3519 ON_UPDATE(fix_trans_mem_root));
3520
3521 static Sys_var_ulong Sys_trans_prealloc_size(
3522 "transaction_prealloc_size",
3523 "Persistent buffer for transactions to be stored in binary log",
3524 SESSION_VAR(trans_prealloc_size), CMD_LINE(REQUIRED_ARG),
3525 VALID_RANGE(1024, 128 * 1024), DEFAULT(TRANS_ALLOC_PREALLOC_SIZE),
3526 BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3527 ON_UPDATE(fix_trans_mem_root));
3528
3529 #ifndef EMBEDDED_LIBRARY
3530 static const char *thread_handling_names[]=
3531 {
3532 "one-thread-per-connection", "no-threads",
3533 #ifdef HAVE_POOL_OF_THREADS
3534 "pool-of-threads",
3535 #endif
3536 0
3537 };
3538
3539 #if defined (_WIN32) && defined (HAVE_POOL_OF_THREADS)
3540 /* Windows is using OS threadpool, so we're pretty sure it works well */
3541 #define DEFAULT_THREAD_HANDLING 2
3542 #else
3543 #define DEFAULT_THREAD_HANDLING 0
3544 #endif
3545
3546 static Sys_var_enum Sys_thread_handling(
3547 "thread_handling",
3548 "Define threads usage for handling queries, one of "
3549 "one-thread-per-connection, no-threads"
3550 #ifdef HAVE_POOL_OF_THREADS
3551 ", pool-of-threads"
3552 #endif
3553 , READ_ONLY GLOBAL_VAR(Connection_handler_manager::thread_handling),
3554 CMD_LINE(REQUIRED_ARG), thread_handling_names, DEFAULT(0));
3555 #endif // !EMBEDDED_LIBRARY
3556
fix_query_cache_size(sys_var * self,THD * thd,enum_var_type type)3557 static bool fix_query_cache_size(sys_var *self, THD *thd, enum_var_type type)
3558 {
3559 ulong new_cache_size= query_cache.resize(query_cache_size);
3560 /*
3561 Note: query_cache_size is a global variable reflecting the
3562 requested cache size. See also query_cache_size_arg
3563 */
3564 if (query_cache_size != new_cache_size)
3565 push_warning_printf(current_thd, Sql_condition::SL_WARNING,
3566 ER_WARN_QC_RESIZE, ER(ER_WARN_QC_RESIZE),
3567 query_cache_size, new_cache_size);
3568
3569 query_cache_size= new_cache_size;
3570 return false;
3571 }
3572 static Sys_var_ulong Sys_query_cache_size(
3573 "query_cache_size",
3574 "The memory allocated to store results from old queries. "
3575 "This variable is deprecated and will be removed in a future release.",
3576 GLOBAL_VAR(query_cache_size), CMD_LINE(REQUIRED_ARG),
3577 VALID_RANGE(0, ULONG_MAX), DEFAULT(1024U*1024U), BLOCK_SIZE(1024),
3578 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3579 ON_UPDATE(fix_query_cache_size), DEPRECATED_VAR(""));
3580
3581 static Sys_var_mybool Sys_query_cache_strip_comments(
3582 "query_cache_strip_comments", "Enable and disable optimisation \"strip comment for query cache\" - optimisation strip all comments from query while search query result in query cache",
3583 GLOBAL_VAR(opt_query_cache_strip_comments), CMD_LINE(OPT_ARG),
3584 DEFAULT(FALSE));
3585
3586 static Sys_var_ulong Sys_query_cache_limit(
3587 "query_cache_limit",
3588 "Don't cache results that are bigger than this. "
3589 "This variable is deprecated and will be removed in a future release.",
3590 GLOBAL_VAR(query_cache.query_cache_limit), CMD_LINE(REQUIRED_ARG),
3591 VALID_RANGE(0, ULONG_MAX), DEFAULT(1024*1024), BLOCK_SIZE(1),
3592 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
3593 DEPRECATED_VAR(""));
3594
fix_qcache_min_res_unit(sys_var * self,THD * thd,enum_var_type type)3595 static bool fix_qcache_min_res_unit(sys_var *self, THD *thd, enum_var_type type)
3596 {
3597 query_cache_min_res_unit=
3598 query_cache.set_min_res_unit(query_cache_min_res_unit);
3599 return false;
3600 }
3601 static Sys_var_ulong Sys_query_cache_min_res_unit(
3602 "query_cache_min_res_unit",
3603 "The minimum size for blocks allocated by the query cache. "
3604 "This variable is deprecated and will be removed in a future release.",
3605 GLOBAL_VAR(query_cache_min_res_unit), CMD_LINE(REQUIRED_ARG),
3606 VALID_RANGE(0, ULONG_MAX), DEFAULT(QUERY_CACHE_MIN_RESULT_DATA_SIZE),
3607 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3608 ON_UPDATE(fix_qcache_min_res_unit), DEPRECATED_VAR(""));
3609
3610 static const char *query_cache_type_names[]= { "OFF", "ON", "DEMAND", 0 };
check_query_cache_type(sys_var * self,THD * thd,set_var * var)3611 static bool check_query_cache_type(sys_var *self, THD *thd, set_var *var)
3612 {
3613 /*
3614 Setting it to 0 (or OFF) is always OK, even if the query cache
3615 is disabled.
3616 */
3617 if (var->save_result.ulonglong_value == 0)
3618 return false;
3619 else if (query_cache.is_disabled())
3620 {
3621 my_error(ER_QUERY_CACHE_DISABLED, MYF(0));
3622 return true;
3623 }
3624 return false;
3625 }
3626 static Sys_var_enum Sys_query_cache_type(
3627 "query_cache_type",
3628 "OFF = Don't cache or retrieve results. ON = Cache all results "
3629 "except SELECT SQL_NO_CACHE ... queries. DEMAND = Cache only "
3630 "SELECT SQL_CACHE ... queries. "
3631 "This variable is deprecated and will be removed in a future release.",
3632 SESSION_VAR(query_cache_type), CMD_LINE(REQUIRED_ARG),
3633 query_cache_type_names, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG,
3634 ON_CHECK(check_query_cache_type), ON_UPDATE(NULL), DEPRECATED_VAR(""));
3635
3636 static Sys_var_mybool Sys_query_cache_wlock_invalidate(
3637 "query_cache_wlock_invalidate",
3638 "Invalidate queries in query cache on LOCK for write. "
3639 "This variable is deprecated and will be removed in a future release.",
3640 SESSION_VAR(query_cache_wlock_invalidate), CMD_LINE(OPT_ARG),
3641 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
3642 ON_UPDATE(NULL), DEPRECATED_VAR(""));
3643
3644 static bool
on_check_opt_secure_auth(sys_var * self,THD * thd,set_var * var)3645 on_check_opt_secure_auth(sys_var *self, THD *thd, set_var *var)
3646 {
3647 push_deprecated_warn_no_replacement(thd, "--secure-auth");
3648 return (!var->save_result.ulonglong_value);
3649 }
3650
3651 static Sys_var_mybool Sys_secure_auth(
3652 "secure_auth",
3653 "Disallow authentication for accounts that have old (pre-4.1) "
3654 "passwords. Deprecated. Always TRUE.",
3655 GLOBAL_VAR(opt_secure_auth), CMD_LINE(OPT_ARG, OPT_SECURE_AUTH),
3656 DEFAULT(TRUE),
3657 NO_MUTEX_GUARD, NOT_IN_BINLOG,
3658 ON_CHECK(on_check_opt_secure_auth)
3659 );
3660
3661 static Sys_var_charptr Sys_secure_file_priv(
3662 "secure_file_priv",
3663 "Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
3664 "within specified directory",
3665 READ_ONLY GLOBAL_VAR(opt_secure_file_priv),
3666 #ifndef EMBEDDED_LIBRARY
3667 CMD_LINE(REQUIRED_ARG), IN_FS_CHARSET, DEFAULT(DEFAULT_SECURE_FILE_PRIV_DIR));
3668 #else
3669 CMD_LINE(REQUIRED_ARG), IN_FS_CHARSET, DEFAULT(DEFAULT_SECURE_FILE_PRIV_EMBEDDED_DIR));
3670 #endif
3671
fix_server_id(sys_var * self,THD * thd,enum_var_type type)3672 static bool fix_server_id(sys_var *self, THD *thd, enum_var_type type)
3673 {
3674 // server_id is 'MYSQL_PLUGIN_IMPORT ulong'
3675 // So we cast here, rather than change its type.
3676 server_id_supplied = 1;
3677 thd->server_id= thd->variables.pseudo_server_id != 0 ?
3678 thd->variables.pseudo_server_id : static_cast<uint32>(server_id);
3679 return false;
3680 }
3681 static Sys_var_ulong Sys_server_id(
3682 "server_id",
3683 "Uniquely identifies the server instance in the community of "
3684 "replication partners",
3685 GLOBAL_VAR(server_id), CMD_LINE(REQUIRED_ARG, OPT_SERVER_ID),
3686 VALID_RANGE(0, UINT_MAX32), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
3687 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(fix_server_id));
3688
3689 static Sys_var_charptr Sys_server_uuid(
3690 "server_uuid",
3691 "Uniquely identifies the server instance in the universe",
3692 READ_ONLY GLOBAL_VAR(server_uuid_ptr),
3693 NO_CMD_LINE, IN_FS_CHARSET, DEFAULT(server_uuid));
3694
3695 static Sys_var_uint Sys_server_id_bits(
3696 "server_id_bits",
3697 "Set number of significant bits in server-id",
3698 GLOBAL_VAR(opt_server_id_bits), CMD_LINE(REQUIRED_ARG),
3699 VALID_RANGE(0, 32), DEFAULT(32), BLOCK_SIZE(1));
3700
3701 static Sys_var_mybool Sys_slave_compressed_protocol(
3702 "slave_compressed_protocol",
3703 "Use compression on master/slave protocol",
3704 GLOBAL_VAR(opt_slave_compressed_protocol), CMD_LINE(OPT_ARG),
3705 DEFAULT(FALSE));
3706
3707 #ifdef HAVE_REPLICATION
3708 static const char *slave_exec_mode_names[]=
3709 {"STRICT", "IDEMPOTENT", 0};
3710 static Sys_var_enum Slave_exec_mode(
3711 "slave_exec_mode",
3712 "Modes for how replication events should be executed. Legal values "
3713 "are STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, "
3714 "replication will not stop for operations that are idempotent. "
3715 "In STRICT mode, replication will stop on any unexpected difference "
3716 "between the master and the slave",
3717 GLOBAL_VAR(slave_exec_mode_options), CMD_LINE(REQUIRED_ARG),
3718 slave_exec_mode_names, DEFAULT(RBR_EXEC_MODE_STRICT));
3719
3720 const char *slave_type_conversions_name[]=
3721 {"ALL_LOSSY", "ALL_NON_LOSSY", "ALL_UNSIGNED", "ALL_SIGNED", 0};
3722 static Sys_var_set Slave_type_conversions(
3723 "slave_type_conversions",
3724 "Set of slave type conversions that are enabled. Legal values are:"
3725 " ALL_LOSSY to enable lossy conversions,"
3726 " ALL_NON_LOSSY to enable non-lossy conversions,"
3727 " ALL_UNSIGNED to treat all integer column type data to be unsigned values, and"
3728 " ALL_SIGNED to treat all integer column type data to be signed values."
3729 " Default treatment is ALL_SIGNED. If ALL_SIGNED and ALL_UNSIGNED both are"
3730 " specified, ALL_SIGNED will take higher priority than ALL_UNSIGNED."
3731 " If the variable is assigned the empty set, no conversions are"
3732 " allowed and it is expected that the types match exactly.",
3733 GLOBAL_VAR(slave_type_conversions_options), CMD_LINE(REQUIRED_ARG),
3734 slave_type_conversions_name,
3735 DEFAULT(0));
3736
3737 static Sys_var_mybool Sys_slave_sql_verify_checksum(
3738 "slave_sql_verify_checksum",
3739 "Force checksum verification of replication events after reading them "
3740 "from relay log. Note: Events are always checksum-verified by slave on "
3741 "receiving them from the network before writing them to the relay "
3742 "log. Enabled by default.",
3743 GLOBAL_VAR(opt_slave_sql_verify_checksum), CMD_LINE(OPT_ARG), DEFAULT(TRUE));
3744
check_not_null_not_empty(sys_var * self,THD * thd,set_var * var)3745 static bool check_not_null_not_empty(sys_var *self, THD *thd, set_var *var)
3746 {
3747 String str, *res;
3748 /* null value is not allowed */
3749 if (check_not_null(self, thd, var))
3750 return true;
3751
3752 /** empty value ('') is not allowed */
3753 res= var->value? var->value->val_str(&str) : NULL;
3754 if (res && res->is_empty())
3755 return true;
3756
3757 return false;
3758 }
3759
check_slave_stopped(sys_var * self,THD * thd,set_var * var)3760 static bool check_slave_stopped(sys_var *self, THD *thd, set_var *var)
3761 {
3762 bool result= false;
3763 Master_info *mi= 0;
3764
3765 if (check_not_null_not_empty(self, thd, var))
3766 return true;
3767
3768 channel_map.wrlock();
3769
3770 for (mi_map::iterator it= channel_map.begin(); it!= channel_map.end(); it++)
3771 {
3772 mi= it->second;
3773 if (mi)
3774 {
3775 mysql_mutex_lock(&mi->rli->run_lock);
3776 if (mi->rli->slave_running)
3777 {
3778 my_error(ER_SLAVE_SQL_THREAD_MUST_STOP, MYF(0));
3779 result= true;
3780 }
3781 mysql_mutex_unlock(&mi->rli->run_lock);
3782 }
3783 }
3784 channel_map.unlock();
3785 return result;
3786 }
3787
3788 static const char *slave_rows_search_algorithms_names[]= {"TABLE_SCAN", "INDEX_SCAN", "HASH_SCAN", 0};
3789 static Sys_var_set Slave_rows_search_algorithms(
3790 "slave_rows_search_algorithms",
3791 "Set of searching algorithms that the slave will use while "
3792 "searching for records from the storage engine to either "
3793 "updated or deleted them. Possible values are: INDEX_SCAN, "
3794 "TABLE_SCAN and HASH_SCAN. Any combination is allowed, and "
3795 "the slave will always pick the most suitable algorithm for "
3796 "any given scenario. "
3797 "(Default: INDEX_SCAN, TABLE_SCAN).",
3798 GLOBAL_VAR(slave_rows_search_algorithms_options), CMD_LINE(REQUIRED_ARG),
3799 slave_rows_search_algorithms_names,
3800 DEFAULT(SLAVE_ROWS_INDEX_SCAN | SLAVE_ROWS_TABLE_SCAN), NO_MUTEX_GUARD,
3801 NOT_IN_BINLOG, ON_CHECK(check_not_null_not_empty), ON_UPDATE(NULL));
3802
3803 static const char *mts_parallel_type_names[]= {"DATABASE", "LOGICAL_CLOCK", 0};
3804 static Sys_var_enum Mts_parallel_type(
3805 "slave_parallel_type",
3806 "Specifies if the slave will use database partitioning "
3807 "or information from master to parallelize transactions."
3808 "(Default: DATABASE).",
3809 GLOBAL_VAR(mts_parallel_option), CMD_LINE(REQUIRED_ARG),
3810 mts_parallel_type_names,
3811 DEFAULT(MTS_PARALLEL_TYPE_DB_NAME), NO_MUTEX_GUARD,
3812 NOT_IN_BINLOG, ON_CHECK(check_slave_stopped),
3813 ON_UPDATE(NULL));
3814
check_binlog_transaction_dependency_tracking(sys_var * self,THD * thd,set_var * var)3815 static bool check_binlog_transaction_dependency_tracking(sys_var *self, THD *thd, set_var *var)
3816 {
3817 if (global_system_variables.transaction_write_set_extraction == HASH_ALGORITHM_OFF
3818 && var->save_result.ulonglong_value != DEPENDENCY_TRACKING_COMMIT_ORDER)
3819 {
3820 my_error(ER_WRONG_USAGE, MYF(0),
3821 "binlog_transaction_dependency_tracking (!= COMMIT_ORDER)",
3822 "transaction_write_set_extraction (= OFF)");
3823
3824 return true;
3825 }
3826 return false;
3827 }
3828
update_binlog_transaction_dependency_tracking(sys_var * var,THD * thd,enum_var_type v)3829 static bool update_binlog_transaction_dependency_tracking(sys_var* var, THD* thd, enum_var_type v)
3830 {
3831 /*
3832 m_opt_tracking_mode is read and written in an atomic way based
3833 on the value of m_opt_tracking_mode_value that is associated
3834 with the sys_var variable.
3835 */
3836 set_mysqld_opt_tracking_mode();
3837 /*
3838 the writeset_history_start needs to be set to 0 whenever there is a
3839 change in the transaction dependency source so that WS and COMMIT
3840 transition smoothly.
3841 */
3842 mysql_bin_log.m_dependency_tracker.tracking_mode_changed();
3843 return false;
3844 }
3845
update_binlog_transaction_dependency_history_size(sys_var * var,THD * thd,enum_var_type v)3846 static bool update_binlog_transaction_dependency_history_size(sys_var* var, THD* thd, enum_var_type v)
3847 {
3848 my_atomic_store64(&mysql_bin_log.m_dependency_tracker.get_writeset()->m_opt_max_history_size,
3849 static_cast<int64>(mysql_bin_log.m_dependency_tracker.get_writeset()->
3850 m_opt_max_history_size_base_var));
3851 return false;
3852 }
3853
3854
3855 static PolyLock_mutex
3856 PLock_slave_trans_dep_tracker(&LOCK_slave_trans_dep_tracker);
3857 static const char *opt_binlog_transaction_dependency_tracking_names[]=
3858 {"COMMIT_ORDER", "WRITESET", "WRITESET_SESSION", NullS};
3859 static Sys_var_enum Binlog_transaction_dependency_tracking(
3860 "binlog_transaction_dependency_tracking",
3861 "Selects the source of dependency information from which to "
3862 "assess which transactions can be executed in parallel by the "
3863 "slave's multi-threaded applier. "
3864 "Possible values are COMMIT_ORDER, WRITESET and WRITESET_SESSION.",
3865 GLOBAL_VAR(mysql_bin_log.m_dependency_tracker.m_opt_tracking_mode_value),
3866 CMD_LINE(REQUIRED_ARG), opt_binlog_transaction_dependency_tracking_names,
3867 DEFAULT(DEPENDENCY_TRACKING_COMMIT_ORDER),
3868 &PLock_slave_trans_dep_tracker,
3869 NOT_IN_BINLOG, ON_CHECK(check_binlog_transaction_dependency_tracking),
3870 ON_UPDATE(update_binlog_transaction_dependency_tracking));
3871 static Sys_var_ulong Binlog_transaction_dependency_history_size(
3872 "binlog_transaction_dependency_history_size",
3873 "Maximum number of rows to keep in the writeset history.",
3874 GLOBAL_VAR(mysql_bin_log.m_dependency_tracker.get_writeset()->m_opt_max_history_size_base_var),
3875 CMD_LINE(REQUIRED_ARG, 0), VALID_RANGE(1, 1000000), DEFAULT(25000),
3876 BLOCK_SIZE(1), &PLock_slave_trans_dep_tracker, NOT_IN_BINLOG, ON_CHECK(NULL),
3877 ON_UPDATE(update_binlog_transaction_dependency_history_size));
3878
3879 static Sys_var_mybool Sys_slave_preserve_commit_order(
3880 "slave_preserve_commit_order",
3881 "Force slave workers to make commits in the same order as on the master. "
3882 "Disabled by default.",
3883 GLOBAL_VAR(opt_slave_preserve_commit_order), CMD_LINE(OPT_ARG),
3884 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
3885 ON_CHECK(check_slave_stopped),
3886 ON_UPDATE(NULL));
3887 #endif
3888
global_update(THD * thd,set_var * var)3889 bool Sys_var_enum_binlog_checksum::global_update(THD *thd, set_var *var)
3890 {
3891 bool check_purge= false;
3892
3893 /*
3894 SET binlog_checksome command should ignore 'read-only' and 'super_read_only'
3895 options so that it can update 'mysql.gtid_executed' replication repository
3896 table.
3897 */
3898 thd->set_skip_readonly_check();
3899 mysql_mutex_lock(mysql_bin_log.get_log_lock());
3900 if(mysql_bin_log.is_open())
3901 {
3902 bool alg_changed=
3903 (binlog_checksum_options != (uint) var->save_result.ulonglong_value);
3904 if (alg_changed)
3905 mysql_bin_log.checksum_alg_reset= (uint8) var->save_result.ulonglong_value;
3906 mysql_bin_log.rotate(true, &check_purge);
3907 if (alg_changed)
3908 mysql_bin_log.checksum_alg_reset= binary_log::BINLOG_CHECKSUM_ALG_UNDEF; // done
3909 }
3910 else
3911 {
3912 binlog_checksum_options=
3913 static_cast<ulong>(var->save_result.ulonglong_value);
3914 }
3915 assert(binlog_checksum_options == var->save_result.ulonglong_value);
3916 assert(mysql_bin_log.checksum_alg_reset ==
3917 binary_log::BINLOG_CHECKSUM_ALG_UNDEF);
3918 mysql_mutex_unlock(mysql_bin_log.get_log_lock());
3919
3920 if (check_purge)
3921 mysql_bin_log.purge();
3922
3923 return 0;
3924 }
3925
3926 static Sys_var_enum_binlog_checksum Binlog_checksum_enum(
3927 "binlog_checksum", "Type of BINLOG_CHECKSUM_ALG. Include checksum for "
3928 "log events in the binary log. Possible values are NONE and CRC32; "
3929 "default is CRC32.",
3930 GLOBAL_VAR(binlog_checksum_options), CMD_LINE(REQUIRED_ARG),
3931 binlog_checksum_type_names, DEFAULT(binary_log::BINLOG_CHECKSUM_ALG_CRC32),
3932 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_outside_trx));
3933
3934 static Sys_var_mybool Sys_master_verify_checksum(
3935 "master_verify_checksum",
3936 "Force checksum verification of logged events in binary log before "
3937 "sending them to slaves or printing them in output of SHOW BINLOG EVENTS. "
3938 "Disabled by default.",
3939 GLOBAL_VAR(opt_master_verify_checksum), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
3940
3941 static Sys_var_ulong Sys_slow_launch_time(
3942 "slow_launch_time",
3943 "If creating the thread takes longer than this value (in seconds), "
3944 "the Slow_launch_threads counter will be incremented",
3945 GLOBAL_VAR(slow_launch_time), CMD_LINE(REQUIRED_ARG),
3946 VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(2), BLOCK_SIZE(1));
3947
3948 static Sys_var_ulong Sys_sort_buffer(
3949 "sort_buffer_size",
3950 "Each thread that needs to do a sort allocates a buffer of this size",
3951 SESSION_VAR(sortbuff_size), CMD_LINE(REQUIRED_ARG),
3952 VALID_RANGE(MIN_SORT_MEMORY, ULONG_MAX), DEFAULT(DEFAULT_SORT_MEMORY),
3953 BLOCK_SIZE(1));
3954
3955 /**
3956 Check sql modes strict_mode, 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and
3957 'ERROR_FOR_DIVISION_BY_ZERO' are used together. If only subset of it
3958 is set then warning is reported.
3959
3960 @param sql_mode sql mode.
3961 */
check_sub_modes_of_strict_mode(sql_mode_t & sql_mode,THD * thd)3962 static void check_sub_modes_of_strict_mode(sql_mode_t &sql_mode, THD *thd)
3963 {
3964 const sql_mode_t strict_modes= (MODE_STRICT_TRANS_TABLES |
3965 MODE_STRICT_ALL_TABLES);
3966
3967 const sql_mode_t new_strict_submodes= (MODE_NO_ZERO_IN_DATE |
3968 MODE_NO_ZERO_DATE |
3969 MODE_ERROR_FOR_DIVISION_BY_ZERO);
3970
3971 const sql_mode_t strict_modes_set= (sql_mode & strict_modes);
3972 const sql_mode_t new_strict_submodes_set= (sql_mode & new_strict_submodes);
3973
3974 if (((strict_modes_set | new_strict_submodes_set) !=0) &&
3975 ((new_strict_submodes_set != new_strict_submodes) ||
3976 (strict_modes_set == 0)))
3977 {
3978 if (thd)
3979 push_warning(thd, Sql_condition::SL_WARNING,
3980 ER_SQL_MODE_MERGED,
3981 ER_THD(thd, ER_SQL_MODE_MERGED));
3982 else
3983 sql_print_warning("'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and "
3984 "'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used "
3985 "with strict mode. They will be merged with strict mode "
3986 "in a future release.");
3987 }
3988 }
3989
expand_sql_mode(sql_mode_t sql_mode,THD * thd)3990 export sql_mode_t expand_sql_mode(sql_mode_t sql_mode, THD *thd)
3991 {
3992 if (sql_mode & MODE_ANSI)
3993 {
3994 /*
3995 Note that we dont set
3996 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | MODE_NO_FIELD_OPTIONS
3997 to allow one to get full use of MySQL in this mode.
3998 */
3999 sql_mode|= (MODE_REAL_AS_FLOAT | MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
4000 MODE_IGNORE_SPACE | MODE_ONLY_FULL_GROUP_BY);
4001 }
4002 if (sql_mode & MODE_ORACLE)
4003 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
4004 MODE_IGNORE_SPACE |
4005 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
4006 MODE_NO_FIELD_OPTIONS | MODE_NO_AUTO_CREATE_USER);
4007 if (sql_mode & MODE_MSSQL)
4008 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
4009 MODE_IGNORE_SPACE |
4010 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
4011 MODE_NO_FIELD_OPTIONS);
4012 if (sql_mode & MODE_POSTGRESQL)
4013 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
4014 MODE_IGNORE_SPACE |
4015 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
4016 MODE_NO_FIELD_OPTIONS);
4017 if (sql_mode & MODE_DB2)
4018 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
4019 MODE_IGNORE_SPACE |
4020 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
4021 MODE_NO_FIELD_OPTIONS);
4022 if (sql_mode & MODE_MAXDB)
4023 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
4024 MODE_IGNORE_SPACE |
4025 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
4026 MODE_NO_FIELD_OPTIONS | MODE_NO_AUTO_CREATE_USER);
4027 if (sql_mode & MODE_MYSQL40)
4028 sql_mode|= MODE_HIGH_NOT_PRECEDENCE;
4029 if (sql_mode & MODE_MYSQL323)
4030 sql_mode|= MODE_HIGH_NOT_PRECEDENCE;
4031 if (sql_mode & MODE_TRADITIONAL)
4032 sql_mode|= (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES |
4033 MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
4034 MODE_ERROR_FOR_DIVISION_BY_ZERO | MODE_NO_AUTO_CREATE_USER |
4035 MODE_NO_ENGINE_SUBSTITUTION);
4036
4037 check_sub_modes_of_strict_mode(sql_mode, thd);
4038 return sql_mode;
4039 }
check_sql_mode(sys_var * self,THD * thd,set_var * var)4040 static bool check_sql_mode(sys_var *self, THD *thd, set_var *var)
4041 {
4042 var->save_result.ulonglong_value=
4043 expand_sql_mode(var->save_result.ulonglong_value, thd);
4044
4045 /* Warning displayed only if the non default sql_mode is specified. */
4046 if (var->value)
4047 {
4048 /* Check if the NO_AUTO_CREATE_USER flag has been swapped. */
4049 if ((thd->variables.sql_mode ^ var->save_result.ulonglong_value) &
4050 MODE_NO_AUTO_CREATE_USER)
4051 {
4052 push_warning_printf(thd, Sql_condition::SL_WARNING,
4053 ER_WARN_DEPRECATED_SQLMODE,
4054 ER_THD(thd, ER_WARN_DEPRECATED_SQLMODE),
4055 "NO_AUTO_CREATE_USER");
4056 }
4057 static const sql_mode_t deprecated_mask= MODE_DB2 | MODE_MAXDB |
4058 MODE_MSSQL | MODE_MYSQL323 | MODE_MYSQL40 | MODE_ORACLE |
4059 MODE_POSTGRESQL | MODE_NO_FIELD_OPTIONS | MODE_NO_KEY_OPTIONS |
4060 MODE_NO_TABLE_OPTIONS;
4061 sql_mode_t deprecated_modes=
4062 var->save_result.ulonglong_value & deprecated_mask;
4063 if (deprecated_modes != 0)
4064 {
4065 LEX_STRING buf;
4066 if (sql_mode_string_representation(thd, deprecated_modes, &buf))
4067 return true; // OOM
4068 push_warning_printf(thd, Sql_condition::SL_WARNING,
4069 ER_WARN_DEPRECATED_SQLMODE,
4070 ER_THD(thd, ER_WARN_DEPRECATED_SQLMODE),
4071 buf.str);
4072 }
4073 }
4074
4075 return false;
4076 }
fix_sql_mode(sys_var * self,THD * thd,enum_var_type type)4077 static bool fix_sql_mode(sys_var *self, THD *thd, enum_var_type type)
4078 {
4079 if (type != OPT_GLOBAL)
4080 {
4081 /* Update thd->server_status */
4082 if (thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
4083 thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
4084 else
4085 thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES;
4086 }
4087 return false;
4088 }
4089 /*
4090 WARNING: When adding new SQL modes don't forget to update the
4091 tables definitions that stores it's value (ie: mysql.event, mysql.proc)
4092 */
4093 static const char *sql_mode_names[]=
4094 {
4095 "REAL_AS_FLOAT", "PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", ",",
4096 "ONLY_FULL_GROUP_BY", "NO_UNSIGNED_SUBTRACTION", "NO_DIR_IN_CREATE",
4097 "POSTGRESQL", "ORACLE", "MSSQL", "DB2", "MAXDB", "NO_KEY_OPTIONS",
4098 "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "MYSQL323", "MYSQL40", "ANSI",
4099 "NO_AUTO_VALUE_ON_ZERO", "NO_BACKSLASH_ESCAPES", "STRICT_TRANS_TABLES",
4100 "STRICT_ALL_TABLES", "NO_ZERO_IN_DATE", "NO_ZERO_DATE",
4101 "ALLOW_INVALID_DATES", "ERROR_FOR_DIVISION_BY_ZERO", "TRADITIONAL",
4102 "NO_AUTO_CREATE_USER", "HIGH_NOT_PRECEDENCE", "NO_ENGINE_SUBSTITUTION",
4103 "PAD_CHAR_TO_FULL_LENGTH",
4104 0
4105 };
sql_mode_string_representation(THD * thd,sql_mode_t sql_mode,LEX_STRING * ls)4106 export bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode,
4107 LEX_STRING *ls)
4108 {
4109 set_to_string(thd, ls, sql_mode, sql_mode_names);
4110 return ls->str == 0;
4111 }
4112 /*
4113 sql_mode should *not* be IN_BINLOG: even though it is written to the binlog,
4114 the slave ignores the MODE_NO_DIR_IN_CREATE variable, so slave's value
4115 differs from master's (see log_event.cc: Query_log_event::do_apply_event()).
4116 */
4117 static Sys_var_set Sys_sql_mode(
4118 "sql_mode",
4119 "Syntax: sql-mode=mode[,mode[,mode...]]. See the manual for the "
4120 "complete list of valid sql modes",
4121 SESSION_VAR(sql_mode), CMD_LINE(REQUIRED_ARG),
4122 sql_mode_names,
4123 DEFAULT(MODE_NO_ENGINE_SUBSTITUTION |
4124 MODE_ONLY_FULL_GROUP_BY |
4125 MODE_STRICT_TRANS_TABLES |
4126 MODE_NO_ZERO_IN_DATE |
4127 MODE_NO_ZERO_DATE |
4128 MODE_ERROR_FOR_DIVISION_BY_ZERO |
4129 MODE_NO_AUTO_CREATE_USER),
4130 NO_MUTEX_GUARD,
4131 NOT_IN_BINLOG, ON_CHECK(check_sql_mode), ON_UPDATE(fix_sql_mode));
4132
4133 static Sys_var_ulong Sys_max_execution_time(
4134 "max_execution_time",
4135 "Kill SELECT statement that takes over the specified number of milliseconds",
4136 SESSION_VAR(max_execution_time), CMD_LINE(REQUIRED_ARG),
4137 VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
4138
4139 #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
4140 #define SSL_OPT(X) CMD_LINE(REQUIRED_ARG,X)
4141 #else
4142 #define SSL_OPT(X) NO_CMD_LINE
4143 #endif
4144
4145 /*
4146 If you are adding new system variable for SSL communication, please take a
4147 look at do_auto_cert_generation() function in sql_authentication.cc and
4148 add new system variable in checks if required.
4149 */
4150
4151 static Sys_var_charptr Sys_ssl_ca(
4152 "ssl_ca",
4153 "CA file in PEM format (check OpenSSL docs, implies --ssl)",
4154 READ_ONLY GLOBAL_VAR(opt_ssl_ca), SSL_OPT(OPT_SSL_CA),
4155 IN_FS_CHARSET, DEFAULT(0));
4156
4157 static Sys_var_charptr Sys_ssl_capath(
4158 "ssl_capath",
4159 "CA directory (check OpenSSL docs, implies --ssl)",
4160 READ_ONLY GLOBAL_VAR(opt_ssl_capath), SSL_OPT(OPT_SSL_CAPATH),
4161 IN_FS_CHARSET, DEFAULT(0));
4162
4163 static Sys_var_charptr Sys_tls_version(
4164 "tls_version",
4165 "TLS version, permitted values are TLSv1, TLSv1.1, TLSv1.2(Only for openssl)",
4166 READ_ONLY GLOBAL_VAR(opt_tls_version), SSL_OPT(OPT_TLS_VERSION),
4167 IN_FS_CHARSET, "TLSv1,TLSv1.1,TLSv1.2");
4168
4169 static Sys_var_charptr Sys_ssl_cert(
4170 "ssl_cert", "X509 cert in PEM format (implies --ssl)",
4171 READ_ONLY GLOBAL_VAR(opt_ssl_cert), SSL_OPT(OPT_SSL_CERT),
4172 IN_FS_CHARSET, DEFAULT(0));
4173
4174 static Sys_var_charptr Sys_ssl_cipher(
4175 "ssl_cipher", "SSL cipher to use (implies --ssl)",
4176 READ_ONLY GLOBAL_VAR(opt_ssl_cipher), SSL_OPT(OPT_SSL_CIPHER),
4177 IN_FS_CHARSET, DEFAULT(0));
4178
4179 static Sys_var_charptr Sys_ssl_key(
4180 "ssl_key", "X509 key in PEM format (implies --ssl)",
4181 READ_ONLY GLOBAL_VAR(opt_ssl_key), SSL_OPT(OPT_SSL_KEY),
4182 IN_FS_CHARSET, DEFAULT(0));
4183
4184 static Sys_var_charptr Sys_ssl_crl(
4185 "ssl_crl",
4186 "CRL file in PEM format (check OpenSSL docs, implies --ssl)",
4187 READ_ONLY GLOBAL_VAR(opt_ssl_crl), SSL_OPT(OPT_SSL_CRL),
4188 IN_FS_CHARSET, DEFAULT(0));
4189
4190 static Sys_var_charptr Sys_ssl_crlpath(
4191 "ssl_crlpath",
4192 "CRL directory (check OpenSSL docs, implies --ssl)",
4193 READ_ONLY GLOBAL_VAR(opt_ssl_crlpath), SSL_OPT(OPT_SSL_CRLPATH),
4194 IN_FS_CHARSET, DEFAULT(0));
4195
4196 #if defined(HAVE_OPENSSL)
4197 static Sys_var_mybool Sys_auto_generate_certs(
4198 "auto_generate_certs",
4199 "Auto generate SSL certificates at server startup if --ssl is set to "
4200 "ON and none of the other SSL system variables are specified and "
4201 "certificate/key files are not present in data directory.",
4202 READ_ONLY GLOBAL_VAR(opt_auto_generate_certs),
4203 CMD_LINE(OPT_ARG),
4204 DEFAULT(TRUE),
4205 NO_MUTEX_GUARD,
4206 NOT_IN_BINLOG,
4207 ON_CHECK(NULL),
4208 ON_UPDATE(NULL),
4209 NULL);
4210 #endif /* HAVE_OPENSSL */
4211
4212 // why ENUM and not BOOL ?
4213 static const char *updatable_views_with_limit_names[]= {"NO", "YES", 0};
4214 static Sys_var_enum Sys_updatable_views_with_limit(
4215 "updatable_views_with_limit",
4216 "YES = Don't issue an error message (warning only) if a VIEW without "
4217 "presence of a key of the underlying table is used in queries with a "
4218 "LIMIT clause for updating. NO = Prohibit update of a VIEW, which "
4219 "does not contain a key of the underlying table and the query uses "
4220 "a LIMIT clause (usually get from GUI tools)",
4221 SESSION_VAR(updatable_views_with_limit), CMD_LINE(REQUIRED_ARG),
4222 updatable_views_with_limit_names, DEFAULT(TRUE));
4223
4224 static Sys_var_mybool Sys_sync_frm(
4225 "sync_frm", "Sync .frm files to disk on creation",
4226 GLOBAL_VAR(opt_sync_frm), CMD_LINE(OPT_ARG),
4227 DEFAULT(TRUE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
4228 ON_CHECK(0), ON_UPDATE(0), DEPRECATED_VAR(""));
4229
4230 static char *system_time_zone_ptr;
4231 static Sys_var_charptr Sys_system_time_zone(
4232 "system_time_zone", "The server system time zone",
4233 READ_ONLY GLOBAL_VAR(system_time_zone_ptr), NO_CMD_LINE,
4234 IN_FS_CHARSET, DEFAULT(system_time_zone));
4235
4236 static Sys_var_ulong Sys_table_def_size(
4237 "table_definition_cache",
4238 "The number of cached table definitions",
4239 GLOBAL_VAR(table_def_size),
4240 CMD_LINE(REQUIRED_ARG, OPT_TABLE_DEFINITION_CACHE),
4241 VALID_RANGE(TABLE_DEF_CACHE_MIN, 512*1024),
4242 DEFAULT(TABLE_DEF_CACHE_DEFAULT),
4243 BLOCK_SIZE(1),
4244 NO_MUTEX_GUARD,
4245 NOT_IN_BINLOG,
4246 ON_CHECK(NULL),
4247 ON_UPDATE(NULL),
4248 NULL,
4249 /* table_definition_cache is used as a sizing hint by the performance schema. */
4250 sys_var::PARSE_EARLY);
4251
fix_table_cache_size(sys_var * self,THD * thd,enum_var_type type)4252 static bool fix_table_cache_size(sys_var *self, THD *thd, enum_var_type type)
4253 {
4254 /*
4255 table_open_cache parameter is a soft limit for total number of objects
4256 in all table cache instances. Once this value is updated we need to
4257 update value of a per-instance soft limit on table cache size.
4258 */
4259 table_cache_size_per_instance= table_cache_size / table_cache_instances;
4260 return false;
4261 }
4262
4263 static Sys_var_ulong Sys_table_cache_size(
4264 "table_open_cache", "The number of cached open tables "
4265 "(total for all table cache instances)",
4266 GLOBAL_VAR(table_cache_size), CMD_LINE(REQUIRED_ARG),
4267 VALID_RANGE(1, 512*1024), DEFAULT(TABLE_OPEN_CACHE_DEFAULT),
4268 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
4269 ON_UPDATE(fix_table_cache_size),
4270 NULL,
4271 /* table_open_cache is used as a sizing hint by the performance schema. */
4272 sys_var::PARSE_EARLY);
4273
4274 static Sys_var_ulong Sys_table_cache_instances(
4275 "table_open_cache_instances", "The number of table cache instances",
4276 READ_ONLY GLOBAL_VAR(table_cache_instances), CMD_LINE(REQUIRED_ARG),
4277 VALID_RANGE(1, Table_cache_manager::MAX_TABLE_CACHES),
4278 DEFAULT(Table_cache_manager::DEFAULT_MAX_TABLE_CACHES),
4279 BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
4280 ON_UPDATE(NULL), NULL,
4281 /*
4282 table_open_cache is used as a sizing hint by the performance schema,
4283 and 'table_open_cache' is a prefix of 'table_open_cache_instances'.
4284 Is is better to keep these options together, to avoid confusing
4285 handle_options() with partial name matches.
4286 */
4287 sys_var::PARSE_EARLY);
4288
4289 #ifndef EMBEDDED_LIBRARY
4290 static Sys_var_ulong Sys_thread_cache_size(
4291 "thread_cache_size",
4292 "How many threads we should keep in a cache for reuse",
4293 GLOBAL_VAR(Per_thread_connection_handler::max_blocked_pthreads),
4294 CMD_LINE(REQUIRED_ARG, OPT_THREAD_CACHE_SIZE),
4295 VALID_RANGE(0, 16384), DEFAULT(0), BLOCK_SIZE(1));
4296 #endif // !EMBEDDED_LIBRARY
4297
4298 #ifdef HAVE_POOL_OF_THREADS
4299
fix_tp_max_threads(sys_var *,THD *,enum_var_type)4300 static bool fix_tp_max_threads(sys_var *, THD *, enum_var_type)
4301 {
4302 #ifdef _WIN32
4303 tp_set_max_threads(threadpool_max_threads);
4304 #endif
4305 return false;
4306 }
4307
4308
4309 #ifdef _WIN32
fix_tp_min_threads(sys_var *,THD *,enum_var_type)4310 static bool fix_tp_min_threads(sys_var *, THD *, enum_var_type)
4311 {
4312 tp_set_min_threads(threadpool_min_threads);
4313 return false;
4314 }
4315 #endif
4316
4317
4318 #ifndef _WIN32
fix_threadpool_size(sys_var *,THD *,enum_var_type)4319 static bool fix_threadpool_size(sys_var*, THD*, enum_var_type)
4320 {
4321 tp_set_threadpool_size(threadpool_size);
4322 return false;
4323 }
4324
4325
fix_threadpool_stall_limit(sys_var *,THD *,enum_var_type)4326 static bool fix_threadpool_stall_limit(sys_var*, THD*, enum_var_type)
4327 {
4328 tp_set_threadpool_stall_limit(threadpool_stall_limit);
4329 return false;
4330 }
4331 #endif
4332
my_getncpus()4333 static inline int my_getncpus()
4334 {
4335 #ifdef _SC_NPROCESSORS_ONLN
4336 return sysconf(_SC_NPROCESSORS_ONLN);
4337 #else
4338 return 2; /* The value returned by the old my_getncpus implementation */
4339 #endif
4340 }
4341
4342 #ifdef _WIN32
4343 static Sys_var_uint Sys_threadpool_min_threads(
4344 "thread_pool_min_threads",
4345 "Minimum number of threads in the thread pool.",
4346 GLOBAL_VAR(threadpool_min_threads), CMD_LINE(REQUIRED_ARG),
4347 VALID_RANGE(1, 256), DEFAULT(1), BLOCK_SIZE(1),
4348 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
4349 ON_UPDATE(fix_tp_min_threads)
4350 );
4351 #else
4352 static Sys_var_uint Sys_threadpool_idle_thread_timeout(
4353 "thread_pool_idle_timeout",
4354 "Timeout in seconds for an idle thread in the thread pool."
4355 "Worker thread will be shut down after timeout",
4356 GLOBAL_VAR(threadpool_idle_timeout), CMD_LINE(REQUIRED_ARG),
4357 VALID_RANGE(1, UINT_MAX), DEFAULT(60), BLOCK_SIZE(1)
4358 );
4359 static Sys_var_uint Sys_threadpool_oversubscribe(
4360 "thread_pool_oversubscribe",
4361 "How many additional active worker threads in a group are allowed.",
4362 GLOBAL_VAR(threadpool_oversubscribe), CMD_LINE(REQUIRED_ARG),
4363 VALID_RANGE(1, 1000), DEFAULT(3), BLOCK_SIZE(1)
4364 );
4365 static Sys_var_uint Sys_threadpool_size(
4366 "thread_pool_size",
4367 "Number of thread groups in the pool. "
4368 "This parameter is roughly equivalent to maximum number of concurrently "
4369 "executing threads (threads in a waiting state do not count as executing).",
4370 GLOBAL_VAR(threadpool_size), CMD_LINE(REQUIRED_ARG),
4371 VALID_RANGE(1, MAX_THREAD_GROUPS), DEFAULT(my_getncpus()), BLOCK_SIZE(1),
4372 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
4373 ON_UPDATE(fix_threadpool_size)
4374 );
4375 static Sys_var_uint Sys_threadpool_stall_limit(
4376 "thread_pool_stall_limit",
4377 "Maximum query execution time in milliseconds,"
4378 "before an executing non-yielding thread is considered stalled."
4379 "If a worker thread is stalled, additional worker thread "
4380 "may be created to handle remaining clients.",
4381 GLOBAL_VAR(threadpool_stall_limit), CMD_LINE(REQUIRED_ARG),
4382 VALID_RANGE(10, UINT_MAX), DEFAULT(500), BLOCK_SIZE(1),
4383 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
4384 ON_UPDATE(fix_threadpool_stall_limit)
4385 );
4386 static Sys_var_uint Sys_threadpool_high_prio_tickets(
4387 "thread_pool_high_prio_tickets",
4388 "Number of tickets to enter the high priority event queue for each "
4389 "transaction.",
4390 SESSION_VAR(threadpool_high_prio_tickets), CMD_LINE(REQUIRED_ARG),
4391 VALID_RANGE(0, UINT_MAX), DEFAULT(UINT_MAX), BLOCK_SIZE(1)
4392 );
4393
4394 static Sys_var_enum Sys_threadpool_high_prio_mode(
4395 "thread_pool_high_prio_mode",
4396 "High priority queue mode: one of 'transactions', 'statements' or 'none'. "
4397 "In the 'transactions' mode the thread pool uses both high- and low-priority "
4398 "queues depending on whether an event is generated by an already started "
4399 "transaction or a connection holding a MDL, table, user, or a global read "
4400 "or backup lock and whether it has any high priority tickets (see "
4401 "thread_pool_high_prio_tickets). In the 'statements' mode all events (i.e. "
4402 "individual statements) always go to the high priority queue, regardless of "
4403 "the current transaction and lock state and high priority tickets. "
4404 "'none' is the opposite of 'statements', i.e. disables the high priority queue "
4405 "completely.",
4406 SESSION_VAR(threadpool_high_prio_mode), CMD_LINE(REQUIRED_ARG),
4407 threadpool_high_prio_mode_names, DEFAULT(TP_HIGH_PRIO_MODE_TRANSACTIONS));
4408
4409 #endif /* !WIN32 */
4410 static Sys_var_uint Sys_threadpool_max_threads(
4411 "thread_pool_max_threads",
4412 "Maximum allowed number of worker threads in the thread pool",
4413 GLOBAL_VAR(threadpool_max_threads), CMD_LINE(REQUIRED_ARG),
4414 VALID_RANGE(1, MAX_CONNECTIONS), DEFAULT(MAX_CONNECTIONS), BLOCK_SIZE(1),
4415 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
4416 ON_UPDATE(fix_tp_max_threads)
4417 );
4418 #endif /* HAVE_POOL_OF_THREADS */
4419
4420 /**
4421 Function to check if the 'next' transaction isolation level
4422 ('tx_isolation'/ its alternative 'transaction_isolation')
4423 can be changed.
4424
4425 @param[in] self A pointer to the sys_var.
4426 @param[in] thd Thread handler.
4427 @param[in] var A pointer to set_var holding the specified list of
4428 system variable names.
4429
4430 @retval FALSE Success.
4431 @retval TRUE Error.
4432 */
check_transaction_isolation(sys_var * self,THD * thd,set_var * var)4433 static bool check_transaction_isolation(sys_var *self, THD *thd, set_var *var)
4434 {
4435 if (var->type == OPT_DEFAULT && (thd->in_active_multi_stmt_transaction() ||
4436 thd->in_sub_stmt))
4437 {
4438 assert(thd->in_multi_stmt_transaction_mode() || thd->in_sub_stmt);
4439 my_error(ER_CANT_CHANGE_TX_CHARACTERISTICS, MYF(0));
4440 return true;
4441 }
4442 return false;
4443 }
4444
4445
4446 /**
4447 This function sets the session variable thd->variables.tx_isolation/
4448 thd->variables.transaction_isolation to reflect changes
4449 to @@session.tx_isolation/@@session.transaction_isolation.
4450 'tx_isolation' is deprecated and 'transaction_isolation' is its
4451 alternative.
4452
4453 @param[in] thd Thread handler.
4454 @param[in] var A pointer to the set_var.
4455
4456 @retval FALSE Success.
4457 @retval TRUE Error.
4458 */
4459
session_update(THD * thd,set_var * var)4460 bool Sys_var_tx_isolation::session_update(THD *thd, set_var *var)
4461 {
4462 if (var->type == OPT_SESSION && Sys_var_enum::session_update(thd, var))
4463 return TRUE;
4464
4465 if (var->type == OPT_DEFAULT || !(thd->in_active_multi_stmt_transaction() ||
4466 thd->in_sub_stmt))
4467 {
4468 /*
4469 Update the isolation level of the next transaction.
4470 I.e. if one did:
4471 COMMIT;
4472 SET SESSION ISOLATION LEVEL ...
4473 BEGIN; <-- this transaction has the new isolation
4474 Note, that in case of:
4475 COMMIT;
4476 SET TRANSACTION ISOLATION LEVEL ...
4477 SET SESSION ISOLATION LEVEL ...
4478 BEGIN; <-- the session isolation level is used, not the
4479 result of SET TRANSACTION statement.
4480
4481 When we are in a trigger/function the transaction is already
4482 started. Adhering to above behavior, the SET TRANSACTION would
4483 fail when run from within trigger/function. And SET SESSION
4484 TRANSACTION would always succeed making the characteristics
4485 effective for the next transaction that starts.
4486 */
4487 enum_tx_isolation tx_isol;
4488 tx_isol= (enum_tx_isolation) var->save_result.ulonglong_value;
4489 bool one_shot= (var->type == OPT_DEFAULT);
4490 return set_tx_isolation(thd, tx_isol, one_shot);
4491 }
4492 return FALSE;
4493 }
4494
4495
4496 /**
4497 This function updates the thd->variables.transaction_isolation
4498 to reflect the changes made to @@session.tx_isolation. 'tx_isolation' is
4499 deprecated and 'transaction_isolation' is its alternative.
4500
4501 @param[in] self A pointer to the sys_var.
4502 @param[in] thd Thread handler.
4503 @param[in] type The type SESSION, GLOBAL or DEFAULT.
4504
4505 @retval FALSE Success.
4506 @retval TRUE Error.
4507 */
update_transaction_isolation(sys_var * self,THD * thd,enum_var_type type)4508 static bool update_transaction_isolation(sys_var *self, THD *thd,
4509 enum_var_type type)
4510 {
4511 SV *sv= type == OPT_GLOBAL ? &global_system_variables : &thd->variables;
4512 sv->transaction_isolation= sv->tx_isolation;
4513 return false;
4514 }
4515
4516
4517 /**
4518 This function updates thd->variables.tx_isolation to reflect the
4519 changes to @@session.transaction_isolation. 'tx_isolation' is
4520 deprecated and 'transaction_isolation' is its alternative.
4521
4522 @param[in] self A pointer to the sys_var.
4523 @param[in] thd Thread handler.
4524 @param[in] type The type SESSION, GLOBAL or DEFAULT.
4525
4526 @retval FALSE Success.
4527 @retval TRUE Error.
4528 */
update_tx_isolation(sys_var * self,THD * thd,enum_var_type type)4529 static bool update_tx_isolation(sys_var *self, THD *thd,
4530 enum_var_type type)
4531 {
4532 SV *sv= type == OPT_GLOBAL ? &global_system_variables : &thd->variables;
4533 sv->tx_isolation= sv->transaction_isolation;
4534 return false;
4535 }
4536
4537
4538 // NO_CMD_LINE - different name of the option
4539 static Sys_var_tx_isolation Sys_tx_isolation(
4540 "tx_isolation", "Default transaction isolation level."
4541 "This variable is deprecated and will be removed in a future release.",
4542 UNTRACKED_DEFAULT SESSION_VAR(tx_isolation), NO_CMD_LINE,
4543 tx_isolation_names, DEFAULT(ISO_REPEATABLE_READ),
4544 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_transaction_isolation),
4545 ON_UPDATE(update_transaction_isolation),
4546 DEPRECATED_VAR("'@@transaction_isolation'"));
4547
4548
4549 // NO_CMD_LINE
4550 static Sys_var_tx_isolation Sys_transaction_isolation(
4551 "transaction_isolation", "Default transaction isolation level",
4552 UNTRACKED_DEFAULT SESSION_VAR(transaction_isolation), NO_CMD_LINE,
4553 tx_isolation_names, DEFAULT(ISO_REPEATABLE_READ),
4554 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_transaction_isolation),
4555 ON_UPDATE(update_tx_isolation));
4556
4557
4558 /**
4559 Function to check if the state of deprecated variable 'tx_read_only'/
4560 its alternative 'transaction_read_only' can be changed. The state cannot
4561 be changed if there is already a transaction in progress.
4562
4563 @param[in] self A pointer to the sys_var.
4564 @param[in] thd Thread handler
4565 @param[in] var A pointer to set_var holding the specified list of
4566 system variable names.
4567
4568 @retval FALSE Success.
4569 @retval TRUE Error.
4570 */
4571
check_transaction_read_only(sys_var * self,THD * thd,set_var * var)4572 static bool check_transaction_read_only(sys_var *self, THD *thd, set_var *var)
4573 {
4574 if (var->type == OPT_DEFAULT && (thd->in_active_multi_stmt_transaction() ||
4575 thd->in_sub_stmt))
4576 {
4577 assert(thd->in_multi_stmt_transaction_mode() || thd->in_sub_stmt);
4578 my_error(ER_CANT_CHANGE_TX_CHARACTERISTICS, MYF(0));
4579 return true;
4580 }
4581 return false;
4582 }
4583
4584
4585 /**
4586 This function sets the session variable thd->variables.tx_read_only/
4587 thd->variables.transaction_read_only to reflect changes to
4588 @@session.tx_read_only/@@session.transaction_read_only. 'tx_read_only'
4589 is deprecated and 'transaction_read_only' is its alternative.
4590
4591 @param[in] thd Thread handler.
4592 @param[in] var A pointer to the set_var.
4593
4594 @retval FALSE Success.
4595 */
session_update(THD * thd,set_var * var)4596 bool Sys_var_tx_read_only::session_update(THD *thd, set_var *var)
4597 {
4598 if (var->type == OPT_SESSION && Sys_var_mybool::session_update(thd, var))
4599 return true;
4600
4601 if (var->type == OPT_DEFAULT || !(thd->in_active_multi_stmt_transaction() ||
4602 thd->in_sub_stmt))
4603 {
4604 // @see Sys_var_tx_isolation::session_update() above for the rules.
4605 thd->tx_read_only= var->save_result.ulonglong_value;
4606
4607 if (thd->variables.session_track_transaction_info > TX_TRACK_NONE)
4608 {
4609 Transaction_state_tracker *tst= (Transaction_state_tracker *)
4610 thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER);
4611
4612 if (var->type == OPT_DEFAULT)
4613 tst->set_read_flags(thd,
4614 thd->tx_read_only ? TX_READ_ONLY : TX_READ_WRITE);
4615 else
4616 tst->set_read_flags(thd, TX_READ_INHERIT);
4617 }
4618 }
4619 return false;
4620 }
4621
4622
4623 /**
4624 This function updates the session variable thd->variables.tx_read_only
4625 to reflect changes made to @@session.transaction_read_only. The variable
4626 'tx_read_only' is deprecated and 'transaction_read_only' is its alternative.
4627
4628 @param[in] self A pointer to the sys_var.
4629 @param[in] thd Thread handler.
4630 @param[in] type The type SESSION, GLOBAL or DEFAULT.
4631
4632 @retval FALSE Success.
4633 */
update_tx_read_only(sys_var * self,THD * thd,enum_var_type type)4634 static bool update_tx_read_only(sys_var *self, THD *thd,
4635 enum_var_type type)
4636 {
4637 SV *sv= type == OPT_GLOBAL ? &global_system_variables : &thd->variables;
4638 sv->tx_read_only= sv->transaction_read_only;
4639 return false;
4640 }
4641
4642
4643 /**
4644 This function updates the session variable
4645 thd->variables.transaction_read_only to reflect changes made to
4646 @@session.tx_read_only. 'tx_read_only' is deprecated and
4647 'transaction_read_only' is its alternative.
4648
4649 @param[in] self A pointer to the sys_var.
4650 @param[in] thd Thread handler.
4651 @param[in] type The type SESSION, GLOBAL or DEFAULT.
4652
4653 @retval FALSE Success.
4654 */
update_transaction_read_only(sys_var * self,THD * thd,enum_var_type type)4655 static bool update_transaction_read_only(sys_var *self, THD *thd,
4656 enum_var_type type)
4657 {
4658 SV *sv= type == OPT_GLOBAL ? &global_system_variables : &thd->variables;
4659 sv->transaction_read_only= sv->tx_read_only;
4660 return false;
4661 }
4662
4663
4664 static Sys_var_tx_read_only Sys_tx_read_only(
4665 "tx_read_only", "Set default transaction access mode to read only."
4666 "This variable is deprecated and will be removed in a future release.",
4667 UNTRACKED_DEFAULT SESSION_VAR(tx_read_only), NO_CMD_LINE, DEFAULT(0),
4668 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_transaction_read_only),
4669 ON_UPDATE(update_transaction_read_only),
4670 DEPRECATED_VAR("'@@transaction_read_only'"));
4671
4672
4673 static Sys_var_tx_read_only Sys_transaction_read_only(
4674 "transaction_read_only",
4675 "Set default transaction access mode to read only.",
4676 UNTRACKED_DEFAULT SESSION_VAR(transaction_read_only), NO_CMD_LINE,
4677 DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG,
4678 ON_CHECK(check_transaction_read_only),
4679 ON_UPDATE(update_tx_read_only));
4680
4681
4682 static Sys_var_ulonglong Sys_tmp_table_size(
4683 "tmp_table_size",
4684 "If an internal in-memory temporary table exceeds this size, MySQL "
4685 "will automatically convert it to an on-disk MyISAM table",
4686 SESSION_VAR(tmp_table_size), CMD_LINE(REQUIRED_ARG),
4687 VALID_RANGE(1024, (ulonglong)~(intptr)0), DEFAULT(16*1024*1024),
4688 BLOCK_SIZE(1));
4689
4690 static char *server_version_ptr;
4691 static Sys_var_version Sys_version(
4692 "version", "Server version",
4693 READ_ONLY GLOBAL_VAR(server_version_ptr), NO_CMD_LINE,
4694 IN_SYSTEM_CHARSET, DEFAULT(MYSQL_SERVER_VERSION));
4695
4696 static char *server_version_suffix_ptr;
4697 static Sys_var_charptr Sys_version_suffix(
4698 "version_suffix", "version_suffix",
4699 GLOBAL_VAR(server_version_suffix_ptr), CMD_LINE(REQUIRED_ARG),
4700 IN_SYSTEM_CHARSET, DEFAULT(server_version_suffix));
4701
4702 static char *server_version_comment_ptr;
4703 static Sys_var_charptr Sys_version_comment(
4704 "version_comment", "version_comment",
4705 GLOBAL_VAR(server_version_comment_ptr), NO_CMD_LINE,
4706 IN_SYSTEM_CHARSET, DEFAULT(MYSQL_COMPILATION_COMMENT));
4707
4708 static char *server_version_compile_machine_ptr;
4709 static Sys_var_charptr Sys_version_compile_machine(
4710 "version_compile_machine", "version_compile_machine",
4711 READ_ONLY GLOBAL_VAR(server_version_compile_machine_ptr), NO_CMD_LINE,
4712 IN_SYSTEM_CHARSET, DEFAULT(MACHINE_TYPE));
4713
4714 static char *server_version_compile_os_ptr;
4715 static Sys_var_charptr Sys_version_compile_os(
4716 "version_compile_os", "version_compile_os",
4717 READ_ONLY GLOBAL_VAR(server_version_compile_os_ptr), NO_CMD_LINE,
4718 IN_SYSTEM_CHARSET, DEFAULT(SYSTEM_TYPE));
4719
4720 static Sys_var_ulong Sys_net_wait_timeout(
4721 "wait_timeout",
4722 "The number of seconds the server waits for activity on a "
4723 "connection before closing it",
4724 SESSION_VAR(net_wait_timeout), CMD_LINE(REQUIRED_ARG),
4725 VALID_RANGE(1, INT_MAX32/1000),
4726 DEFAULT(NET_WAIT_TIMEOUT), BLOCK_SIZE(1));
4727
4728 static Sys_var_plugin Sys_default_storage_engine(
4729 "default_storage_engine", "The default storage engine for new tables",
4730 SESSION_VAR(table_plugin), NO_CMD_LINE,
4731 MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_storage_engine),
4732 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_storage_engine));
4733
4734 const char *internal_tmp_disk_storage_engine_names[] = { "MyISAM", "InnoDB", 0};
4735 static Sys_var_enum Sys_internal_tmp_disk_storage_engine(
4736 "internal_tmp_disk_storage_engine",
4737 "The default storage engine for on-disk internal tmp table",
4738 GLOBAL_VAR(internal_tmp_disk_storage_engine), CMD_LINE(OPT_ARG),
4739 internal_tmp_disk_storage_engine_names, DEFAULT(TMP_TABLE_INNODB));
4740
4741 static Sys_var_plugin Sys_default_tmp_storage_engine(
4742 "default_tmp_storage_engine", "The default storage engine for new explicit temporary tables",
4743 SESSION_VAR(temp_table_plugin), NO_CMD_LINE,
4744 MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_tmp_storage_engine),
4745 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_storage_engine));
4746
4747 static Sys_var_charptr Sys_enforce_storage_engine(
4748 "enforce_storage_engine", "Force the use of a storage engine for new "
4749 "tables",
4750 READ_ONLY GLOBAL_VAR(enforce_storage_engine),
4751 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
4752 DEFAULT(0));
4753
4754 #if defined(ENABLED_DEBUG_SYNC)
4755 /*
4756 Variable can be set for the session only.
4757
4758 This could be changed later. Then we need to have a global array of
4759 actions in addition to the thread local ones. SET GLOBAL would
4760 manage the global array, SET [SESSION] the local array. A sync point
4761 would need to look for a local and a global action. Setting and
4762 executing of global actions need to be protected by a mutex.
4763
4764 The purpose of global actions could be to allow synchronizing with
4765 connectionless threads that cannot execute SET statements.
4766 */
4767 static Sys_var_debug_sync Sys_debug_sync(
4768 "debug_sync", "Debug Sync Facility",
4769 sys_var::ONLY_SESSION, NO_CMD_LINE,
4770 DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_has_super));
4771 #endif /* defined(ENABLED_DEBUG_SYNC) */
4772
4773 /**
4774 "time_format" "date_format" "datetime_format"
4775
4776 the following three variables are unused, and the source of confusion
4777 (bug reports like "I've changed date_format, but date format hasn't changed.
4778 I've made them read-only, to alleviate the situation somewhat.
4779
4780 @todo make them NO_CMD_LINE ?
4781 */
4782 static Sys_var_charptr Sys_date_format(
4783 "date_format", "The DATE format (ignored)",
4784 READ_ONLY GLOBAL_VAR(global_date_format.format.str),
4785 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
4786 DEFAULT(known_date_time_formats[ISO_FORMAT].date_format),
4787 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
4788 DEPRECATED_VAR(""));
4789
4790 static Sys_var_charptr Sys_datetime_format(
4791 "datetime_format", "The DATETIME format (ignored)",
4792 READ_ONLY GLOBAL_VAR(global_datetime_format.format.str),
4793 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
4794 DEFAULT(known_date_time_formats[ISO_FORMAT].datetime_format),
4795 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
4796 DEPRECATED_VAR(""));
4797
4798 static Sys_var_charptr Sys_time_format(
4799 "time_format", "The TIME format (ignored)",
4800 READ_ONLY GLOBAL_VAR(global_time_format.format.str),
4801 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
4802 DEFAULT(known_date_time_formats[ISO_FORMAT].time_format),
4803 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
4804 DEPRECATED_VAR(""));
4805
4806 /**
4807 Pre-update function to commit connection's active transactions when autocommit
4808 is enabled.
4809
4810 @note This hook relies on the fact that it is called while not holding any
4811 locks. Breaking this assumption might result in deadlocks as commit
4812 acquires many different locks in its process (e.g. to open GTID-related
4813 tables).
4814
4815 @param[in] self A pointer to the sys_var, i.e. Sys_autocommit.
4816 @param[in] thd A reference to THD object.
4817 @param[in] var A pointer to the set_var created by the parser.
4818
4819 @retval true Error during commit
4820 @retval false Otherwise
4821 */
pre_autocommit(sys_var * self,THD * thd,set_var * var)4822 static bool pre_autocommit(sys_var *self, THD *thd, set_var *var)
4823 {
4824 if (!(var->type == OPT_GLOBAL) &&
4825 (thd->variables.option_bits & OPTION_NOT_AUTOCOMMIT) &&
4826 var->save_result.ulonglong_value)
4827 {
4828 // Autocommit mode is about to be activated.
4829 if (trans_commit_stmt(thd) || trans_commit(thd))
4830 return true;
4831 }
4832 return false;
4833 }
4834
fix_autocommit(sys_var * self,THD * thd,enum_var_type type)4835 static bool fix_autocommit(sys_var *self, THD *thd, enum_var_type type)
4836 {
4837 if (type == OPT_GLOBAL)
4838 {
4839 if (global_system_variables.option_bits & OPTION_AUTOCOMMIT)
4840 global_system_variables.option_bits&= ~OPTION_NOT_AUTOCOMMIT;
4841 else
4842 global_system_variables.option_bits|= OPTION_NOT_AUTOCOMMIT;
4843 return false;
4844 }
4845
4846 if (thd->variables.option_bits & OPTION_AUTOCOMMIT &&
4847 thd->variables.option_bits & OPTION_NOT_AUTOCOMMIT)
4848 { // activating autocommit
4849 /*
4850 Don't close thread tables or release metadata locks: if we do so, we
4851 risk releasing locks/closing tables of expressions used to assign
4852 other variables, as in:
4853 set @var=my_stored_function1(), @@autocommit=1, @var2=(select max(a)
4854 from my_table), ...
4855 The locks will be released at statement end anyway, as SET
4856 statement that assigns autocommit is marked to commit
4857 transaction implicitly at the end (@sa stmt_causes_implicitcommit()).
4858 */
4859 thd->variables.option_bits&=
4860 ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
4861 thd->get_transaction()->reset_unsafe_rollback_flags(
4862 Transaction_ctx::SESSION);
4863 thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
4864 return false;
4865 }
4866
4867 if (!(thd->variables.option_bits & OPTION_AUTOCOMMIT) &&
4868 !(thd->variables.option_bits & OPTION_NOT_AUTOCOMMIT))
4869 { // disabling autocommit
4870
4871 thd->get_transaction()->reset_unsafe_rollback_flags(
4872 Transaction_ctx::SESSION);
4873 thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
4874 thd->variables.option_bits|= OPTION_NOT_AUTOCOMMIT;
4875 return false;
4876 }
4877
4878 return false; // autocommit value wasn't changed
4879 }
4880 static Sys_var_bit Sys_autocommit(
4881 "autocommit", "autocommit",
4882 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_AUTOCOMMIT, DEFAULT(TRUE),
4883 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
4884 PRE_UPDATE(pre_autocommit), ON_UPDATE(fix_autocommit));
4885 export sys_var *Sys_autocommit_ptr= &Sys_autocommit; // for sql_yacc.yy
4886
4887 static Sys_var_mybool Sys_big_tables(
4888 "big_tables", "Allow big result sets by saving all "
4889 "temporary sets on file (Solves most 'table full' errors)",
4890 SESSION_VAR(big_tables), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
4891
4892 static Sys_var_bit Sys_big_selects(
4893 "sql_big_selects", "sql_big_selects",
4894 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_BIG_SELECTS,
4895 DEFAULT(FALSE));
4896
4897 static Sys_var_bit Sys_log_off(
4898 "sql_log_off", "sql_log_off",
4899 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_LOG_OFF,
4900 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_has_super));
4901
4902 /**
4903 This function sets the session variable thd->variables.sql_log_bin
4904 to reflect changes to @@session.sql_log_bin.
4905
4906 @param[in] self A pointer to the sys_var, i.e. Sys_log_binlog.
4907 @param[in] type The type either session or global.
4908
4909 @return @c FALSE.
4910 */
fix_sql_log_bin_after_update(sys_var * self,THD * thd,enum_var_type type)4911 static bool fix_sql_log_bin_after_update(sys_var *self, THD *thd,
4912 enum_var_type type)
4913 {
4914 assert(type == OPT_SESSION);
4915
4916 if (thd->variables.sql_log_bin)
4917 thd->variables.option_bits |= OPTION_BIN_LOG;
4918 else
4919 thd->variables.option_bits &= ~OPTION_BIN_LOG;
4920
4921 return FALSE;
4922 }
4923
4924 /**
4925 This function checks if the sql_log_bin can be changed,
4926 what is possible if:
4927 - the user is a super user;
4928 - the set is not called from within a function/trigger;
4929 - there is no on-going transaction.
4930
4931 @param[in] self A pointer to the sys_var, i.e. Sys_log_binlog.
4932 @param[in] var A pointer to the set_var created by the parser.
4933
4934 @return @c FALSE if the change is allowed, otherwise @c TRUE.
4935 */
check_sql_log_bin(sys_var * self,THD * thd,set_var * var)4936 static bool check_sql_log_bin(sys_var *self, THD *thd, set_var *var)
4937 {
4938 if (check_has_super(self, thd, var))
4939 return TRUE;
4940
4941 if (var->type == OPT_GLOBAL)
4942 return TRUE;
4943
4944 /* If in a stored function/trigger, it's too late to change sql_log_bin. */
4945 if (thd->in_sub_stmt)
4946 {
4947 my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN, MYF(0));
4948 return TRUE;
4949 }
4950 /* Make the session variable 'sql_log_bin' read-only inside a transaction. */
4951 if (thd->in_active_multi_stmt_transaction())
4952 {
4953 my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SQL_LOG_BIN, MYF(0));
4954 return TRUE;
4955 }
4956
4957 return FALSE;
4958 }
4959
4960 static Sys_var_sql_log_bin Sys_log_binlog(
4961 "sql_log_bin", "Controls whether logging to the binary log is done",
4962 SESSION_VAR(sql_log_bin), NO_CMD_LINE, DEFAULT(TRUE),
4963 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_sql_log_bin),
4964 ON_UPDATE(fix_sql_log_bin_after_update));
4965
4966 static Sys_var_bit Sys_transaction_allow_batching(
4967 "transaction_allow_batching", "transaction_allow_batching",
4968 SESSION_ONLY(option_bits), NO_CMD_LINE, OPTION_ALLOW_BATCH,
4969 DEFAULT(FALSE));
4970
4971 static Sys_var_bit Sys_sql_warnings(
4972 "sql_warnings", "sql_warnings",
4973 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_WARNINGS,
4974 DEFAULT(FALSE));
4975
4976 static Sys_var_bit Sys_sql_notes(
4977 "sql_notes", "sql_notes",
4978 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_SQL_NOTES,
4979 DEFAULT(TRUE));
4980
4981 static Sys_var_bit Sys_auto_is_null(
4982 "sql_auto_is_null", "sql_auto_is_null",
4983 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_AUTO_IS_NULL,
4984 DEFAULT(FALSE), NO_MUTEX_GUARD, IN_BINLOG);
4985
4986 static Sys_var_bit Sys_safe_updates(
4987 "sql_safe_updates", "sql_safe_updates",
4988 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_SAFE_UPDATES,
4989 DEFAULT(FALSE));
4990
4991 static Sys_var_bit Sys_buffer_results(
4992 "sql_buffer_result", "sql_buffer_result",
4993 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_BUFFER_RESULT,
4994 DEFAULT(FALSE));
4995
4996 static Sys_var_bit Sys_quote_show_create(
4997 "sql_quote_show_create", "sql_quote_show_create",
4998 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_QUOTE_SHOW_CREATE,
4999 DEFAULT(TRUE));
5000
5001 static Sys_var_bit Sys_foreign_key_checks(
5002 "foreign_key_checks", "foreign_key_checks",
5003 SESSION_VAR(option_bits), NO_CMD_LINE,
5004 REVERSE(OPTION_NO_FOREIGN_KEY_CHECKS),
5005 DEFAULT(TRUE), NO_MUTEX_GUARD, IN_BINLOG);
5006
5007 static Sys_var_bit Sys_unique_checks(
5008 "unique_checks", "unique_checks",
5009 SESSION_VAR(option_bits), NO_CMD_LINE,
5010 REVERSE(OPTION_RELAXED_UNIQUE_CHECKS),
5011 DEFAULT(TRUE), NO_MUTEX_GUARD, IN_BINLOG);
5012
5013 #ifdef ENABLED_PROFILING
5014 static Sys_var_bit Sys_profiling(
5015 "profiling", "profiling",
5016 SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_PROFILING,
5017 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
5018 PRE_UPDATE(0), ON_UPDATE(0), DEPRECATED_VAR(""));
5019
5020 static Sys_var_ulong Sys_profiling_history_size(
5021 "profiling_history_size", "Limit of query profiling memory",
5022 SESSION_VAR(profiling_history_size), CMD_LINE(REQUIRED_ARG),
5023 VALID_RANGE(0, 100), DEFAULT(15), BLOCK_SIZE(1), NO_MUTEX_GUARD,
5024 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED_VAR(""));
5025 #endif
5026
5027 static Sys_var_harows Sys_select_limit(
5028 "sql_select_limit",
5029 "The maximum number of rows to return from SELECT statements",
5030 SESSION_VAR(select_limit), NO_CMD_LINE,
5031 VALID_RANGE(0, HA_POS_ERROR), DEFAULT(HA_POS_ERROR), BLOCK_SIZE(1));
5032
update_timestamp(THD * thd,set_var * var)5033 static bool update_timestamp(THD *thd, set_var *var)
5034 {
5035 if (var->value)
5036 {
5037 double fl= floor(var->save_result.double_value); // Truncate integer part
5038 struct timeval tmp;
5039 tmp.tv_sec= static_cast<long>(fl);
5040 /* Round nanoseconds to nearest microsecond */
5041 tmp.tv_usec=
5042 static_cast<long>(rint((var->save_result.double_value - fl) * 1000000));
5043 thd->set_time(&tmp);
5044 }
5045 else // SET timestamp=DEFAULT
5046 {
5047 thd->user_time.tv_sec= 0;
5048 thd->user_time.tv_usec= 0;
5049 }
5050 return false;
5051 }
read_timestamp(THD * thd)5052 static double read_timestamp(THD *thd)
5053 {
5054 return (double) thd->start_time.tv_sec +
5055 (double) thd->start_time.tv_usec / 1000000;
5056 }
5057
5058
check_timestamp(sys_var * self,THD * thd,set_var * var)5059 static bool check_timestamp(sys_var *self, THD *thd, set_var *var)
5060 {
5061 double val;
5062
5063 if (!var->value)
5064 return FALSE;
5065
5066 val= var->save_result.double_value;
5067 if (val != 0 && // this is how you set the default value
5068 (val < TIMESTAMP_MIN_VALUE || val > TIMESTAMP_MAX_VALUE))
5069 {
5070 ErrConvString prm(val);
5071 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "timestamp", prm.ptr());
5072 return TRUE;
5073 }
5074 return FALSE;
5075 }
5076
5077
5078 static Sys_var_session_special_double Sys_timestamp(
5079 "timestamp", "Set the time for this client",
5080 sys_var::ONLY_SESSION, NO_CMD_LINE,
5081 VALID_RANGE(0, 0), BLOCK_SIZE(1),
5082 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_timestamp),
5083 ON_UPDATE(update_timestamp), ON_READ(read_timestamp));
5084
update_last_insert_id(THD * thd,set_var * var)5085 static bool update_last_insert_id(THD *thd, set_var *var)
5086 {
5087 if (!var->value)
5088 {
5089 my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
5090 return true;
5091 }
5092 thd->first_successful_insert_id_in_prev_stmt=
5093 var->save_result.ulonglong_value;
5094 thd->substitute_null_with_insert_id= TRUE;
5095 return false;
5096 }
read_last_insert_id(THD * thd)5097 static ulonglong read_last_insert_id(THD *thd)
5098 {
5099 return thd->read_first_successful_insert_id_in_prev_stmt();
5100 }
5101 static Sys_var_session_special Sys_last_insert_id(
5102 "last_insert_id", "The value to be returned from LAST_INSERT_ID()",
5103 sys_var::ONLY_SESSION, NO_CMD_LINE,
5104 VALID_RANGE(0, ULLONG_MAX), BLOCK_SIZE(1),
5105 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
5106 ON_UPDATE(update_last_insert_id), ON_READ(read_last_insert_id));
5107
5108 // alias for last_insert_id(), Sybase-style
5109 static Sys_var_session_special Sys_identity(
5110 "identity", "Synonym for the last_insert_id variable",
5111 sys_var::ONLY_SESSION, NO_CMD_LINE,
5112 VALID_RANGE(0, ULLONG_MAX), BLOCK_SIZE(1),
5113 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
5114 ON_UPDATE(update_last_insert_id), ON_READ(read_last_insert_id));
5115
5116 /*
5117 insert_id should *not* be marked as written to the binlog (i.e., it
5118 should *not* be IN_BINLOG), because we want any statement that
5119 refers to insert_id explicitly to be unsafe. (By "explicitly", we
5120 mean using @@session.insert_id, whereas insert_id is used
5121 "implicitly" when NULL value is inserted into an auto_increment
5122 column).
5123
5124 We want statements referring explicitly to @@session.insert_id to be
5125 unsafe, because insert_id is modified internally by the slave sql
5126 thread when NULL values are inserted in an AUTO_INCREMENT column.
5127 This modification interfers with the value of the
5128 @@session.insert_id variable if @@session.insert_id is referred
5129 explicitly by an insert statement (as is seen by executing "SET
5130 @@session.insert_id=0; CREATE TABLE t (a INT, b INT KEY
5131 AUTO_INCREMENT); INSERT INTO t(a) VALUES (@@session.insert_id);" in
5132 statement-based logging mode: t will be different on master and
5133 slave).
5134 */
update_insert_id(THD * thd,set_var * var)5135 static bool update_insert_id(THD *thd, set_var *var)
5136 {
5137 if (!var->value)
5138 {
5139 my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
5140 return true;
5141 }
5142 thd->force_one_auto_inc_interval(var->save_result.ulonglong_value);
5143 return false;
5144 }
5145
read_insert_id(THD * thd)5146 static ulonglong read_insert_id(THD *thd)
5147 {
5148 return thd->auto_inc_intervals_forced.minimum();
5149 }
5150 static Sys_var_session_special Sys_insert_id(
5151 "insert_id", "The value to be used by the following INSERT "
5152 "or ALTER TABLE statement when inserting an AUTO_INCREMENT value",
5153 sys_var::ONLY_SESSION, NO_CMD_LINE,
5154 VALID_RANGE(0, ULLONG_MAX), BLOCK_SIZE(1),
5155 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
5156 ON_UPDATE(update_insert_id), ON_READ(read_insert_id));
5157
update_rand_seed1(THD * thd,set_var * var)5158 static bool update_rand_seed1(THD *thd, set_var *var)
5159 {
5160 if (!var->value)
5161 {
5162 my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
5163 return true;
5164 }
5165 thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
5166 return false;
5167 }
read_rand_seed(THD * thd)5168 static ulonglong read_rand_seed(THD *thd)
5169 {
5170 return 0;
5171 }
5172 static Sys_var_session_special Sys_rand_seed1(
5173 "rand_seed1", "Sets the internal state of the RAND() "
5174 "generator for replication purposes",
5175 sys_var::ONLY_SESSION, NO_CMD_LINE,
5176 VALID_RANGE(0, ULONG_MAX), BLOCK_SIZE(1),
5177 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
5178 ON_UPDATE(update_rand_seed1), ON_READ(read_rand_seed));
5179
update_rand_seed2(THD * thd,set_var * var)5180 static bool update_rand_seed2(THD *thd, set_var *var)
5181 {
5182 if (!var->value)
5183 {
5184 my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
5185 return true;
5186 }
5187 thd->rand.seed2= (ulong) var->save_result.ulonglong_value;
5188 return false;
5189 }
5190 static Sys_var_session_special Sys_rand_seed2(
5191 "rand_seed2", "Sets the internal state of the RAND() "
5192 "generator for replication purposes",
5193 sys_var::ONLY_SESSION, NO_CMD_LINE,
5194 VALID_RANGE(0, ULONG_MAX), BLOCK_SIZE(1),
5195 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
5196 ON_UPDATE(update_rand_seed2), ON_READ(read_rand_seed));
5197
read_error_count(THD * thd)5198 static ulonglong read_error_count(THD *thd)
5199 {
5200 return thd->get_stmt_da()->error_count(thd);
5201 }
5202 // this really belongs to the SHOW STATUS
5203 static Sys_var_session_special Sys_error_count(
5204 "error_count", "The number of errors that resulted from the "
5205 "last statement that generated messages",
5206 READ_ONLY sys_var::ONLY_SESSION, NO_CMD_LINE,
5207 VALID_RANGE(0, ULLONG_MAX), BLOCK_SIZE(1), NO_MUTEX_GUARD,
5208 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), ON_READ(read_error_count));
5209
read_warning_count(THD * thd)5210 static ulonglong read_warning_count(THD *thd)
5211 {
5212 return thd->get_stmt_da()->warn_count(thd);
5213 }
5214 // this really belongs to the SHOW STATUS
5215 static Sys_var_session_special Sys_warning_count(
5216 "warning_count", "The number of errors, warnings, and notes "
5217 "that resulted from the last statement that generated messages",
5218 READ_ONLY sys_var::ONLY_SESSION, NO_CMD_LINE,
5219 VALID_RANGE(0, ULLONG_MAX), BLOCK_SIZE(1), NO_MUTEX_GUARD,
5220 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), ON_READ(read_warning_count));
5221
5222 static Sys_var_ulong Sys_default_week_format(
5223 "default_week_format",
5224 "The default week format used by WEEK() functions",
5225 SESSION_VAR(default_week_format), CMD_LINE(REQUIRED_ARG),
5226 VALID_RANGE(0, 7), DEFAULT(0), BLOCK_SIZE(1));
5227
5228 static Sys_var_ulong Sys_group_concat_max_len(
5229 "group_concat_max_len",
5230 "The maximum length of the result of function GROUP_CONCAT()",
5231 SESSION_VAR(group_concat_max_len), CMD_LINE(REQUIRED_ARG),
5232 VALID_RANGE(4, ULONG_MAX), DEFAULT(1024), BLOCK_SIZE(1));
5233
5234 static char *glob_hostname_ptr;
5235 static Sys_var_charptr Sys_hostname(
5236 "hostname", "Server host name",
5237 READ_ONLY GLOBAL_VAR(glob_hostname_ptr), NO_CMD_LINE,
5238 IN_FS_CHARSET, DEFAULT(glob_hostname));
5239
5240 #ifndef EMBEDDED_LIBRARY
5241 static Sys_var_charptr Sys_repl_report_host(
5242 "report_host",
5243 "Hostname or IP of the slave to be reported to the master during "
5244 "slave registration. Will appear in the output of SHOW SLAVE HOSTS. "
5245 "Leave unset if you do not want the slave to register itself with the "
5246 "master. Note that it is not sufficient for the master to simply read "
5247 "the IP of the slave off the socket once the slave connects. Due to "
5248 "NAT and other routing issues, that IP may not be valid for connecting "
5249 "to the slave from the master or other hosts",
5250 READ_ONLY GLOBAL_VAR(report_host), CMD_LINE(REQUIRED_ARG),
5251 IN_FS_CHARSET, DEFAULT(0));
5252
5253 static Sys_var_charptr Sys_repl_report_user(
5254 "report_user",
5255 "The account user name of the slave to be reported to the master "
5256 "during slave registration",
5257 READ_ONLY GLOBAL_VAR(report_user), CMD_LINE(REQUIRED_ARG),
5258 IN_FS_CHARSET, DEFAULT(0));
5259
5260 static Sys_var_charptr Sys_repl_report_password(
5261 "report_password",
5262 "The account password of the slave to be reported to the master "
5263 "during slave registration",
5264 READ_ONLY GLOBAL_VAR(report_password), CMD_LINE(REQUIRED_ARG),
5265 IN_FS_CHARSET, DEFAULT(0));
5266
5267 static Sys_var_uint Sys_repl_report_port(
5268 "report_port",
5269 "Port for connecting to slave reported to the master during slave "
5270 "registration. Set it only if the slave is listening on a non-default "
5271 "port or if you have a special tunnel from the master or other clients "
5272 "to the slave. If not sure, leave this option unset",
5273 READ_ONLY GLOBAL_VAR(report_port), CMD_LINE(REQUIRED_ARG),
5274 VALID_RANGE(0, 65535), DEFAULT(0), BLOCK_SIZE(1));
5275 #endif
5276
5277 static Sys_var_mybool Sys_keep_files_on_create(
5278 "keep_files_on_create",
5279 "Don't overwrite stale .MYD and .MYI even if no directory is specified",
5280 SESSION_VAR(keep_files_on_create), CMD_LINE(OPT_ARG),
5281 DEFAULT(FALSE));
5282
5283 static char *license;
5284 static Sys_var_charptr Sys_license(
5285 "license", "The type of license the server has",
5286 READ_ONLY GLOBAL_VAR(license), NO_CMD_LINE, IN_SYSTEM_CHARSET,
5287 DEFAULT(STRINGIFY_ARG(LICENSE)));
5288
check_log_path(sys_var * self,THD * thd,set_var * var)5289 static bool check_log_path(sys_var *self, THD *thd, set_var *var)
5290 {
5291 if (!var->value)
5292 return false; // DEFAULT is ok
5293
5294 if (!var->save_result.string_value.str)
5295 return true;
5296
5297 if (!is_valid_log_name(var->save_result.string_value.str,
5298 var->save_result.string_value.length))
5299 {
5300 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
5301 self->name.str, var->save_result.string_value.str);
5302 return true;
5303 }
5304
5305 if (var->save_result.string_value.length > FN_REFLEN)
5306 { // path is too long
5307 my_error(ER_PATH_LENGTH, MYF(0), self->name.str);
5308 return true;
5309 }
5310
5311 char path[FN_REFLEN];
5312 size_t path_length= unpack_filename(path, var->save_result.string_value.str);
5313
5314 if (!path_length)
5315 return true;
5316
5317 if (!is_filename_allowed(var->save_result.string_value.str,
5318 var->save_result.string_value.length, TRUE))
5319 {
5320 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
5321 self->name.str, var->save_result.string_value.str);
5322 return true;
5323 }
5324
5325 MY_STAT f_stat;
5326
5327 if (my_stat(path, &f_stat, MYF(0)))
5328 {
5329 if (!MY_S_ISREG(f_stat.st_mode) || !(f_stat.st_mode & MY_S_IWRITE))
5330 return true; // not a regular writable file
5331 return false;
5332 }
5333
5334 (void) dirname_part(path, var->save_result.string_value.str, &path_length);
5335
5336 if (var->save_result.string_value.length - path_length >= FN_LEN)
5337 { // filename is too long
5338 my_error(ER_PATH_LENGTH, MYF(0), self->name.str);
5339 return true;
5340 }
5341
5342 if (!path_length) // no path is good path (remember, relative to datadir)
5343 return false;
5344
5345 if (my_access(path, (F_OK|W_OK)))
5346 return true; // directory is not writable
5347
5348 return false;
5349 }
5350
5351
fix_general_log_file(sys_var * self,THD * thd,enum_var_type type)5352 static bool fix_general_log_file(sys_var *self, THD *thd, enum_var_type type)
5353 {
5354 bool res;
5355
5356 if (!opt_general_logname) // SET ... = DEFAULT
5357 {
5358 char buff[FN_REFLEN];
5359 opt_general_logname= my_strdup(key_memory_LOG_name,
5360 make_query_log_name(buff, QUERY_LOG_GENERAL),
5361 MYF(MY_FAE+MY_WME));
5362 if (!opt_general_logname)
5363 return true;
5364 }
5365
5366 res= query_logger.set_log_file(QUERY_LOG_GENERAL);
5367
5368 if (opt_general_log)
5369 {
5370 mysql_mutex_unlock(&LOCK_global_system_variables);
5371
5372 if (!res)
5373 res= query_logger.reopen_log_file(QUERY_LOG_GENERAL);
5374 else
5375 query_logger.deactivate_log_handler(QUERY_LOG_GENERAL);
5376
5377 mysql_mutex_lock(&LOCK_global_system_variables);
5378 }
5379
5380 if (res)
5381 opt_general_log= false;
5382
5383 return res;
5384 }
5385
5386 static Sys_var_charptr Sys_general_log_path(
5387 "general_log_file", "Log connections and queries to given file",
5388 GLOBAL_VAR(opt_general_logname), CMD_LINE(REQUIRED_ARG),
5389 IN_FS_CHARSET, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG,
5390 ON_CHECK(check_log_path), ON_UPDATE(fix_general_log_file));
5391
fix_slow_log_file(sys_var * self,THD * thd,enum_var_type type)5392 static bool fix_slow_log_file(sys_var *self, THD *thd, enum_var_type type)
5393 {
5394 bool res;
5395
5396 DEBUG_SYNC(thd, "log_fix_slow_log_holds_sysvar_lock");
5397
5398 if (!opt_slow_logname) // SET ... = DEFAULT
5399 {
5400 char buff[FN_REFLEN];
5401 opt_slow_logname= my_strdup(key_memory_LOG_name,
5402 make_query_log_name(buff, QUERY_LOG_SLOW),
5403 MYF(MY_FAE+MY_WME));
5404 if (!opt_slow_logname)
5405 return true;
5406 }
5407
5408 res= query_logger.set_log_file(QUERY_LOG_SLOW);
5409
5410 DEBUG_SYNC(thd, "log_fix_slow_log_released_logger_lock");
5411
5412 if (opt_slow_log)
5413 {
5414 mysql_mutex_unlock(&LOCK_global_system_variables);
5415
5416 DEBUG_SYNC(thd, "log_fix_slow_log_released_sysvar_lock");
5417
5418 if (!res)
5419 res= query_logger.reopen_log_file(QUERY_LOG_SLOW);
5420 else
5421 query_logger.deactivate_log_handler(QUERY_LOG_SLOW);
5422
5423 mysql_mutex_lock(&LOCK_global_system_variables);
5424 }
5425
5426 if (res)
5427 opt_slow_log= false;
5428
5429 return res;
5430 }
5431 static Sys_var_charptr Sys_slow_log_path(
5432 "slow_query_log_file", "Log slow queries to given log file. "
5433 "Defaults logging to hostname-slow.log. Must be enabled to activate "
5434 "other slow log options",
5435 GLOBAL_VAR(opt_slow_logname), CMD_LINE(REQUIRED_ARG),
5436 IN_FS_CHARSET, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG,
5437 ON_CHECK(check_log_path), ON_UPDATE(fix_slow_log_file));
5438
5439 static Sys_var_have Sys_have_compress(
5440 "have_compress", "have_compress",
5441 READ_ONLY GLOBAL_VAR(have_compress), NO_CMD_LINE);
5442
5443 static Sys_var_have Sys_have_crypt(
5444 "have_crypt", "have_crypt",
5445 READ_ONLY GLOBAL_VAR(have_crypt), NO_CMD_LINE);
5446
5447 static Sys_var_have Sys_have_dlopen(
5448 "have_dynamic_loading", "have_dynamic_loading",
5449 READ_ONLY GLOBAL_VAR(have_dlopen), NO_CMD_LINE);
5450
5451 static Sys_var_have Sys_have_geometry(
5452 "have_geometry", "have_geometry",
5453 READ_ONLY GLOBAL_VAR(have_geometry), NO_CMD_LINE);
5454
5455 static Sys_var_have Sys_have_openssl(
5456 "have_openssl", "have_openssl",
5457 READ_ONLY GLOBAL_VAR(have_ssl), NO_CMD_LINE);
5458
5459 static Sys_var_have Sys_have_profiling(
5460 "have_profiling", "have_profiling",
5461 READ_ONLY GLOBAL_VAR(have_profiling), NO_CMD_LINE, NO_MUTEX_GUARD,
5462 NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED_VAR(""));
5463
5464 static Sys_var_have Sys_have_backup_locks(
5465 "have_backup_locks", "have_backup_locks",
5466 READ_ONLY GLOBAL_VAR(have_backup_locks), NO_CMD_LINE);
5467
5468 static Sys_var_have Sys_have_backup_safe_binlog_info(
5469 "have_backup_safe_binlog_info", "have_backup_safe_binlog_info",
5470 READ_ONLY GLOBAL_VAR(have_backup_safe_binlog_info), NO_CMD_LINE);
5471
5472 static Sys_var_have Sys_have_snapshot_cloning(
5473 "have_snapshot_cloning", "have_snapshot_cloning",
5474 READ_ONLY GLOBAL_VAR(have_snapshot_cloning), NO_CMD_LINE);
5475
5476 static Sys_var_have Sys_have_query_cache(
5477 "have_query_cache",
5478 "have_query_cache. "
5479 "This variable is deprecated and will be removed in a future release.",
5480 READ_ONLY GLOBAL_VAR(have_query_cache), NO_CMD_LINE,
5481 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
5482 DEPRECATED_VAR(""));
5483
5484 static Sys_var_have Sys_have_rtree_keys(
5485 "have_rtree_keys", "have_rtree_keys",
5486 READ_ONLY GLOBAL_VAR(have_rtree_keys), NO_CMD_LINE);
5487
5488 static Sys_var_have Sys_have_ssl(
5489 "have_ssl", "have_ssl",
5490 READ_ONLY GLOBAL_VAR(have_ssl), NO_CMD_LINE);
5491
5492 static Sys_var_have Sys_have_symlink(
5493 "have_symlink", "have_symlink",
5494 READ_ONLY GLOBAL_VAR(have_symlink), NO_CMD_LINE);
5495
5496 static Sys_var_have Sys_have_statement_timeout(
5497 "have_statement_timeout", "have_statement_timeout",
5498 READ_ONLY GLOBAL_VAR(have_statement_timeout), NO_CMD_LINE);
5499
5500 static const char *log_slow_filter_name[]= { "qc_miss", "full_scan", "full_join",
5501 "tmp_table", "tmp_table_on_disk",
5502 "filesort", "filesort_on_disk", 0};
5503 static Sys_var_set Sys_log_slow_filter(
5504 "log_slow_filter",
5505 "Log only the queries that followed certain execution plan. "
5506 "Multiple flags allowed in a comma-separated string. "
5507 "[qc_miss, full_scan, full_join, tmp_table, tmp_table_on_disk, "
5508 "filesort, filesort_on_disk]",
5509 SESSION_VAR(log_slow_filter), CMD_LINE(REQUIRED_ARG),
5510 log_slow_filter_name, DEFAULT(0));
5511 static Sys_var_ulong sys_log_slow_rate_limit(
5512 "log_slow_rate_limit","Rate limit statement writes to slow log to only those from every (1/log_slow_rate_limit) session.",
5513 SESSION_VAR(log_slow_rate_limit), CMD_LINE(REQUIRED_ARG),
5514 VALID_RANGE(1, SLOG_SLOW_RATE_LIMIT_MAX), DEFAULT(1), BLOCK_SIZE(1));
5515
5516 static double opt_slow_query_log_always_write_time;
update_slow_query_log_always_write_time(sys_var * self,THD * thd,enum_var_type type)5517 static bool update_slow_query_log_always_write_time(sys_var *self, THD *thd,
5518 enum_var_type type)
5519 {
5520 slow_query_log_always_write_time=
5521 double2ulonglong(opt_slow_query_log_always_write_time * 1e6);
5522 return false;
5523 }
5524 static Sys_var_double sys_slow_query_log_always_write_time(
5525 "slow_query_log_always_write_time",
5526 "Log queries which run longer than specified by this value regardless "
5527 "of the log_slow_rate_limit valiue.",
5528 GLOBAL_VAR(opt_slow_query_log_always_write_time), CMD_LINE(REQUIRED_ARG),
5529 VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(10),
5530 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
5531 ON_UPDATE(update_slow_query_log_always_write_time));
5532 static const char* log_slow_verbosity_name[] = {
5533 "microtime", "query_plan", "innodb",
5534 "profiling", "profiling_use_getrusage",
5535 "minimal", "standard", "full", 0
5536 };
update_log_slow_verbosity_replace(ulonglong value,ulonglong what,ulonglong by)5537 static ulonglong update_log_slow_verbosity_replace(ulonglong value, ulonglong what, ulonglong by)
5538 {
5539 if((value & what) == what)
5540 {
5541 value = value & (~what);
5542 value = value | by;
5543 }
5544 return value;
5545 }
update_log_slow_verbosity(ulonglong * value_ptr)5546 static void update_log_slow_verbosity(ulonglong* value_ptr)
5547 {
5548 ulonglong &value = *value_ptr;
5549 static const ulonglong microtime= 1ULL << SLOG_V_MICROTIME;
5550 static const ulonglong query_plan= 1ULL << SLOG_V_QUERY_PLAN;
5551 static const ulonglong innodb= 1ULL << SLOG_V_INNODB;
5552 static const ulonglong minimal= 1ULL << SLOG_V_MINIMAL;
5553 static const ulonglong standard= 1ULL << SLOG_V_STANDARD;
5554 static const ulonglong full= 1ULL << SLOG_V_FULL;
5555 value= update_log_slow_verbosity_replace(value,minimal,microtime);
5556 value= update_log_slow_verbosity_replace(value,standard,microtime | query_plan);
5557 value= update_log_slow_verbosity_replace(value,full,microtime | query_plan | innodb);
5558 }
update_log_slow_verbosity_helper(sys_var *,THD * thd,enum_var_type type)5559 static bool update_log_slow_verbosity_helper(sys_var */*self*/, THD *thd,
5560 enum_var_type type)
5561 {
5562 if(type == OPT_SESSION)
5563 {
5564 update_log_slow_verbosity(&(thd->variables.log_slow_verbosity));
5565 }
5566 else
5567 {
5568 update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
5569 }
5570 return false;
5571 }
init_slow_query_log_use_global_control()5572 void init_slow_query_log_use_global_control()
5573 {
5574 update_log_slow_verbosity(&(global_system_variables.log_slow_verbosity));
5575 }
5576 static Sys_var_set Sys_log_slow_verbosity(
5577 "log_slow_verbosity",
5578 "Choose how verbose the messages to your slow log will be. "
5579 "Multiple flags allowed in a comma-separated string. "
5580 "[microtime, query_plan, innodb, profiling, profiling_use_getrusage, "
5581 "minimal, standard, full]",
5582 SESSION_VAR(log_slow_verbosity), CMD_LINE(REQUIRED_ARG),
5583 log_slow_verbosity_name, DEFAULT(SLOG_V_MICROTIME),
5584 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
5585 ON_UPDATE(update_log_slow_verbosity_helper));
5586 static const char *log_slow_sp_statements_names[]=
5587 {"OFF", "ON", "OFF_NO_CALLS", "FALSE", "TRUE", "0", "1", 0};
fix_log_slow_sp_statements(sys_var *,THD *,enum_var_type)5588 static bool fix_log_slow_sp_statements(sys_var */*self*/, THD */*thd*/,
5589 enum_var_type /*type*/)
5590 {
5591 if(opt_log_slow_sp_statements > 2)
5592 {
5593 opt_log_slow_sp_statements= (opt_log_slow_sp_statements - 3) % 2;
5594 }
5595 return false;
5596 }
init_log_slow_sp_statements()5597 void init_log_slow_sp_statements()
5598 {
5599 fix_log_slow_sp_statements(NULL, NULL, OPT_GLOBAL);
5600 }
5601 static Sys_var_enum Sys_log_slow_sp_statements(
5602 "log_slow_sp_statements",
5603 "Choice between logging slow CALL statements, logging individual slow "
5604 "statements inside stored procedures or skipping the logging of stored "
5605 "procedures into the slow log entirely. Values are OFF, ON and "
5606 "OFF_NO_CALLS respectively.",
5607 GLOBAL_VAR(opt_log_slow_sp_statements), CMD_LINE(OPT_ARG),
5608 log_slow_sp_statements_names, DEFAULT(1),
5609 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
5610 ON_UPDATE(fix_log_slow_sp_statements));
5611 static const char *slow_query_log_use_global_control_name[]=
5612 { "log_slow_filter", "log_slow_rate_limit", "log_slow_verbosity",
5613 "long_query_time", "min_examined_row_limit", "all", 0};
update_slow_query_log_use_global_control(sys_var *,THD *,enum_var_type)5614 static bool update_slow_query_log_use_global_control(sys_var */*self*/, THD */*thd*/,
5615 enum_var_type /*type*/)
5616 {
5617 if(opt_slow_query_log_use_global_control & (1ULL << SLOG_UG_ALL))
5618 {
5619 opt_slow_query_log_use_global_control=
5620 (1ULL << SLOG_UG_LOG_SLOW_FILTER) | (1ULL << SLOG_UG_LOG_SLOW_RATE_LIMIT)
5621 | (1ULL << SLOG_UG_LOG_SLOW_VERBOSITY) | (1ULL << SLOG_UG_LONG_QUERY_TIME)
5622 | (1ULL << SLOG_UG_MIN_EXAMINED_ROW_LIMIT);
5623 }
5624 return false;
5625 }
init_log_slow_verbosity()5626 void init_log_slow_verbosity()
5627 {
5628 update_slow_query_log_use_global_control(0,0,OPT_GLOBAL);
5629 }
5630
5631 /**
5632 Specialized class that handles "none" value of
5633 slow_query_log_use_global_control_set variable.
5634 When "none" only value is detected, it is rewriten to empty
5635 causing set to be cleared.
5636 */
5637 class Sys_var_set_none: public Sys_var_set {
5638 public:
Sys_var_set_none(const char * name_arg,const char * comment,int flag_args,ptrdiff_t off,size_t size,CMD_LINE getopt,const char * values[],ulonglong def_val,PolyLock * lock=0,enum binlog_status_enum binlog_status_arg=VARIABLE_NOT_IN_BINLOG,on_check_function on_check_func=0,on_update_function on_update_func=0,const char * substitute=0)5639 Sys_var_set_none(const char *name_arg,
5640 const char *comment, int flag_args, ptrdiff_t off, size_t size,
5641 CMD_LINE getopt, const char *values[], ulonglong def_val, PolyLock *lock =
5642 0, enum binlog_status_enum binlog_status_arg = VARIABLE_NOT_IN_BINLOG,
5643 on_check_function on_check_func = 0,
5644 on_update_function on_update_func = 0, const char *substitute = 0)
5645 : Sys_var_set(name_arg, comment, flag_args, off, size, getopt, values,
5646 def_val, lock, binlog_status_arg, on_check_func, on_update_func,
5647 substitute)
5648 {
5649 }
5650
do_check(THD * thd,set_var * var)5651 virtual bool do_check(THD *thd, set_var *var)
5652 {
5653 if (var->value->result_type() == STRING_RESULT) {
5654 char buff[STRING_BUFFER_USUAL_SIZE];
5655 String str(buff, sizeof(buff), system_charset_info);
5656
5657 String *res = var->value->val_str(&str);
5658 if (res
5659 && (res->length() > 0)
5660 && (0 == my_strcasecmp(system_charset_info, res->ptr(), "none"))) {
5661 var->value = new Item_string("", 0, system_charset_info);
5662 }
5663 }
5664 return Sys_var_set::do_check(thd, var);
5665 }
5666 };
5667
5668 static Sys_var_set_none Sys_slow_query_log_use_global_control(
5669 "slow_query_log_use_global_control",
5670 "Choose flags, wich always use the global variables. Multiple flags "
5671 "allowed in a comma-separated string. [none, log_slow_filter, "
5672 "log_slow_rate_limit, log_slow_verbosity, long_query_time, "
5673 "min_examined_row_limit, all]",
5674 GLOBAL_VAR(opt_slow_query_log_use_global_control),
5675 CMD_LINE(REQUIRED_ARG),
5676 slow_query_log_use_global_control_name, DEFAULT(0),
5677 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
5678 ON_UPDATE(update_slow_query_log_use_global_control));
5679
5680 static const char* slow_query_log_rate_name[]= {"session", "query", 0};
5681 static Sys_var_enum Sys_slow_query_log_rate_type(
5682 "log_slow_rate_type",
5683 "Choose the log_slow_rate_limit behavior: session or query. "
5684 "When you choose 'session' - every %log_slow_rate_limit connection "
5685 "will be processed to slow query log. "
5686 "When you choose 'query' - every %log_slow_rate_limit query "
5687 "will be processed to slow query log. "
5688 "[session, query]",
5689 GLOBAL_VAR(opt_slow_query_log_rate_type), CMD_LINE(REQUIRED_ARG),
5690 slow_query_log_rate_name, DEFAULT(SLOG_RT_SESSION));
5691
fix_general_log_state(sys_var * self,THD * thd,enum_var_type type)5692 static bool fix_general_log_state(sys_var *self, THD *thd, enum_var_type type)
5693 {
5694 bool new_state= opt_general_log,
5695 res= false;
5696
5697 if (query_logger.is_log_file_enabled(QUERY_LOG_GENERAL) == new_state)
5698 return false;
5699
5700 mysql_mutex_unlock(&LOCK_global_system_variables);
5701
5702 if (!new_state)
5703 {
5704 query_logger.deactivate_log_handler(QUERY_LOG_GENERAL);
5705 }
5706 else
5707 {
5708 res= query_logger.activate_log_handler(thd, QUERY_LOG_GENERAL);
5709 }
5710
5711 mysql_mutex_lock(&LOCK_global_system_variables);
5712
5713 if (res)
5714 opt_general_log= false;
5715
5716 return res;
5717 }
5718 static Sys_var_mybool Sys_general_log(
5719 "general_log", "Log connections and queries to a table or log file. "
5720 "Defaults to logging to a file hostname.log, "
5721 "or if --log-output=TABLE is used, to a table mysql.general_log.",
5722 GLOBAL_VAR(opt_general_log), CMD_LINE(OPT_ARG),
5723 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
5724 ON_UPDATE(fix_general_log_state));
5725
fix_slow_log_state(sys_var * self,THD * thd,enum_var_type type)5726 static bool fix_slow_log_state(sys_var *self, THD *thd, enum_var_type type)
5727 {
5728 bool new_state= opt_slow_log,
5729 res= false;
5730
5731 if (query_logger.is_log_file_enabled(QUERY_LOG_SLOW) == new_state)
5732 return false;
5733
5734 mysql_mutex_unlock(&LOCK_global_system_variables);
5735
5736 if (!new_state)
5737 {
5738 query_logger.deactivate_log_handler(QUERY_LOG_SLOW);
5739 }
5740 else
5741 {
5742 res= query_logger.activate_log_handler(thd, QUERY_LOG_SLOW);
5743 }
5744
5745 mysql_mutex_lock(&LOCK_global_system_variables);
5746
5747 if (res)
5748 opt_slow_log= false;
5749
5750 return res;
5751 }
5752 static Sys_var_mybool Sys_slow_query_log(
5753 "slow_query_log",
5754 "Log slow queries to a table or log file. Defaults logging to a file "
5755 "hostname-slow.log or a table mysql.slow_log if --log-output=TABLE is "
5756 "used. Must be enabled to activate other slow log options",
5757 GLOBAL_VAR(opt_slow_log), CMD_LINE(OPT_ARG),
5758 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
5759 ON_UPDATE(fix_slow_log_state));
5760
check_not_empty_set(sys_var * self,THD * thd,set_var * var)5761 static bool check_not_empty_set(sys_var *self, THD *thd, set_var *var)
5762 {
5763 return var->save_result.ulonglong_value == 0;
5764 }
fix_log_output(sys_var * self,THD * thd,enum_var_type type)5765 static bool fix_log_output(sys_var *self, THD *thd, enum_var_type type)
5766 {
5767 query_logger.set_handlers(static_cast<uint>(log_output_options));
5768 return false;
5769 }
5770
5771 static const char *log_output_names[] = { "NONE", "FILE", "TABLE", NULL};
5772
5773 static Sys_var_set Sys_log_output(
5774 "log_output", "Syntax: log-output=value[,value...], "
5775 "where \"value\" could be TABLE, FILE or NONE",
5776 GLOBAL_VAR(log_output_options), CMD_LINE(REQUIRED_ARG),
5777 log_output_names, DEFAULT(LOG_FILE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
5778 ON_CHECK(check_not_empty_set), ON_UPDATE(fix_log_output));
5779
5780 #ifdef HAVE_REPLICATION
5781 static Sys_var_mybool Sys_log_slave_updates(
5782 "log_slave_updates", "Tells the slave to log the updates from "
5783 "the slave thread to the binary log. You will need to turn it on if "
5784 "you plan to daisy-chain the slaves",
5785 READ_ONLY GLOBAL_VAR(opt_log_slave_updates), CMD_LINE(OPT_ARG),
5786 DEFAULT(0));
5787
5788 static Sys_var_charptr Sys_relay_log(
5789 "relay_log", "The location and name to use for relay logs",
5790 READ_ONLY GLOBAL_VAR(opt_relay_logname), CMD_LINE(REQUIRED_ARG),
5791 IN_FS_CHARSET, DEFAULT(0));
5792
5793 /*
5794 Uses NO_CMD_LINE since the --relay-log-index option set
5795 opt_relaylog_index_name variable and computes a value for the
5796 relay_log_index variable.
5797 */
5798 static Sys_var_charptr Sys_relay_log_index(
5799 "relay_log_index", "The location and name to use for the file "
5800 "that keeps a list of the last relay logs",
5801 READ_ONLY GLOBAL_VAR(relay_log_index), NO_CMD_LINE,
5802 IN_FS_CHARSET, DEFAULT(0));
5803
5804 /*
5805 Uses NO_CMD_LINE since the --log-bin-index option set
5806 opt_binlog_index_name variable and computes a value for the
5807 log_bin_index variable.
5808 */
5809 static Sys_var_charptr Sys_binlog_index(
5810 "log_bin_index", "File that holds the names for last binary log files.",
5811 READ_ONLY GLOBAL_VAR(log_bin_index), NO_CMD_LINE,
5812 IN_FS_CHARSET, DEFAULT(0));
5813
5814 static Sys_var_charptr Sys_relay_log_basename(
5815 "relay_log_basename",
5816 "The full path of the relay log file names, excluding the extension.",
5817 READ_ONLY GLOBAL_VAR(relay_log_basename), NO_CMD_LINE,
5818 IN_FS_CHARSET, DEFAULT(0));
5819
5820 static Sys_var_charptr Sys_log_bin_basename(
5821 "log_bin_basename",
5822 "The full path of the binary log file names, excluding the extension.",
5823 READ_ONLY GLOBAL_VAR(log_bin_basename), NO_CMD_LINE,
5824 IN_FS_CHARSET, DEFAULT(0));
5825
5826 static Sys_var_charptr Sys_relay_log_info_file(
5827 "relay_log_info_file", "The location and name of the file that "
5828 "remembers where the SQL replication thread is in the relay logs",
5829 READ_ONLY GLOBAL_VAR(relay_log_info_file), CMD_LINE(REQUIRED_ARG),
5830 IN_FS_CHARSET, DEFAULT(0));
5831
5832 static Sys_var_mybool Sys_relay_log_purge(
5833 "relay_log_purge", "if disabled - do not purge relay logs. "
5834 "if enabled - purge them as soon as they are no more needed",
5835 GLOBAL_VAR(relay_log_purge), CMD_LINE(OPT_ARG), DEFAULT(TRUE));
5836
5837 static Sys_var_mybool Sys_relay_log_recovery(
5838 "relay_log_recovery", "Enables automatic relay log recovery "
5839 "right after the database startup, which means that the IO Thread "
5840 "starts re-fetching from the master right after the last transaction "
5841 "processed",
5842 READ_ONLY GLOBAL_VAR(relay_log_recovery), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
5843
5844 static Sys_var_mybool Sys_slave_allow_batching(
5845 "slave_allow_batching", "Allow slave to batch requests",
5846 GLOBAL_VAR(opt_slave_allow_batching),
5847 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
5848
5849 static Sys_var_charptr Sys_slave_load_tmpdir(
5850 "slave_load_tmpdir", "The location where the slave should put "
5851 "its temporary files when replicating a LOAD DATA INFILE command",
5852 READ_ONLY GLOBAL_VAR(slave_load_tmpdir), CMD_LINE(REQUIRED_ARG),
5853 IN_FS_CHARSET, DEFAULT(0));
5854
fix_slave_net_timeout(sys_var * self,THD * thd,enum_var_type type)5855 static bool fix_slave_net_timeout(sys_var *self, THD *thd, enum_var_type type)
5856 {
5857 DEBUG_SYNC(thd, "fix_slave_net_timeout");
5858 Master_info *mi;
5859
5860
5861 /* @TODO: slave net timeout is for all channels, but does this make
5862 sense?
5863 */
5864
5865 /*
5866 Here we have lock on LOCK_global_system_variables and we need
5867 lock on channel_map lock. In START_SLAVE handler, we take these
5868 two locks in different order. This can lead to DEADLOCKs. See
5869 BUG#14236151 for more details.
5870 So we release lock on LOCK_global_system_variables before acquiring
5871 lock on channel_map lock. But this could lead to isolation issues
5872 between multiple setters. Hence introducing secondary guard
5873 for this global variable and releasing the lock here and acquiring
5874 locks back again at the end of this function.
5875 */
5876 mysql_mutex_unlock(&LOCK_slave_net_timeout);
5877 mysql_mutex_unlock(&LOCK_global_system_variables);
5878 channel_map.wrlock();
5879
5880 for (mi_map::iterator it=channel_map.begin(); it!=channel_map.end(); it++)
5881 {
5882 mi= it->second;
5883
5884 DBUG_PRINT("info", ("slave_net_timeout=%u mi->heartbeat_period=%.3f",
5885 slave_net_timeout,
5886 (mi ? mi->heartbeat_period : 0.0)));
5887 if (mi != NULL && slave_net_timeout < mi->heartbeat_period)
5888 push_warning(thd, Sql_condition::SL_WARNING,
5889 ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX,
5890 ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX));
5891 }
5892
5893 channel_map.unlock();
5894 mysql_mutex_lock(&LOCK_global_system_variables);
5895 mysql_mutex_lock(&LOCK_slave_net_timeout);
5896 return false;
5897 }
5898 static PolyLock_mutex PLock_slave_net_timeout(&LOCK_slave_net_timeout);
5899 static Sys_var_uint Sys_slave_net_timeout(
5900 "slave_net_timeout", "Number of seconds to wait for more data "
5901 "from a master/slave connection before aborting the read",
5902 GLOBAL_VAR(slave_net_timeout), CMD_LINE(REQUIRED_ARG),
5903 VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(SLAVE_NET_TIMEOUT), BLOCK_SIZE(1),
5904 &PLock_slave_net_timeout, NOT_IN_BINLOG, ON_CHECK(0),
5905 ON_UPDATE(fix_slave_net_timeout));
5906
check_slave_skip_counter(sys_var * self,THD * thd,set_var * var)5907 static bool check_slave_skip_counter(sys_var *self, THD *thd, set_var *var)
5908 {
5909 /*
5910 @todo: move this check into the set function and hold the lock on
5911 gtid_mode_lock until the operation has completed, so that we are
5912 sure a concurrent connection does not change gtid_mode between
5913 check and fix.
5914 */
5915 if (get_gtid_mode(GTID_MODE_LOCK_NONE) == GTID_MODE_ON)
5916 {
5917 my_message(ER_SQL_SLAVE_SKIP_COUNTER_NOT_SETTABLE_IN_GTID_MODE,
5918 ER(ER_SQL_SLAVE_SKIP_COUNTER_NOT_SETTABLE_IN_GTID_MODE),
5919 MYF(0));
5920 return true;
5921 }
5922
5923 return false;
5924 }
5925
5926 static PolyLock_mutex PLock_sql_slave_skip_counter(&LOCK_sql_slave_skip_counter);
5927 static Sys_var_uint Sys_slave_skip_counter(
5928 "sql_slave_skip_counter", "sql_slave_skip_counter",
5929 GLOBAL_VAR(sql_slave_skip_counter), NO_CMD_LINE,
5930 VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1),
5931 &PLock_sql_slave_skip_counter, NOT_IN_BINLOG,
5932 ON_CHECK(check_slave_skip_counter));
5933
5934 static Sys_var_charptr Sys_slave_skip_errors(
5935 "slave_skip_errors", "Tells the slave thread to continue "
5936 "replication when a query event returns an error from the "
5937 "provided list",
5938 READ_ONLY GLOBAL_VAR(opt_slave_skip_errors), CMD_LINE(REQUIRED_ARG),
5939 IN_SYSTEM_CHARSET, DEFAULT(0));
5940
5941 static Sys_var_ulonglong Sys_relay_log_space_limit(
5942 "relay_log_space_limit", "Maximum space to use for all relay logs",
5943 READ_ONLY GLOBAL_VAR(relay_log_space_limit), CMD_LINE(REQUIRED_ARG),
5944 VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
5945
5946 static Sys_var_uint Sys_sync_relaylog_period(
5947 "sync_relay_log", "Synchronously flush relay log to disk after "
5948 "every #th event. Use 0 to disable synchronous flushing",
5949 GLOBAL_VAR(sync_relaylog_period), CMD_LINE(REQUIRED_ARG),
5950 VALID_RANGE(0, UINT_MAX), DEFAULT(10000), BLOCK_SIZE(1));
5951
5952 static Sys_var_uint Sys_sync_relayloginfo_period(
5953 "sync_relay_log_info", "Synchronously flush relay log info "
5954 "to disk after every #th transaction. Use 0 to disable "
5955 "synchronous flushing",
5956 GLOBAL_VAR(sync_relayloginfo_period), CMD_LINE(REQUIRED_ARG),
5957 VALID_RANGE(0, UINT_MAX), DEFAULT(10000), BLOCK_SIZE(1));
5958
5959 static Sys_var_uint Sys_checkpoint_mts_period(
5960 "slave_checkpoint_period", "Gather workers' activities to "
5961 "Update progress status of Multi-threaded slave and flush "
5962 "the relay log info to disk after every #th milli-seconds.",
5963 GLOBAL_VAR(opt_mts_checkpoint_period), CMD_LINE(REQUIRED_ARG),
5964 #ifndef NDEBUG
5965 VALID_RANGE(0, UINT_MAX), DEFAULT(300), BLOCK_SIZE(1));
5966 #else
5967 VALID_RANGE(1, UINT_MAX), DEFAULT(300), BLOCK_SIZE(1));
5968 #endif /* NDEBUG */
5969
5970 static Sys_var_uint Sys_checkpoint_mts_group(
5971 "slave_checkpoint_group",
5972 "Maximum number of processed transactions by Multi-threaded slave "
5973 "before a checkpoint operation is called to update progress status.",
5974 GLOBAL_VAR(opt_mts_checkpoint_group), CMD_LINE(REQUIRED_ARG),
5975 #ifndef NDEBUG
5976 VALID_RANGE(1, MTS_MAX_BITS_IN_GROUP), DEFAULT(512), BLOCK_SIZE(1));
5977 #else
5978 VALID_RANGE(32, MTS_MAX_BITS_IN_GROUP), DEFAULT(512), BLOCK_SIZE(8));
5979 #endif /* NDEBUG */
5980 #endif /* HAVE_REPLICATION */
5981
5982 static Sys_var_uint Sys_sync_binlog_period(
5983 "sync_binlog", "Synchronously flush binary log to disk after"
5984 " every #th write to the file. Use 0 to disable synchronous"
5985 " flushing",
5986 GLOBAL_VAR(sync_binlog_period), CMD_LINE(REQUIRED_ARG),
5987 VALID_RANGE(0, UINT_MAX), DEFAULT(1), BLOCK_SIZE(1));
5988
5989 static Sys_var_uint Sys_sync_masterinfo_period(
5990 "sync_master_info", "Synchronously flush master info to disk "
5991 "after every #th event. Use 0 to disable synchronous flushing",
5992 GLOBAL_VAR(sync_masterinfo_period), CMD_LINE(REQUIRED_ARG),
5993 VALID_RANGE(0, UINT_MAX), DEFAULT(10000), BLOCK_SIZE(1));
5994
5995 #ifdef HAVE_REPLICATION
5996 static Sys_var_ulong Sys_slave_trans_retries(
5997 "slave_transaction_retries", "Number of times the slave SQL "
5998 "thread will retry a transaction in case it failed with a deadlock "
5999 "or elapsed lock wait timeout, before giving up and stopping",
6000 GLOBAL_VAR(slave_trans_retries), CMD_LINE(REQUIRED_ARG),
6001 VALID_RANGE(0, ULONG_MAX), DEFAULT(10), BLOCK_SIZE(1));
6002
6003 static Sys_var_ulong Sys_slave_parallel_workers(
6004 "slave_parallel_workers",
6005 "Number of worker threads for executing events in parallel ",
6006 GLOBAL_VAR(opt_mts_slave_parallel_workers), CMD_LINE(REQUIRED_ARG),
6007 VALID_RANGE(0, MTS_MAX_WORKERS), DEFAULT(0), BLOCK_SIZE(1));
6008
6009 static Sys_var_ulonglong Sys_mts_pending_jobs_size_max(
6010 "slave_pending_jobs_size_max",
6011 "Max size of Slave Worker queues holding yet not applied events."
6012 "The least possible value must be not less than the master side "
6013 "max_allowed_packet.",
6014 GLOBAL_VAR(opt_mts_pending_jobs_size_max), CMD_LINE(REQUIRED_ARG),
6015 VALID_RANGE(1024, (ulonglong)~(intptr)0), DEFAULT(16 * 1024*1024),
6016 BLOCK_SIZE(1024), ON_CHECK(0));
6017 #endif
6018
check_locale(sys_var * self,THD * thd,set_var * var)6019 static bool check_locale(sys_var *self, THD *thd, set_var *var)
6020 {
6021 if (!var->value)
6022 return false;
6023
6024 MY_LOCALE *locale;
6025 char buff[STRING_BUFFER_USUAL_SIZE];
6026 if (var->value->result_type() == INT_RESULT)
6027 {
6028 int lcno= (int)var->value->val_int();
6029 if (!(locale= my_locale_by_number(lcno)))
6030 {
6031 my_error(ER_UNKNOWN_LOCALE, MYF(0), llstr(lcno, buff));
6032 return true;
6033 }
6034 if (check_not_null(self, thd, var))
6035 return true;
6036 }
6037 else // STRING_RESULT
6038 {
6039 String str(buff, sizeof(buff), system_charset_info), *res;
6040 if (!(res=var->value->val_str(&str)))
6041 return true;
6042 else if (!(locale= my_locale_by_name(res->c_ptr_safe())))
6043 {
6044 ErrConvString err(res);
6045 my_error(ER_UNKNOWN_LOCALE, MYF(0), err.ptr());
6046 return true;
6047 }
6048 }
6049
6050 var->save_result.ptr= locale;
6051
6052 if (!locale->errmsgs->is_loaded())
6053 {
6054 mysql_mutex_lock(&LOCK_error_messages);
6055 if (!locale->errmsgs->is_loaded() &&
6056 locale->errmsgs->read_texts())
6057 {
6058 push_warning_printf(thd, Sql_condition::SL_WARNING, ER_UNKNOWN_ERROR,
6059 "Can't process error message file for locale '%s'",
6060 locale->name);
6061 mysql_mutex_unlock(&LOCK_error_messages);
6062 return true;
6063 }
6064 mysql_mutex_unlock(&LOCK_error_messages);
6065 }
6066 return false;
6067 }
6068 static Sys_var_struct Sys_lc_messages(
6069 "lc_messages", "Set the language used for the error messages",
6070 SESSION_VAR(lc_messages), NO_CMD_LINE,
6071 my_offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_messages),
6072 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_locale));
6073
6074 static Sys_var_struct Sys_lc_time_names(
6075 "lc_time_names", "Set the language used for the month "
6076 "names and the days of the week",
6077 SESSION_VAR(lc_time_names), NO_CMD_LINE,
6078 my_offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_time_names),
6079 NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_locale));
6080
6081 static Sys_var_tz Sys_time_zone(
6082 "time_zone", "time_zone",
6083 SESSION_VAR(time_zone), NO_CMD_LINE,
6084 DEFAULT(&default_tz), NO_MUTEX_GUARD, IN_BINLOG);
6085
fix_host_cache_size(sys_var *,THD *,enum_var_type)6086 static bool fix_host_cache_size(sys_var *, THD *, enum_var_type)
6087 {
6088 hostname_cache_resize(host_cache_size);
6089 return false;
6090 }
6091
6092 static Sys_var_uint Sys_host_cache_size(
6093 "host_cache_size",
6094 "How many host names should be cached to avoid resolving.",
6095 GLOBAL_VAR(host_cache_size),
6096 CMD_LINE(REQUIRED_ARG, OPT_HOST_CACHE_SIZE), VALID_RANGE(0, 65536),
6097 DEFAULT(HOST_CACHE_SIZE),
6098 BLOCK_SIZE(1),
6099 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
6100 ON_UPDATE(fix_host_cache_size));
6101
6102 static Sys_var_charptr Sys_ignore_db_dirs(
6103 "ignore_db_dirs",
6104 "The list of directories to ignore when collecting database lists",
6105 READ_ONLY GLOBAL_VAR(opt_ignore_db_dirs),
6106 NO_CMD_LINE,
6107 IN_FS_CHARSET, DEFAULT(0));
6108
6109 const Sys_var_multi_enum::ALIAS enforce_gtid_consistency_aliases[]=
6110 {
6111 { "OFF", 0 },
6112 { "ON", 1 },
6113 { "WARN", 2 },
6114 { "FALSE", 0 },
6115 { "TRUE", 1 },
6116 { NULL, 0 }
6117 };
6118 static Sys_var_enforce_gtid_consistency Sys_enforce_gtid_consistency(
6119 "enforce_gtid_consistency",
6120 "Prevents execution of statements that would be impossible to log "
6121 "in a transactionally safe manner. Currently, the disallowed "
6122 "statements include CREATE TEMPORARY TABLE inside transactions, "
6123 "all updates to non-transactional tables, and CREATE TABLE ... SELECT.",
6124 GLOBAL_VAR(_gtid_consistency_mode),
6125 CMD_LINE(OPT_ARG, OPT_ENFORCE_GTID_CONSISTENCY),
6126 enforce_gtid_consistency_aliases, 3,
6127 DEFAULT(3/*position of "FALSE" in enforce_gtid_consistency_aliases*/),
6128 DEFAULT(GTID_CONSISTENCY_MODE_ON),
6129 NO_MUTEX_GUARD, NOT_IN_BINLOG,
6130 ON_CHECK(check_super_outside_trx_outside_sf_outside_sp));
fixup_enforce_gtid_consistency_command_line(char * value_arg)6131 const char *fixup_enforce_gtid_consistency_command_line(char *value_arg)
6132 {
6133 return Sys_enforce_gtid_consistency.fixup_command_line(value_arg);
6134 }
6135
6136 static Sys_var_mybool Sys_binlog_gtid_simple_recovery(
6137 "binlog_gtid_simple_recovery",
6138 "If this option is enabled, the server does not open more than "
6139 "two binary logs when initializing GTID_PURGED and "
6140 "GTID_EXECUTED, either during server restart or when binary "
6141 "logs are being purged. Enabling this option is useful when "
6142 "the server has already generated many binary logs without "
6143 "GTID events (e.g., having GTID_MODE = OFF). Note: If this "
6144 "option is enabled, GLOBAL.GTID_EXECUTED and "
6145 "GLOBAL.GTID_PURGED may be initialized wrongly in two cases: "
6146 "(1) All binary logs were generated by MySQL 5.7.5 or older, "
6147 "and GTID_MODE was ON for some binary logs but OFF for the "
6148 "newest binary log. (2) The oldest existing binary log was "
6149 "generated by MySQL 5.7.5 or older, and SET GTID_PURGED was "
6150 "issued after the oldest binary log was generated. If a wrong "
6151 "set is computed in one of case (1) or case (2), it will "
6152 "remain wrong even if the server is later restarted with this "
6153 "option disabled.",
6154 READ_ONLY GLOBAL_VAR(binlog_gtid_simple_recovery),
6155 CMD_LINE(OPT_ARG), DEFAULT(TRUE));
6156
6157 static Sys_var_ulong Sys_sp_cache_size(
6158 "stored_program_cache",
6159 "The soft upper limit for number of cached stored routines for "
6160 "one connection.",
6161 GLOBAL_VAR(stored_program_cache_size), CMD_LINE(REQUIRED_ARG),
6162 VALID_RANGE(16, 512 * 1024), DEFAULT(256), BLOCK_SIZE(1));
6163
6164 static Sys_var_mybool Sys_encrypt_tmp_files(
6165 "encrypt_tmp_files",
6166 "Encrypt temporary files "
6167 "(created for filesort, binary log cache, etc)",
6168 READ_ONLY GLOBAL_VAR(encrypt_tmp_files),
6169 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
6170
check_pseudo_slave_mode(sys_var * self,THD * thd,set_var * var)6171 static bool check_pseudo_slave_mode(sys_var *self, THD *thd, set_var *var)
6172 {
6173 if (check_outside_trx(self, thd, var))
6174 return true;
6175 longlong previous_val= thd->variables.pseudo_slave_mode;
6176 longlong val= (longlong) var->save_result.ulonglong_value;
6177 bool rli_fake= false;
6178
6179 #ifndef EMBEDDED_LIBRARY
6180 rli_fake= thd->rli_fake ? true : false;
6181 #endif
6182
6183 if (rli_fake)
6184 {
6185 if (!val)
6186 {
6187 #ifndef EMBEDDED_LIBRARY
6188 thd->rli_fake->end_info();
6189 delete thd->rli_fake;
6190 thd->rli_fake= NULL;
6191 #endif
6192 }
6193 else if (previous_val && val)
6194 goto ineffective;
6195 else if (!previous_val && val)
6196 push_warning(thd, Sql_condition::SL_WARNING,
6197 ER_WRONG_VALUE_FOR_VAR,
6198 "'pseudo_slave_mode' is already ON.");
6199 }
6200 else
6201 {
6202 if (!previous_val && !val)
6203 goto ineffective;
6204 else if (previous_val && !val)
6205 push_warning(thd, Sql_condition::SL_WARNING,
6206 ER_WRONG_VALUE_FOR_VAR,
6207 "Slave applier execution mode not active, "
6208 "statement ineffective.");
6209 }
6210 goto end;
6211
6212 ineffective:
6213 push_warning(thd, Sql_condition::SL_WARNING,
6214 ER_WRONG_VALUE_FOR_VAR,
6215 "'pseudo_slave_mode' change was ineffective.");
6216
6217 end:
6218 return FALSE;
6219 }
6220 static Sys_var_mybool Sys_pseudo_slave_mode(
6221 "pseudo_slave_mode",
6222 "SET pseudo_slave_mode= 0,1 are commands that mysqlbinlog "
6223 "adds to beginning and end of binary log dumps. While zero "
6224 "value indeed disables, the actual enabling of the slave "
6225 "applier execution mode is done implicitly when a "
6226 "Format_description_event is sent through the session.",
6227 SESSION_ONLY(pseudo_slave_mode), NO_CMD_LINE, DEFAULT(FALSE),
6228 NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_pseudo_slave_mode));
6229
6230
6231 #ifdef HAVE_REPLICATION
6232 #ifdef HAVE_GTID_NEXT_LIST
check_gtid_next_list(sys_var * self,THD * thd,set_var * var)6233 static bool check_gtid_next_list(sys_var *self, THD *thd, set_var *var)
6234 {
6235 DBUG_ENTER("check_gtid_next_list");
6236 my_error(ER_NOT_SUPPORTED_YET, MYF(0), "GTID_NEXT_LIST");
6237 if (check_super_outside_trx_outside_sf_outside_sp(self, thd, var))
6238 DBUG_RETURN(true);
6239 /*
6240 @todo: move this check into the set function and hold the lock on
6241 gtid_mode_lock until the operation has completed, so that we are
6242 sure a concurrent connection does not change gtid_mode between
6243 check and fix - if we ever implement this variable.
6244 */
6245 if (get_gtid_mode(GTID_MODE_LOCK_NONE) == GTID_MODE_OFF &&
6246 var->save_result.string_value.str != NULL)
6247 my_error(ER_CANT_SET_GTID_NEXT_LIST_TO_NON_NULL_WHEN_GTID_MODE_IS_OFF,
6248 MYF(0));
6249 DBUG_RETURN(false);
6250 }
6251
update_gtid_next_list(sys_var * self,THD * thd,enum_var_type type)6252 static bool update_gtid_next_list(sys_var *self, THD *thd, enum_var_type type)
6253 {
6254 assert(type == OPT_SESSION);
6255 if (thd->get_gtid_next_list() != NULL)
6256 return gtid_acquire_ownership_multiple(thd) != 0 ? true : false;
6257 return false;
6258 }
6259
6260 static Sys_var_gtid_set Sys_gtid_next_list(
6261 "gtid_next_list",
6262 "Before re-executing a transaction that contains multiple "
6263 "Global Transaction Identifiers, this variable must be set "
6264 "to the set of all re-executed transactions.",
6265 SESSION_ONLY(gtid_next_list), NO_CMD_LINE,
6266 DEFAULT(NULL), NO_MUTEX_GUARD,
6267 NOT_IN_BINLOG, ON_CHECK(check_gtid_next_list),
6268 ON_UPDATE(update_gtid_next_list)
6269 );
6270 export sys_var *Sys_gtid_next_list_ptr= &Sys_gtid_next_list;
6271 #endif //HAVE_GTID_NEXT_LIST
6272
6273 static Sys_var_gtid_next Sys_gtid_next(
6274 "gtid_next",
6275 "Specifies the Global Transaction Identifier for the following "
6276 "transaction.",
6277 SESSION_ONLY(gtid_next), NO_CMD_LINE,
6278 DEFAULT("AUTOMATIC"), NO_MUTEX_GUARD,
6279 NOT_IN_BINLOG, ON_CHECK(check_gtid_next));
6280 export sys_var *Sys_gtid_next_ptr= &Sys_gtid_next;
6281
6282 static Sys_var_gtid_executed Sys_gtid_executed(
6283 "gtid_executed",
6284 "The global variable contains the set of GTIDs in the "
6285 "binary log. The session variable contains the set of GTIDs "
6286 "in the current, ongoing transaction.");
6287
check_gtid_purged(sys_var * self,THD * thd,set_var * var)6288 static bool check_gtid_purged(sys_var *self, THD *thd, set_var *var)
6289 {
6290 DBUG_ENTER("check_gtid_purged");
6291
6292 if (!var->value ||
6293 check_super_outside_trx_outside_sf_outside_sp(self, thd, var))
6294 DBUG_RETURN(true);
6295
6296 if (var->value->result_type() != STRING_RESULT ||
6297 !var->save_result.string_value.str)
6298 DBUG_RETURN(true);
6299
6300 DBUG_RETURN(false);
6301 }
6302
global_update(THD * thd,set_var * var)6303 bool Sys_var_gtid_purged::global_update(THD *thd, set_var *var)
6304 {
6305 DBUG_ENTER("Sys_var_gtid_purged::global_update");
6306 #ifdef HAVE_REPLICATION
6307 bool error= false;
6308
6309 global_sid_lock->wrlock();
6310
6311 /*
6312 ensures the commit of the transaction started when saving the
6313 purged gtid set in the table
6314 */
6315 thd->lex->autocommit= true;
6316 /*
6317 SET GITD_PURGED command should ignore 'read-only' and 'super_read_only'
6318 options so that it can update 'mysql.gtid_executed' replication repository
6319 table.
6320 */
6321 thd->set_skip_readonly_check();
6322 char *previous_gtid_executed= NULL, *previous_gtid_purged= NULL,
6323 *current_gtid_executed= NULL, *current_gtid_purged= NULL;
6324 gtid_state->get_executed_gtids()->to_string(&previous_gtid_executed);
6325 gtid_state->get_lost_gtids()->to_string(&previous_gtid_purged);
6326 enum_return_status ret;
6327 Gtid_set gtid_set(global_sid_map, var->save_result.string_value.str,
6328 &ret, global_sid_lock);
6329 if (ret != RETURN_STATUS_OK)
6330 {
6331 global_sid_lock->unlock();
6332 error= true;
6333 goto end;
6334 }
6335 ret= gtid_state->add_lost_gtids(>id_set);
6336 if (ret != RETURN_STATUS_OK)
6337 {
6338 global_sid_lock->unlock();
6339 error= true;
6340 goto end;
6341 }
6342 gtid_state->get_executed_gtids()->to_string(¤t_gtid_executed);
6343 gtid_state->get_lost_gtids()->to_string(¤t_gtid_purged);
6344 global_sid_lock->unlock();
6345
6346 // Log messages saying that GTID_PURGED and GTID_EXECUTED were changed.
6347 sql_print_information(ER(ER_GTID_PURGED_WAS_CHANGED),
6348 previous_gtid_purged, current_gtid_purged);
6349 sql_print_information(ER(ER_GTID_EXECUTED_WAS_CHANGED),
6350 previous_gtid_executed, current_gtid_executed);
6351
6352 end:
6353 my_free(previous_gtid_executed);
6354 my_free(previous_gtid_purged);
6355 my_free(current_gtid_executed);
6356 my_free(current_gtid_purged);
6357 DBUG_RETURN(error);
6358 #else
6359 DBUG_RETURN(true);
6360 #endif /* HAVE_REPLICATION */
6361 }
6362
6363 Gtid_set *gtid_purged;
6364 static Sys_var_gtid_purged Sys_gtid_purged(
6365 "gtid_purged",
6366 "The set of GTIDs that existed in previous, purged binary logs.",
6367 GLOBAL_VAR(gtid_purged), NO_CMD_LINE,
6368 DEFAULT(NULL), NO_MUTEX_GUARD,
6369 NOT_IN_BINLOG, ON_CHECK(check_gtid_purged));
6370 export sys_var *Sys_gtid_purged_ptr= &Sys_gtid_purged;
6371
6372 static Sys_var_gtid_owned Sys_gtid_owned(
6373 "gtid_owned",
6374 "The global variable lists all GTIDs owned by all threads. "
6375 "The session variable lists all GTIDs owned by the current thread.");
6376
6377 static Sys_var_gtid_mode Sys_gtid_mode(
6378 "gtid_mode",
6379 "Controls whether Global Transaction Identifiers (GTIDs) are "
6380 "enabled. Can be OFF, OFF_PERMISSIVE, ON_PERMISSIVE, or ON. OFF "
6381 "means that no transaction has a GTID. OFF_PERMISSIVE means that "
6382 "new transactions (committed in a client session using "
6383 "GTID_NEXT='AUTOMATIC') are not assigned any GTID, and "
6384 "replicated transactions are allowed to have or not have a "
6385 "GTID. ON_PERMISSIVE means that new transactions are assigned a "
6386 "GTID, and replicated transactions are allowed to have or not "
6387 "have a GTID. ON means that all transactions have a GTID. "
6388 "ON is required on a master before any slave can use "
6389 "MASTER_AUTO_POSITION=1. To safely switch from OFF to ON, first "
6390 "set all servers to OFF_PERMISSIVE, then set all servers to "
6391 "ON_PERMISSIVE, then wait for all transactions without a GTID to "
6392 "be replicated and executed on all servers, and finally set all "
6393 "servers to GTID_MODE = ON.",
6394 GLOBAL_VAR(_gtid_mode), CMD_LINE(REQUIRED_ARG), gtid_mode_names,
6395 DEFAULT(GTID_MODE_OFF), NO_MUTEX_GUARD, NOT_IN_BINLOG,
6396 ON_CHECK(check_super_outside_trx_outside_sf_outside_sp));
6397
6398 #endif // HAVE_REPLICATION
6399
6400 static Sys_var_uint Sys_gtid_executed_compression_period(
6401 "gtid_executed_compression_period", "When binlog is disabled, "
6402 "a background thread wakes up to compress the gtid_executed table "
6403 "every gtid_executed_compression_period transactions, as a "
6404 "special case, if variable is 0, the thread never wakes up "
6405 "to compress the gtid_executed table.",
6406 GLOBAL_VAR(gtid_executed_compression_period),
6407 CMD_LINE(OPT_ARG), VALID_RANGE(0, UINT_MAX32), DEFAULT(1000),
6408 BLOCK_SIZE(1));
6409
6410 static Sys_var_mybool Sys_disconnect_on_expired_password(
6411 "disconnect_on_expired_password",
6412 "Give clients that don't signal password expiration support execution time error(s) instead of connection error",
6413 READ_ONLY GLOBAL_VAR(disconnect_on_expired_password),
6414 CMD_LINE(OPT_ARG), DEFAULT(TRUE));
6415
6416 #ifndef NO_EMBEDDED_ACCESS_CHECKS
6417 static Sys_var_mybool Sys_validate_user_plugins(
6418 "validate_user_plugins",
6419 "Turns on additional validation of authentication plugins assigned "
6420 "to user accounts. ",
6421 READ_ONLY NOT_VISIBLE GLOBAL_VAR(validate_user_plugins),
6422 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
6423 NO_MUTEX_GUARD, NOT_IN_BINLOG);
6424 #endif
6425
6426 static Sys_var_enum Sys_block_encryption_mode(
6427 "block_encryption_mode", "mode for AES_ENCRYPT/AES_DECRYPT",
6428 SESSION_VAR(my_aes_mode), CMD_LINE(REQUIRED_ARG),
6429 my_aes_opmode_names, DEFAULT(my_aes_128_ecb));
6430
check_track_session_sys_vars(sys_var * self,THD * thd,set_var * var)6431 static bool check_track_session_sys_vars(sys_var *self, THD *thd, set_var *var)
6432 {
6433 DBUG_ENTER("check_sysvar_change_reporter");
6434 DBUG_RETURN(thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)->check(thd, var));
6435 DBUG_RETURN(false);
6436 }
6437
update_track_session_sys_vars(sys_var * self,THD * thd,enum_var_type type)6438 static bool update_track_session_sys_vars(sys_var *self, THD *thd,
6439 enum_var_type type)
6440 {
6441 DBUG_ENTER("check_sysvar_change_reporter");
6442 /* Populate map only for session variable. */
6443 if (type == OPT_SESSION)
6444 DBUG_RETURN(thd->session_tracker.get_tracker(SESSION_SYSVARS_TRACKER)->update(thd));
6445 DBUG_RETURN(false);
6446 }
6447
6448 static Sys_var_charptr Sys_track_session_sys_vars(
6449 "session_track_system_variables",
6450 "Track changes in registered system variables.",
6451 SESSION_VAR(track_sysvars_ptr),
6452 CMD_LINE(REQUIRED_ARG),
6453 IN_FS_CHARSET,
6454 DEFAULT("time_zone,autocommit,character_set_client,character_set_results,"
6455 "character_set_connection"),
6456 NO_MUTEX_GUARD,
6457 NOT_IN_BINLOG,
6458 ON_CHECK(check_track_session_sys_vars),
6459 ON_UPDATE(update_track_session_sys_vars)
6460 );
6461
update_session_track_schema(sys_var * self,THD * thd,enum_var_type type)6462 static bool update_session_track_schema(sys_var *self, THD *thd,
6463 enum_var_type type)
6464 {
6465 DBUG_ENTER("update_session_track_schema");
6466 DBUG_RETURN(thd->session_tracker.get_tracker(CURRENT_SCHEMA_TRACKER)->update(thd));
6467 }
6468
6469 static Sys_var_mybool Sys_session_track_schema(
6470 "session_track_schema",
6471 "Track changes to the 'default schema'.",
6472 SESSION_VAR(session_track_schema),
6473 CMD_LINE(OPT_ARG), DEFAULT(TRUE),
6474 NO_MUTEX_GUARD, NOT_IN_BINLOG,
6475 ON_CHECK(0),
6476 ON_UPDATE(update_session_track_schema));
6477
update_session_track_tx_info(sys_var * self,THD * thd,enum_var_type type)6478 static bool update_session_track_tx_info(sys_var *self, THD *thd,
6479 enum_var_type type)
6480 {
6481 DBUG_ENTER("update_session_track_tx_info");
6482 DBUG_RETURN(thd->session_tracker.get_tracker(TRANSACTION_INFO_TRACKER)->update(thd));
6483 }
6484
6485 static const char *session_track_transaction_info_names[]=
6486 { "OFF", "STATE", "CHARACTERISTICS", NullS };
6487
6488 static Sys_var_enum Sys_session_track_transaction_info(
6489 "session_track_transaction_info",
6490 "Track changes to the transaction attributes. OFF to disable; "
6491 "STATE to track just transaction state (Is there an active transaction? "
6492 "Does it have any data? etc.); CHARACTERISTICS to track transaction "
6493 "state "
6494 "and report all statements needed to start a transaction with the same "
6495 "characteristics (isolation level, read only/read write, snapshot - "
6496 "but not any work done / data modified within the transaction).",
6497 SESSION_VAR(session_track_transaction_info),
6498 CMD_LINE(REQUIRED_ARG), session_track_transaction_info_names,
6499 DEFAULT(OFF), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
6500 ON_UPDATE(update_session_track_tx_info));
6501
update_session_track_state_change(sys_var * self,THD * thd,enum_var_type type)6502 static bool update_session_track_state_change(sys_var *self, THD *thd,
6503 enum_var_type type)
6504 {
6505 DBUG_ENTER("update_session_track_state_change");
6506 DBUG_RETURN(thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER)->update(thd));
6507 }
6508
6509 static Sys_var_mybool Sys_session_track_state_change(
6510 "session_track_state_change",
6511 "Track changes to the 'session state'.",
6512 SESSION_VAR(session_track_state_change),
6513 CMD_LINE(OPT_ARG), DEFAULT(FALSE),
6514 NO_MUTEX_GUARD, NOT_IN_BINLOG,
6515 ON_CHECK(0),
6516 ON_UPDATE(update_session_track_state_change));
6517
handle_offline_mode(sys_var * self,THD * thd,enum_var_type type)6518 static bool handle_offline_mode(sys_var *self, THD *thd, enum_var_type type)
6519 {
6520 DBUG_ENTER("handle_offline_mode");
6521 if (offline_mode == TRUE)
6522 killall_non_super_threads(thd);
6523 DBUG_RETURN(false);
6524 }
6525
6526 static PolyLock_mutex PLock_offline_mode(&LOCK_offline_mode);
6527 static Sys_var_mybool Sys_offline_mode(
6528 "offline_mode",
6529 "Make the server into offline mode",
6530 GLOBAL_VAR(offline_mode), CMD_LINE(OPT_ARG), DEFAULT(FALSE),
6531 &PLock_offline_mode, NOT_IN_BINLOG,
6532 ON_CHECK(0), ON_UPDATE(handle_offline_mode));
6533
6534 static Sys_var_mybool Sys_log_builtin_as_identified_by_password(
6535 "log_builtin_as_identified_by_password",
6536 "Controls logging of CREATE/ALTER/GRANT and SET PASSWORD user statements "
6537 "in replication binlogs, general query logs and audit logs.",
6538 GLOBAL_VAR(opt_log_builtin_as_identified_by_password),
6539 CMD_LINE(OPT_ARG), DEFAULT(FALSE));
6540
6541 static Sys_var_mybool Sys_avoid_temporal_upgrade(
6542 "avoid_temporal_upgrade",
6543 "When this option is enabled, the pre-5.6.4 temporal types are "
6544 "not upgraded to the new format for ALTER TABLE requests ADD/CHANGE/MODIFY"
6545 " COLUMN, ADD INDEX or FORCE operation. "
6546 "This variable is deprecated and will be removed in a future release.",
6547 GLOBAL_VAR(avoid_temporal_upgrade),
6548 CMD_LINE(OPT_ARG, OPT_AVOID_TEMPORAL_UPGRADE),
6549 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
6550 ON_CHECK(0), ON_UPDATE(0),
6551 DEPRECATED_VAR(""));
6552
6553 static Sys_var_mybool Sys_show_old_temporals(
6554 "show_old_temporals",
6555 "When this option is enabled, the pre-5.6.4 temporal types will "
6556 "be marked in the 'SHOW CREATE TABLE' and 'INFORMATION_SCHEMA.COLUMNS' "
6557 "table as a comment in COLUMN_TYPE field. "
6558 "This variable is deprecated and will be removed in a future release.",
6559 SESSION_VAR(show_old_temporals),
6560 CMD_LINE(OPT_ARG, OPT_SHOW_OLD_TEMPORALS),
6561 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
6562 ON_CHECK(0), ON_UPDATE(0),
6563 DEPRECATED_VAR(""));
6564
6565 static Sys_var_charptr Sys_disabled_storage_engines(
6566 "disabled_storage_engines",
6567 "Limit CREATE TABLE for the storage engines listed",
6568 READ_ONLY GLOBAL_VAR(opt_disabled_storage_engines),
6569 CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
6570 DEFAULT(""));
6571
6572 static Sys_var_mybool Sys_show_create_table_verbosity(
6573 "show_create_table_verbosity",
6574 "When this option is enabled, it increases the verbosity of "
6575 "'SHOW CREATE TABLE'.",
6576 SESSION_VAR(show_create_table_verbosity),
6577 CMD_LINE(OPT_ARG),
6578 DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
6579 ON_CHECK(0), ON_UPDATE(0));
6580
check_keyring_access(sys_var *,THD * thd,set_var *)6581 static bool check_keyring_access(sys_var*, THD* thd, set_var*)
6582 {
6583 if (!(thd->security_context()->check_access(SUPER_ACL)))
6584 {
6585 my_error(ER_KEYRING_ACCESS_DENIED_ERROR, MYF(0),
6586 "SUPER");
6587 return true;
6588 }
6589 return false;
6590 }
6591
6592 /**
6593 This is a mutex used to protect global variable @@keyring_operations.
6594 */
6595 static PolyLock_mutex PLock_keyring_operations(&LOCK_keyring_operations);
6596 /**
6597 This variable provides access to keyring service APIs. When this variable
6598 is disabled calls to keyring_key_generate(), keyring_key_store() and
6599 keyring_key_remove() will report error until this variable is enabled.
6600 This variable is protected under a mutex named PLock_keyring_operations.
6601 To access this variable you must first set this mutex.
6602
6603 @sa PLock_keyring_operations
6604 */
6605 static Sys_var_mybool Sys_keyring_operations(
6606 "keyring_operations",
6607 "This variable provides access to keyring service APIs. When this "
6608 "option is disabled calls to keyring_key_generate(), keyring_key_store() "
6609 "and keyring_key_remove() will report error until this variable is enabled.",
6610 GLOBAL_VAR(opt_keyring_operations),
6611 NO_CMD_LINE, DEFAULT(TRUE),
6612 &PLock_keyring_operations,
6613 NOT_IN_BINLOG,
6614 ON_CHECK(check_keyring_access),
6615 ON_UPDATE(0));
6616
6617 /**
6618 Changes the `Delegate` internal state in regards to which type of lock to
6619 use and in regards to whether or not to take plugin locks in each hook
6620 invocation.
6621 */
handle_plugin_lock_type_change(sys_var *,THD *,enum_var_type)6622 static bool handle_plugin_lock_type_change(sys_var *, THD *,
6623 enum_var_type)
6624 {
6625 DBUG_ENTER("handle_plugin_lock_type_change");
6626 delegates_acquire_locks();
6627 delegates_update_lock_type();
6628 delegates_release_locks();
6629 DBUG_RETURN(false);
6630 }
6631
6632 static Sys_var_mybool Sys_replication_optimize_for_static_plugin_config(
6633 "replication_optimize_for_static_plugin_config",
6634 "Optional flag that blocks plugin install/uninstall and allows skipping "
6635 "the acquisition of the lock to read from the plugin list and the usage "
6636 "of read-optimized spin-locks. Use only when plugin hook callback needs "
6637 "optimization (a lot of semi-sync slaves, for instance).",
6638 GLOBAL_VAR(opt_replication_optimize_for_static_plugin_config),
6639 CMD_LINE(OPT_ARG),
6640 DEFAULT(FALSE),
6641 NO_MUTEX_GUARD,
6642 NOT_IN_BINLOG,
6643 ON_CHECK(0),
6644 ON_UPDATE(handle_plugin_lock_type_change));
6645
6646 /**
6647 Updates the atomic access version of
6648 `opt_replication_sender_observe_commit_only`.
6649 */
handle_sender_observe_commit_change(sys_var *,THD *,enum_var_type)6650 static bool handle_sender_observe_commit_change(sys_var *, THD *, enum_var_type)
6651 {
6652 DBUG_ENTER("handle_sender_observe_commit_change");
6653 my_atomic_store32(&opt_atomic_replication_sender_observe_commit_only,
6654 opt_replication_sender_observe_commit_only);
6655 DBUG_RETURN(false);
6656 }
6657
6658 static Sys_var_mybool Sys_replication_sender_observe_commit_only(
6659 "replication_sender_observe_commit_only",
6660 "Optional flag that allows for only calling back observer hooks at "
6661 "commit.",
6662 GLOBAL_VAR(opt_replication_sender_observe_commit_only),
6663 CMD_LINE(OPT_ARG),
6664 DEFAULT(FALSE),
6665 NO_MUTEX_GUARD,
6666 NOT_IN_BINLOG,
6667 ON_CHECK(0),
6668 ON_UPDATE(handle_sender_observe_commit_change));
6669
6670 #ifndef NDEBUG
6671 Debug_shutdown_actions Debug_shutdown_actions::instance;
6672 #endif
6673