MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sys_vars.cc
Go to the documentation of this file.
1 /* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
33 #include "my_global.h" /* NO_EMBEDDED_ACCESS_CHECKS */
34 #include "sql_priv.h"
35 #include "sql_class.h" // set_var.h: THD
36 #include "rpl_gtid.h"
37 #include "sys_vars.h"
38 #include "mysql_com.h"
39 
40 #include "events.h"
41 #include <thr_alarm.h>
42 #include "rpl_slave.h"
43 #include "rpl_mi.h"
44 #include "rpl_rli.h"
45 #include "rpl_slave.h"
46 #include "rpl_info_factory.h"
47 #include "transaction.h"
48 #include "opt_trace.h"
49 #include "mysqld.h"
50 #include "lock.h"
51 #include "sql_time.h" // known_date_time_formats
52 #include "sql_acl.h" // SUPER_ACL,
53  // mysql_user_table_is_in_short_password_format
54  // disconnect_on_expired_password
55 #include "derror.h" // read_texts
56 #include "sql_base.h" // close_cached_tables
57 #include "debug_sync.h" // DEBUG_SYNC
58 #include "hostname.h" // host_cache_size
59 #include "sql_show.h" // opt_ignore_db_dirs
60 #include "table_cache.h" // Table_cache_manager
61 
62 #include "log_event.h"
63 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
64 #include "../storage/perfschema/pfs_server.h"
65 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
66 
67 TYPELIB bool_typelib={ array_elements(bool_values)-1, "", bool_values, 0 };
68 
69 /*
70  This forward declaration is needed because including sql_base.h
71  causes further includes. [TODO] Eliminate this forward declaration
72  and include a file with the prototype instead.
73 */
74 extern void close_thread_tables(THD *thd);
75 
76 
77 static bool update_buffer_size(THD *thd, KEY_CACHE *key_cache,
78  ptrdiff_t offset, ulonglong new_value)
79 {
80  bool error= false;
81  DBUG_ASSERT(offset == offsetof(KEY_CACHE, param_buff_size));
82 
83  if (new_value == 0)
84  {
85  if (key_cache == dflt_key_cache)
86  {
87  my_error(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE, MYF(0));
88  return true;
89  }
90 
91  if (key_cache->key_cache_inited) // If initied
92  {
93  /*
94  Move tables using this key cache to the default key cache
95  and clear the old key cache.
96  */
97  key_cache->in_init= 1;
98  mysql_mutex_unlock(&LOCK_global_system_variables);
99  key_cache->param_buff_size= 0;
100  ha_resize_key_cache(key_cache);
101  ha_change_key_cache(key_cache, dflt_key_cache);
102  /*
103  We don't delete the key cache as some running threads my still be in
104  the key cache code with a pointer to the deleted (empty) key cache
105  */
106  mysql_mutex_lock(&LOCK_global_system_variables);
107  key_cache->in_init= 0;
108  }
109  return error;
110  }
111 
112  key_cache->param_buff_size= new_value;
113 
114  /* If key cache didn't exist initialize it, else resize it */
115  key_cache->in_init= 1;
116  mysql_mutex_unlock(&LOCK_global_system_variables);
117 
118  if (!key_cache->key_cache_inited)
119  error= ha_init_key_cache(0, key_cache);
120  else
121  error= ha_resize_key_cache(key_cache);
122 
123  mysql_mutex_lock(&LOCK_global_system_variables);
124  key_cache->in_init= 0;
125 
126  return error;
127 }
128 
129 static bool update_keycache_param(THD *thd, KEY_CACHE *key_cache,
130  ptrdiff_t offset, ulonglong new_value)
131 {
132  bool error= false;
133  DBUG_ASSERT(offset != offsetof(KEY_CACHE, param_buff_size));
134 
135  keycache_var(key_cache, offset)= new_value;
136 
137  key_cache->in_init= 1;
138  mysql_mutex_unlock(&LOCK_global_system_variables);
139  error= ha_resize_key_cache(key_cache);
140 
141  mysql_mutex_lock(&LOCK_global_system_variables);
142  key_cache->in_init= 0;
143 
144  return error;
145 }
146 
147 /*
148  The rule for this file: everything should be 'static'. When a sys_var
149  variable or a function from this file is - in very rare cases - needed
150  elsewhere it should be explicitly declared 'export' here to show that it's
151  not a mistakenly forgotten 'static' keyword.
152 */
153 #define export /* not static */
154 
155 #ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
156 #ifndef EMBEDDED_LIBRARY
157 
158 #define PFS_TRAILING_PROPERTIES \
159  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL), \
160  NULL, sys_var::PARSE_EARLY
161 
162 static Sys_var_mybool Sys_pfs_enabled(
163  "performance_schema",
164  "Enable the performance schema.",
165  READ_ONLY GLOBAL_VAR(pfs_param.m_enabled),
166  CMD_LINE(OPT_ARG), DEFAULT(TRUE),
167  PFS_TRAILING_PROPERTIES);
168 
169 static Sys_var_charptr Sys_pfs_instrument(
170  "performance_schema_instrument",
171  "Default startup value for a performance schema instrument.",
172  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_pfs_instrument),
173  CMD_LINE(OPT_ARG, OPT_PFS_INSTRUMENT),
174  IN_FS_CHARSET,
175  DEFAULT(""),
176  PFS_TRAILING_PROPERTIES);
177 
178 static Sys_var_mybool Sys_pfs_consumer_events_stages_current(
179  "performance_schema_consumer_events_stages_current",
180  "Default startup value for the events_stages_current consumer.",
181  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_stages_current_enabled),
182  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
183  PFS_TRAILING_PROPERTIES);
184 
185 static Sys_var_mybool Sys_pfs_consumer_events_stages_history(
186  "performance_schema_consumer_events_stages_history",
187  "Default startup value for the events_stages_history consumer.",
188  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_stages_history_enabled),
189  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
190  PFS_TRAILING_PROPERTIES);
191 
192 static Sys_var_mybool Sys_pfs_consumer_events_stages_history_long(
193  "performance_schema_consumer_events_stages_history_long",
194  "Default startup value for the events_stages_history_long consumer.",
195  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_stages_history_long_enabled),
196  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
197  PFS_TRAILING_PROPERTIES);
198 
199 static Sys_var_mybool Sys_pfs_consumer_events_statements_current(
200  "performance_schema_consumer_events_statements_current",
201  "Default startup value for the events_statements_current consumer.",
202  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_statements_current_enabled),
203  CMD_LINE(OPT_ARG), DEFAULT(TRUE),
204  PFS_TRAILING_PROPERTIES);
205 
206 static Sys_var_mybool Sys_pfs_consumer_events_statements_history(
207  "performance_schema_consumer_events_statements_history",
208  "Default startup value for the events_statements_history consumer.",
209  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_statements_history_enabled),
210  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
211  PFS_TRAILING_PROPERTIES);
212 
213 static Sys_var_mybool Sys_pfs_consumer_events_statements_history_long(
214  "performance_schema_consumer_events_statements_history_long",
215  "Default startup value for the events_statements_history_long consumer.",
216  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_statements_history_long_enabled),
217  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
218  PFS_TRAILING_PROPERTIES);
219 
220 static Sys_var_mybool Sys_pfs_consumer_events_waits_current(
221  "performance_schema_consumer_events_waits_current",
222  "Default startup value for the events_waits_current consumer.",
223  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_waits_current_enabled),
224  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
225  PFS_TRAILING_PROPERTIES);
226 
227 static Sys_var_mybool Sys_pfs_consumer_events_waits_history(
228  "performance_schema_consumer_events_waits_history",
229  "Default startup value for the events_waits_history consumer.",
230  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_waits_history_enabled),
231  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
232  PFS_TRAILING_PROPERTIES);
233 
234 static Sys_var_mybool Sys_pfs_consumer_events_waits_history_long(
235  "performance_schema_consumer_events_waits_history_long",
236  "Default startup value for the events_waits_history_long consumer.",
237  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_events_waits_history_long_enabled),
238  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
239  PFS_TRAILING_PROPERTIES);
240 
241 static Sys_var_mybool Sys_pfs_consumer_global_instrumentation(
242  "performance_schema_consumer_global_instrumentation",
243  "Default startup value for the global_instrumentation consumer.",
244  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_global_instrumentation_enabled),
245  CMD_LINE(OPT_ARG), DEFAULT(TRUE),
246  PFS_TRAILING_PROPERTIES);
247 
248 static Sys_var_mybool Sys_pfs_consumer_thread_instrumentation(
249  "performance_schema_consumer_thread_instrumentation",
250  "Default startup value for the thread_instrumentation consumer.",
251  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_thread_instrumentation_enabled),
252  CMD_LINE(OPT_ARG), DEFAULT(TRUE),
253  PFS_TRAILING_PROPERTIES);
254 
255 static Sys_var_mybool Sys_pfs_consumer_statement_digest(
256  "performance_schema_consumer_statements_digest",
257  "Default startup value for the statements_digest consumer.",
258  READ_ONLY NOT_VISIBLE GLOBAL_VAR(pfs_param.m_consumer_statement_digest_enabled),
259  CMD_LINE(OPT_ARG), DEFAULT(TRUE),
260  PFS_TRAILING_PROPERTIES);
261 
262 static Sys_var_long Sys_pfs_events_waits_history_long_size(
263  "performance_schema_events_waits_history_long_size",
264  "Number of rows in EVENTS_WAITS_HISTORY_LONG."
265  " Use 0 to disable, -1 for automated sizing.",
266  READ_ONLY GLOBAL_VAR(pfs_param.m_events_waits_history_long_sizing),
267  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
268  DEFAULT(-1),
269  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
270 
271 static Sys_var_long Sys_pfs_events_waits_history_size(
272  "performance_schema_events_waits_history_size",
273  "Number of rows per thread in EVENTS_WAITS_HISTORY."
274  " Use 0 to disable, -1 for automated sizing.",
275  READ_ONLY GLOBAL_VAR(pfs_param.m_events_waits_history_sizing),
276  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024),
277  DEFAULT(-1),
278  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
279 
280 static Sys_var_ulong Sys_pfs_max_cond_classes(
281  "performance_schema_max_cond_classes",
282  "Maximum number of condition instruments.",
283  READ_ONLY GLOBAL_VAR(pfs_param.m_cond_class_sizing),
284  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
285  DEFAULT(PFS_MAX_COND_CLASS),
286  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
287 
288 static Sys_var_long Sys_pfs_max_cond_instances(
289  "performance_schema_max_cond_instances",
290  "Maximum number of instrumented condition objects."
291  " Use 0 to disable, -1 for automated sizing.",
292  READ_ONLY GLOBAL_VAR(pfs_param.m_cond_sizing),
293  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
294  DEFAULT(-1),
295  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
296 
297 static Sys_var_ulong Sys_pfs_max_file_classes(
298  "performance_schema_max_file_classes",
299  "Maximum number of file instruments.",
300  READ_ONLY GLOBAL_VAR(pfs_param.m_file_class_sizing),
301  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
302  DEFAULT(PFS_MAX_FILE_CLASS),
303  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
304 
305 static Sys_var_ulong Sys_pfs_max_file_handles(
306  "performance_schema_max_file_handles",
307  "Maximum number of opened instrumented files.",
308  READ_ONLY GLOBAL_VAR(pfs_param.m_file_handle_sizing),
309  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024),
310  DEFAULT(PFS_MAX_FILE_HANDLE),
311  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
312 
313 static Sys_var_long Sys_pfs_max_file_instances(
314  "performance_schema_max_file_instances",
315  "Maximum number of instrumented files."
316  " Use 0 to disable, -1 for automated sizing.",
317  READ_ONLY GLOBAL_VAR(pfs_param.m_file_sizing),
318  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
319  DEFAULT(-1),
320  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
321 
322 static Sys_var_long Sys_pfs_max_sockets(
323  "performance_schema_max_socket_instances",
324  "Maximum number of opened instrumented sockets."
325  " Use 0 to disable, -1 for automated sizing.",
326  READ_ONLY GLOBAL_VAR(pfs_param.m_socket_sizing),
327  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
328  DEFAULT(-1),
329  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
330 
331 static Sys_var_ulong Sys_pfs_max_socket_classes(
332  "performance_schema_max_socket_classes",
333  "Maximum number of socket instruments.",
334  READ_ONLY GLOBAL_VAR(pfs_param.m_socket_class_sizing),
335  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
336  DEFAULT(PFS_MAX_SOCKET_CLASS),
337  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
338 
339 static Sys_var_ulong Sys_pfs_max_mutex_classes(
340  "performance_schema_max_mutex_classes",
341  "Maximum number of mutex instruments.",
342  READ_ONLY GLOBAL_VAR(pfs_param.m_mutex_class_sizing),
343  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
344  DEFAULT(PFS_MAX_MUTEX_CLASS),
345  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
346 
347 static Sys_var_long Sys_pfs_max_mutex_instances(
348  "performance_schema_max_mutex_instances",
349  "Maximum number of instrumented MUTEX objects."
350  " Use 0 to disable, -1 for automated sizing.",
351  READ_ONLY GLOBAL_VAR(pfs_param.m_mutex_sizing),
352  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 100*1024*1024),
353  DEFAULT(-1),
354  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
355 
356 static Sys_var_ulong Sys_pfs_max_rwlock_classes(
357  "performance_schema_max_rwlock_classes",
358  "Maximum number of rwlock instruments.",
359  READ_ONLY GLOBAL_VAR(pfs_param.m_rwlock_class_sizing),
360  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
361  DEFAULT(PFS_MAX_RWLOCK_CLASS),
362  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
363 
364 static Sys_var_long Sys_pfs_max_rwlock_instances(
365  "performance_schema_max_rwlock_instances",
366  "Maximum number of instrumented RWLOCK objects."
367  " Use 0 to disable, -1 for automated sizing.",
368  READ_ONLY GLOBAL_VAR(pfs_param.m_rwlock_sizing),
369  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 100*1024*1024),
370  DEFAULT(-1),
371  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
372 
373 static Sys_var_long Sys_pfs_max_table_handles(
374  "performance_schema_max_table_handles",
375  "Maximum number of opened instrumented tables."
376  " Use 0 to disable, -1 for automated sizing.",
377  READ_ONLY GLOBAL_VAR(pfs_param.m_table_sizing),
378  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
379  DEFAULT(-1),
380  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
381 
382 static Sys_var_long Sys_pfs_max_table_instances(
383  "performance_schema_max_table_instances",
384  "Maximum number of instrumented tables."
385  " Use 0 to disable, -1 for automated sizing.",
386  READ_ONLY GLOBAL_VAR(pfs_param.m_table_share_sizing),
387  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
388  DEFAULT(-1),
389  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
390 
391 static Sys_var_ulong Sys_pfs_max_thread_classes(
392  "performance_schema_max_thread_classes",
393  "Maximum number of thread instruments.",
394  READ_ONLY GLOBAL_VAR(pfs_param.m_thread_class_sizing),
395  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
396  DEFAULT(PFS_MAX_THREAD_CLASS),
397  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
398 
399 static Sys_var_long Sys_pfs_max_thread_instances(
400  "performance_schema_max_thread_instances",
401  "Maximum number of instrumented threads."
402  " Use 0 to disable, -1 for automated sizing.",
403  READ_ONLY GLOBAL_VAR(pfs_param.m_thread_sizing),
404  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
405  DEFAULT(-1),
406  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
407 
408 static Sys_var_ulong Sys_pfs_setup_actors_size(
409  "performance_schema_setup_actors_size",
410  "Maximum number of rows in SETUP_ACTORS.",
411  READ_ONLY GLOBAL_VAR(pfs_param.m_setup_actor_sizing),
412  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024),
413  DEFAULT(PFS_MAX_SETUP_ACTOR),
414  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
415 
416 static Sys_var_ulong Sys_pfs_setup_objects_size(
417  "performance_schema_setup_objects_size",
418  "Maximum number of rows in SETUP_OBJECTS.",
419  READ_ONLY GLOBAL_VAR(pfs_param.m_setup_object_sizing),
420  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 1024*1024),
421  DEFAULT(PFS_MAX_SETUP_OBJECT),
422  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
423 
424 static Sys_var_long Sys_pfs_accounts_size(
425  "performance_schema_accounts_size",
426  "Maximum number of instrumented user@host accounts."
427  " Use 0 to disable, -1 for automated sizing.",
428  READ_ONLY GLOBAL_VAR(pfs_param.m_account_sizing),
429  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
430  DEFAULT(-1),
431  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
432 
433 static Sys_var_long Sys_pfs_hosts_size(
434  "performance_schema_hosts_size",
435  "Maximum number of instrumented hosts."
436  " Use 0 to disable, -1 for automated sizing.",
437  READ_ONLY GLOBAL_VAR(pfs_param.m_host_sizing),
438  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
439  DEFAULT(-1),
440  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
441 
442 static Sys_var_long Sys_pfs_users_size(
443  "performance_schema_users_size",
444  "Maximum number of instrumented users."
445  " Use 0 to disable, -1 for automated sizing.",
446  READ_ONLY GLOBAL_VAR(pfs_param.m_user_sizing),
447  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
448  DEFAULT(-1),
449  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
450 
451 static Sys_var_ulong Sys_pfs_max_stage_classes(
452  "performance_schema_max_stage_classes",
453  "Maximum number of stage instruments.",
454  READ_ONLY GLOBAL_VAR(pfs_param.m_stage_class_sizing),
455  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
456  DEFAULT(PFS_MAX_STAGE_CLASS),
457  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
458 
459 static Sys_var_long Sys_pfs_events_stages_history_long_size(
460  "performance_schema_events_stages_history_long_size",
461  "Number of rows in EVENTS_STAGES_HISTORY_LONG."
462  " Use 0 to disable, -1 for automated sizing.",
463  READ_ONLY GLOBAL_VAR(pfs_param.m_events_stages_history_long_sizing),
464  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
465  DEFAULT(-1),
466  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
467 
468 static Sys_var_long Sys_pfs_events_stages_history_size(
469  "performance_schema_events_stages_history_size",
470  "Number of rows per thread in EVENTS_STAGES_HISTORY."
471  " Use 0 to disable, -1 for automated sizing.",
472  READ_ONLY GLOBAL_VAR(pfs_param.m_events_stages_history_sizing),
473  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024),
474  DEFAULT(-1),
475  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
476 
487 static Sys_var_ulong Sys_pfs_max_statement_classes(
488  "performance_schema_max_statement_classes",
489  "Maximum number of statement instruments.",
490  READ_ONLY GLOBAL_VAR(pfs_param.m_statement_class_sizing),
491  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 256),
492  DEFAULT((ulong) SQLCOM_END + (ulong) COM_END + 4),
493  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
494 
495 static Sys_var_long Sys_pfs_events_statements_history_long_size(
496  "performance_schema_events_statements_history_long_size",
497  "Number of rows in EVENTS_STATEMENTS_HISTORY_LONG."
498  " Use 0 to disable, -1 for automated sizing.",
500  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024*1024),
501  DEFAULT(-1),
502  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
503 
504 static Sys_var_long Sys_pfs_events_statements_history_size(
505  "performance_schema_events_statements_history_size",
506  "Number of rows per thread in EVENTS_STATEMENTS_HISTORY."
507  " Use 0 to disable, -1 for automated sizing.",
508  READ_ONLY GLOBAL_VAR(pfs_param.m_events_statements_history_sizing),
509  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024),
510  DEFAULT(-1),
511  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
512 
513 static Sys_var_long Sys_pfs_digest_size(
514  "performance_schema_digests_size",
515  "Size of the statement digest."
516  " Use 0 to disable, -1 for automated sizing.",
517  READ_ONLY GLOBAL_VAR(pfs_param.m_digest_sizing),
518  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024 * 1024),
519  DEFAULT(-1),
520  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
521 
522 static Sys_var_long Sys_pfs_connect_attrs_size(
523  "performance_schema_session_connect_attrs_size",
524  "Size of session attribute string buffer per thread."
525  " Use 0 to disable, -1 for automated sizing.",
526  READ_ONLY GLOBAL_VAR(pfs_param.m_session_connect_attrs_sizing),
527  CMD_LINE(REQUIRED_ARG), VALID_RANGE(-1, 1024 * 1024),
528  DEFAULT(-1),
529  BLOCK_SIZE(1), PFS_TRAILING_PROPERTIES);
530 
531 #endif /* EMBEDDED_LIBRARY */
532 #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
533 
534 static Sys_var_ulong Sys_auto_increment_increment(
535  "auto_increment_increment",
536  "Auto-increment columns are incremented by this",
537  SESSION_VAR(auto_increment_increment),
538  CMD_LINE(OPT_ARG),
539  VALID_RANGE(1, 65535), DEFAULT(1), BLOCK_SIZE(1),
540  NO_MUTEX_GUARD, IN_BINLOG);
541 
542 static Sys_var_ulong Sys_auto_increment_offset(
543  "auto_increment_offset",
544  "Offset added to Auto-increment columns. Used when "
545  "auto-increment-increment != 1",
546  SESSION_VAR(auto_increment_offset),
547  CMD_LINE(OPT_ARG),
548  VALID_RANGE(1, 65535), DEFAULT(1), BLOCK_SIZE(1),
549  NO_MUTEX_GUARD, IN_BINLOG);
550 
551 static Sys_var_mybool Sys_automatic_sp_privileges(
552  "automatic_sp_privileges",
553  "Creating and dropping stored procedures alters ACLs",
554  GLOBAL_VAR(sp_automatic_privileges),
555  CMD_LINE(OPT_ARG), DEFAULT(TRUE));
556 
557 static Sys_var_ulong Sys_back_log(
558  "back_log", "The number of outstanding connection requests "
559  "MySQL can have. This comes into play when the main MySQL thread "
560  "gets very many connection requests in a very short time",
561  READ_ONLY GLOBAL_VAR(back_log), CMD_LINE(REQUIRED_ARG),
562  VALID_RANGE(0, 65535), DEFAULT(0), BLOCK_SIZE(1));
563 
564 static Sys_var_charptr Sys_basedir(
565  "basedir", "Path to installation directory. All paths are "
566  "usually resolved relative to this",
567  READ_ONLY GLOBAL_VAR(mysql_home_ptr), CMD_LINE(REQUIRED_ARG, 'b'),
568  IN_FS_CHARSET, DEFAULT(0));
569 
570 static Sys_var_charptr Sys_my_bind_addr(
571  "bind_address", "IP address to bind to.",
572  READ_ONLY GLOBAL_VAR(my_bind_addr_str), CMD_LINE(REQUIRED_ARG),
573  IN_FS_CHARSET, DEFAULT(MY_BIND_ALL_ADDRESSES));
574 
575 static bool fix_binlog_cache_size(sys_var *self, THD *thd, enum_var_type type)
576 {
578  return false;
579 }
580 
581 static bool fix_binlog_stmt_cache_size(sys_var *self, THD *thd, enum_var_type type)
582 {
584  return false;
585 }
586 
587 static Sys_var_ulong Sys_binlog_cache_size(
588  "binlog_cache_size", "The size of the transactional cache for "
589  "updates to transactional engines for the binary log. "
590  "If you often use transactions containing many statements, "
591  "you can increase this to get more performance",
592  GLOBAL_VAR(binlog_cache_size),
593  CMD_LINE(REQUIRED_ARG),
594  VALID_RANGE(IO_SIZE, ULONG_MAX), DEFAULT(32768), BLOCK_SIZE(IO_SIZE),
595  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
596  ON_UPDATE(fix_binlog_cache_size));
597 
598 static Sys_var_ulong Sys_binlog_stmt_cache_size(
599  "binlog_stmt_cache_size", "The size of the statement cache for "
600  "updates to non-transactional engines for the binary log. "
601  "If you often use statements updating a great number of rows, "
602  "you can increase this to get more performance",
603  GLOBAL_VAR(binlog_stmt_cache_size),
604  CMD_LINE(REQUIRED_ARG),
605  VALID_RANGE(IO_SIZE, ULONG_MAX), DEFAULT(32768), BLOCK_SIZE(IO_SIZE),
606  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
607  ON_UPDATE(fix_binlog_stmt_cache_size));
608 
609 static Sys_var_int32 Sys_binlog_max_flush_queue_time(
610  "binlog_max_flush_queue_time",
611  "The maximum time that the binary log group commit will keep reading"
612  " transactions before it flush the transactions to the binary log (and"
613  " optionally sync, depending on the value of sync_binlog).",
614  GLOBAL_VAR(opt_binlog_max_flush_queue_time),
615  CMD_LINE(REQUIRED_ARG),
616  VALID_RANGE(0, 100000), DEFAULT(0), BLOCK_SIZE(1),
617  NO_MUTEX_GUARD, NOT_IN_BINLOG);
618 
619 static bool check_has_super(sys_var *self, THD *thd, set_var *var)
620 {
621  DBUG_ASSERT(self->scope() != sys_var::GLOBAL);// don't abuse check_has_super()
622 #ifndef NO_EMBEDDED_ACCESS_CHECKS
623  if (!(thd->security_ctx->master_access & SUPER_ACL))
624  {
625  my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER");
626  return true;
627  }
628 #endif
629  return false;
630 }
631 
632 #if defined(HAVE_GTID_NEXT_LIST) || defined(NON_DISABLED_GTID) || defined(HAVE_REPLICATION)
633 static bool check_top_level_stmt(sys_var *self, THD *thd, set_var *var)
634 {
635  if (thd->in_sub_stmt)
636  {
637  my_error(ER_VARIABLE_NOT_SETTABLE_IN_SF_OR_TRIGGER, MYF(0), var->var->name.str);
638  return true;
639  }
640  return false;
641 }
642 
643 static bool check_top_level_stmt_and_super(sys_var *self, THD *thd, set_var *var)
644 {
645  return (check_has_super(self, thd, var) ||
646  check_top_level_stmt(self, thd, var));
647 }
648 #endif
649 
650 #if defined(HAVE_GTID_NEXT_LIST) || defined(HAVE_REPLICATION)
651 static bool check_outside_transaction(sys_var *self, THD *thd, set_var *var)
652 {
653  if (thd->in_active_multi_stmt_transaction())
654  {
655  my_error(ER_VARIABLE_NOT_SETTABLE_IN_TRANSACTION, MYF(0), var->var->name.str);
656  return true;
657  }
658  return false;
659 }
660 static bool check_outside_sp(sys_var *self, THD *thd, set_var *var)
661 {
662  if (thd->lex->sphead)
663  {
664  my_error(ER_VARIABLE_NOT_SETTABLE_IN_SP, MYF(0), var->var->name.str);
665  return true;
666  }
667  return false;
668 }
669 #endif
670 
671 static bool binlog_format_check(sys_var *self, THD *thd, set_var *var)
672 {
673  if (check_has_super(self, thd, var))
674  return true;
675 
676  if (var->type == OPT_GLOBAL)
677  return false;
678 
679  /*
680  If RBR and open temporary tables, their CREATE TABLE may not be in the
681  binlog, so we can't toggle to SBR in this connection.
682 
683  If binlog_format=MIXED, there are open temporary tables, and an unsafe
684  statement is executed, then subsequent statements are logged in row
685  format and hence changes to temporary tables may be lost. So we forbid
686  switching @@SESSION.binlog_format from MIXED to STATEMENT when there are
687  open temp tables and we are logging in row format.
688  */
689  if (thd->temporary_tables && var->type == OPT_SESSION &&
690  var->save_result.ulonglong_value == BINLOG_FORMAT_STMT &&
691  ((thd->variables.binlog_format == BINLOG_FORMAT_MIXED &&
692  thd->is_current_stmt_binlog_format_row()) ||
693  thd->variables.binlog_format == BINLOG_FORMAT_ROW))
694  {
695  my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
696  return true;
697  }
698 
699  /*
700  if in a stored function/trigger, it's too late to change mode
701  */
702  if (thd->in_sub_stmt)
703  {
704  my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
705  return true;
706  }
707  /*
708  Make the session variable 'binlog_format' read-only inside a transaction.
709  */
710  if (thd->in_active_multi_stmt_transaction())
711  {
712  my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
713  return true;
714  }
715 
716  return false;
717 }
718 
719 static bool fix_binlog_format_after_update(sys_var *self, THD *thd,
720  enum_var_type type)
721 {
722  if (type == OPT_SESSION)
723  thd->reset_current_stmt_binlog_format_row();
724  return false;
725 }
726 
727 static Sys_var_test_flag Sys_core_file(
728  "core_file", "write a core-file on crashes", TEST_CORE_ON_SIGNAL);
729 
730 static Sys_var_enum Sys_binlog_format(
731  "binlog_format", "What form of binary logging the master will "
732  "use: either ROW for row-based binary logging, STATEMENT "
733  "for statement-based binary logging, or MIXED. MIXED is statement-"
734  "based binary logging except for those statements where only row-"
735  "based is correct: those which involve user-defined functions (i.e. "
736  "UDFs) or the UUID() function; for those, row-based binary logging is "
737  "automatically used. If NDBCLUSTER is enabled and binlog-format is "
738  "MIXED, the format switches to row-based and back implicitly per each "
739  "query accessing an NDBCLUSTER table",
740  SESSION_VAR(binlog_format), CMD_LINE(REQUIRED_ARG, OPT_BINLOG_FORMAT),
741  binlog_format_names, DEFAULT(BINLOG_FORMAT_STMT),
742  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_format_check),
743  ON_UPDATE(fix_binlog_format_after_update));
744 
745 static const char *binlog_row_image_names[]= {"MINIMAL", "NOBLOB", "FULL", NullS};
746 static Sys_var_enum Sys_binlog_row_image(
747  "binlog_row_image",
748  "Controls whether rows should be logged in 'FULL', 'NOBLOB' or "
749  "'MINIMAL' formats. 'FULL', means that all columns in the before "
750  "and after image are logged. 'NOBLOB', means that mysqld avoids logging "
751  "blob columns whenever possible (eg, blob column was not changed or "
752  "is not part of primary key). 'MINIMAL', means that a PK equivalent (PK "
753  "columns or full row if there is no PK in the table) is logged in the "
754  "before image, and only changed columns are logged in the after image. "
755  "(Default: FULL).",
756  SESSION_VAR(binlog_row_image), CMD_LINE(REQUIRED_ARG),
757  binlog_row_image_names, DEFAULT(BINLOG_ROW_IMAGE_FULL),
758  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
759  ON_UPDATE(NULL));
760 
761 static bool binlog_direct_check(sys_var *self, THD *thd, set_var *var)
762 {
763  if (check_has_super(self, thd, var))
764  return true;
765 
766  if (var->type == OPT_GLOBAL)
767  return false;
768 
769  /*
770  Makes the session variable 'binlog_direct_non_transactional_updates'
771  read-only if within a procedure, trigger or function.
772  */
773  if (thd->in_sub_stmt)
774  {
775  my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0));
776  return true;
777  }
778  /*
779  Makes the session variable 'binlog_direct_non_transactional_updates'
780  read-only inside a transaction.
781  */
782  if (thd->in_active_multi_stmt_transaction())
783  {
784  my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_BINLOG_DIRECT, MYF(0));
785  return true;
786  }
787 
788  return false;
789 }
790 
791 static Sys_var_mybool Sys_binlog_direct(
792  "binlog_direct_non_transactional_updates",
793  "Causes updates to non-transactional engines using statement format to "
794  "be written directly to binary log. Before using this option make sure "
795  "that there are no dependencies between transactional and "
796  "non-transactional tables such as in the statement INSERT INTO t_myisam "
797  "SELECT * FROM t_innodb; otherwise, slaves may diverge from the master.",
798  SESSION_VAR(binlog_direct_non_trans_update),
799  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
800  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(binlog_direct_check));
801 
812 static Sys_var_mybool Sys_explicit_defaults_for_timestamp(
813  "explicit_defaults_for_timestamp",
814  "This option causes CREATE TABLE to create all TIMESTAMP columns "
815  "as NULL with DEFAULT NULL attribute, Without this option, "
816  "TIMESTAMP columns are NOT NULL and have implicit DEFAULT clauses. "
817  "The old behavior is deprecated.",
818  READ_ONLY SESSION_VAR(explicit_defaults_for_timestamp),
819  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
820 
821 static bool repository_check(sys_var *self, THD *thd, set_var *var, SLAVE_THD_TYPE thread_mask)
822 {
823  bool ret= FALSE;
824 #ifndef NO_EMBEDDED_ACCESS_CHECKS
825  if (!(thd->security_ctx->master_access & SUPER_ACL))
826  {
827  my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER");
828  return TRUE;
829  }
830 #endif
831 #ifdef HAVE_REPLICATION
832  int running= 0;
833  const char *msg= NULL;
834  mysql_mutex_lock(&LOCK_active_mi);
835  if (active_mi != NULL)
836  {
837  lock_slave_threads(active_mi);
838  init_thread_mask(&running, active_mi, FALSE);
839  if(!running)
840  {
841  switch (thread_mask)
842  {
843  case SLAVE_THD_IO:
844  if (Rpl_info_factory::change_mi_repository(active_mi,
845  var->save_result.ulonglong_value,
846  &msg))
847  {
848  ret= TRUE;
849  my_error(ER_CHANGE_RPL_INFO_REPOSITORY_FAILURE, MYF(0), msg);
850  }
851  break;
852  case SLAVE_THD_SQL:
853  mts_recovery_groups(active_mi->rli);
854  if (!active_mi->rli->is_mts_recovery())
855  {
856  if (Rpl_info_factory::reset_workers(active_mi->rli) ||
857  Rpl_info_factory::change_rli_repository(active_mi->rli,
858  var->save_result.ulonglong_value,
859  &msg))
860  {
861  ret= TRUE;
862  my_error(ER_CHANGE_RPL_INFO_REPOSITORY_FAILURE, MYF(0), msg);
863  }
864  }
865  else
866  sql_print_warning("It is not possible to change the type of the "
867  "relay log's repository because there are workers' "
868  "repositories with gaps. Please, fix the gaps first "
869  "before doing such change.");
870  break;
871  default:
872  assert(0);
873  break;
874  }
875  }
876  else
877  {
878  ret= TRUE;
879  my_error(ER_SLAVE_MUST_STOP, MYF(0));
880  }
881  unlock_slave_threads(active_mi);
882  }
883  mysql_mutex_unlock(&LOCK_active_mi);
884 #endif
885  return ret;
886 }
887 
888 static bool relay_log_info_repository_check(sys_var *self, THD *thd, set_var *var)
889 {
890  return repository_check(self, thd, var, SLAVE_THD_SQL);
891 }
892 
893 static bool master_info_repository_check(sys_var *self, THD *thd, set_var *var)
894 {
895  return repository_check(self, thd, var, SLAVE_THD_IO);
896 }
897 
898 static const char *repository_names[]=
899 {
900  "FILE", "TABLE",
901 #ifndef DBUG_OFF
902  "DUMMY",
903 #endif
904  0
905 };
906 
907 ulong opt_mi_repository_id= INFO_REPOSITORY_FILE;
908 static Sys_var_enum Sys_mi_repository(
909  "master_info_repository",
910  "Defines the type of the repository for the master information."
911  ,GLOBAL_VAR(opt_mi_repository_id), CMD_LINE(REQUIRED_ARG),
912  repository_names, DEFAULT(INFO_REPOSITORY_FILE), NO_MUTEX_GUARD,
913  NOT_IN_BINLOG, ON_CHECK(master_info_repository_check),
914  ON_UPDATE(0));
915 
916 ulong opt_rli_repository_id= INFO_REPOSITORY_FILE;
917 static Sys_var_enum Sys_rli_repository(
918  "relay_log_info_repository",
919  "Defines the type of the repository for the relay log information "
920  "and associated workers."
921  ,GLOBAL_VAR(opt_rli_repository_id), CMD_LINE(REQUIRED_ARG),
922  repository_names, DEFAULT(INFO_REPOSITORY_FILE), NO_MUTEX_GUARD,
923  NOT_IN_BINLOG, ON_CHECK(relay_log_info_repository_check),
924  ON_UPDATE(0));
925 
926 static Sys_var_mybool Sys_binlog_rows_query(
927  "binlog_rows_query_log_events",
928  "Allow writing of Rows_query_log events into binary log.",
929  SESSION_VAR(binlog_rows_query_log_events),
930  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
931 
932 static Sys_var_mybool Sys_binlog_order_commits(
933  "binlog_order_commits",
934  "Issue internal commit calls in the same order as transactions are"
935  " written to the binary log. Default is to order commits.",
936  GLOBAL_VAR(opt_binlog_order_commits),
937  CMD_LINE(OPT_ARG), DEFAULT(TRUE));
938 
939 static Sys_var_ulong Sys_bulk_insert_buff_size(
940  "bulk_insert_buffer_size", "Size of tree cache used in bulk "
941  "insert optimisation. Note that this is a limit per thread!",
942  SESSION_VAR(bulk_insert_buff_size), CMD_LINE(REQUIRED_ARG),
943  VALID_RANGE(0, ULONG_MAX), DEFAULT(8192*1024), BLOCK_SIZE(1));
944 
945 static Sys_var_charptr Sys_character_sets_dir(
946  "character_sets_dir", "Directory where character sets are",
947  READ_ONLY GLOBAL_VAR(charsets_dir), CMD_LINE(REQUIRED_ARG),
948  IN_FS_CHARSET, DEFAULT(0));
949 
950 static bool check_not_null(sys_var *self, THD *thd, set_var *var)
951 {
952  return var->value && var->value->is_null();
953 }
954 static bool check_charset(sys_var *self, THD *thd, set_var *var)
955 {
956  if (!var->value)
957  return false;
958 
959  char buff[STRING_BUFFER_USUAL_SIZE];
960  if (var->value->result_type() == STRING_RESULT)
961  {
962  String str(buff, sizeof(buff), system_charset_info), *res;
963  if (!(res= var->value->val_str(&str)))
964  var->save_result.ptr= NULL;
965  else
966  {
967  ErrConvString err(res); /* Get utf8 '\0' terminated string */
968  if (!(var->save_result.ptr= get_charset_by_csname(err.ptr(),
969  MY_CS_PRIMARY,
970  MYF(0))) &&
971  !(var->save_result.ptr= get_old_charset_by_name(err.ptr())))
972  {
973  my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), err.ptr());
974  return true;
975  }
976  }
977  }
978  else // INT_RESULT
979  {
980  int csno= (int)var->value->val_int();
981  if (!(var->save_result.ptr= get_charset(csno, MYF(0))))
982  {
983  my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), llstr(csno, buff));
984  return true;
985  }
986  }
987  return false;
988 }
989 static bool check_charset_not_null(sys_var *self, THD *thd, set_var *var)
990 {
991  return check_charset(self, thd, var) || check_not_null(self, thd, var);
992 }
993 static Sys_var_struct Sys_character_set_system(
994  "character_set_system", "The character set used by the server "
995  "for storing identifiers",
996  READ_ONLY GLOBAL_VAR(system_charset_info), NO_CMD_LINE,
997  offsetof(CHARSET_INFO, csname), DEFAULT(0));
998 
999 static Sys_var_struct Sys_character_set_server(
1000  "character_set_server", "The default character set",
1001  SESSION_VAR(collation_server), NO_CMD_LINE,
1002  offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1003  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_not_null));
1004 
1005 static bool check_charset_db(sys_var *self, THD *thd, set_var *var)
1006 {
1007  if (check_charset_not_null(self, thd, var))
1008  return true;
1009  if (!var->value) // = DEFAULT
1010  var->save_result.ptr= thd->db_charset;
1011  return false;
1012 }
1013 static Sys_var_struct Sys_character_set_database(
1014  "character_set_database",
1015  " The character set used by the default database",
1016  SESSION_VAR(collation_database), NO_CMD_LINE,
1017  offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1018  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_db));
1019 
1020 static bool check_cs_client(sys_var *self, THD *thd, set_var *var)
1021 {
1022  if (check_charset_not_null(self, thd, var))
1023  return true;
1024 
1025  // Currently, UCS-2 cannot be used as a client character set
1026  if (((CHARSET_INFO *)(var->save_result.ptr))->mbminlen > 1)
1027  return true;
1028 
1029  return false;
1030 }
1031 static bool fix_thd_charset(sys_var *self, THD *thd, enum_var_type type)
1032 {
1033  if (type == OPT_SESSION)
1034  thd->update_charset();
1035  return false;
1036 }
1037 static Sys_var_struct Sys_character_set_client(
1038  "character_set_client", "The character set for statements "
1039  "that arrive from the client",
1040  SESSION_VAR(character_set_client), NO_CMD_LINE,
1041  offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1042  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_cs_client),
1043  ON_UPDATE(fix_thd_charset));
1044 
1045 static Sys_var_struct Sys_character_set_connection(
1046  "character_set_connection", "The character set used for "
1047  "literals that do not have a character set introducer and for "
1048  "number-to-string conversion",
1049  SESSION_VAR(collation_connection), NO_CMD_LINE,
1050  offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1051  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_charset_not_null),
1052  ON_UPDATE(fix_thd_charset));
1053 
1054 static Sys_var_struct Sys_character_set_results(
1055  "character_set_results", "The character set used for returning "
1056  "query results to the client",
1057  SESSION_VAR(character_set_results), NO_CMD_LINE,
1058  offsetof(CHARSET_INFO, csname), DEFAULT(&default_charset_info),
1059  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_charset));
1060 
1061 static Sys_var_struct Sys_character_set_filesystem(
1062  "character_set_filesystem", "The filesystem character set",
1063  SESSION_VAR(character_set_filesystem), NO_CMD_LINE,
1064  offsetof(CHARSET_INFO, csname), DEFAULT(&character_set_filesystem),
1065  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_charset_not_null),
1066  ON_UPDATE(fix_thd_charset));
1067 
1068 static const char *completion_type_names[]= {"NO_CHAIN", "CHAIN", "RELEASE", 0};
1069 static Sys_var_enum Sys_completion_type(
1070  "completion_type", "The transaction completion type, one of "
1071  "NO_CHAIN, CHAIN, RELEASE",
1072  SESSION_VAR(completion_type), CMD_LINE(REQUIRED_ARG),
1073  completion_type_names, DEFAULT(0));
1074 
1075 static bool check_collation_not_null(sys_var *self, THD *thd, set_var *var)
1076 {
1077  if (!var->value)
1078  return false;
1079 
1080  char buff[STRING_BUFFER_USUAL_SIZE];
1081  if (var->value->result_type() == STRING_RESULT)
1082  {
1083  String str(buff, sizeof(buff), system_charset_info), *res;
1084  if (!(res= var->value->val_str(&str)))
1085  var->save_result.ptr= NULL;
1086  else
1087  {
1088  ErrConvString err(res); /* Get utf8 '\0'-terminated string */
1089  if (!(var->save_result.ptr= get_charset_by_name(err.ptr(), MYF(0))))
1090  {
1091  my_error(ER_UNKNOWN_COLLATION, MYF(0), err.ptr());
1092  return true;
1093  }
1094  }
1095  }
1096  else // INT_RESULT
1097  {
1098  int csno= (int)var->value->val_int();
1099  if (!(var->save_result.ptr= get_charset(csno, MYF(0))))
1100  {
1101  my_error(ER_UNKNOWN_COLLATION, MYF(0), llstr(csno, buff));
1102  return true;
1103  }
1104  }
1105  return check_not_null(self, thd, var);
1106 }
1107 static Sys_var_struct Sys_collation_connection(
1108  "collation_connection", "The collation of the connection "
1109  "character set",
1110  SESSION_VAR(collation_connection), NO_CMD_LINE,
1111  offsetof(CHARSET_INFO, name), DEFAULT(&default_charset_info),
1112  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_collation_not_null),
1113  ON_UPDATE(fix_thd_charset));
1114 
1115 static bool check_collation_db(sys_var *self, THD *thd, set_var *var)
1116 {
1117  if (check_collation_not_null(self, thd, var))
1118  return true;
1119  if (!var->value) // = DEFAULT
1120  var->save_result.ptr= thd->db_charset;
1121  return false;
1122 }
1123 static Sys_var_struct Sys_collation_database(
1124  "collation_database", "The collation of the database "
1125  "character set",
1126  SESSION_VAR(collation_database), NO_CMD_LINE,
1127  offsetof(CHARSET_INFO, name), DEFAULT(&default_charset_info),
1128  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_collation_db));
1129 
1130 static Sys_var_struct Sys_collation_server(
1131  "collation_server", "The server default collation",
1132  SESSION_VAR(collation_server), NO_CMD_LINE,
1133  offsetof(CHARSET_INFO, name), DEFAULT(&default_charset_info),
1134  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_collation_not_null));
1135 
1136 static const char *concurrent_insert_names[]= {"NEVER", "AUTO", "ALWAYS", 0};
1137 static Sys_var_enum Sys_concurrent_insert(
1138  "concurrent_insert", "Use concurrent insert with MyISAM. Possible "
1139  "values are NEVER, AUTO, ALWAYS",
1140  GLOBAL_VAR(myisam_concurrent_insert), CMD_LINE(OPT_ARG),
1141  concurrent_insert_names, DEFAULT(1));
1142 
1143 static Sys_var_ulong Sys_connect_timeout(
1144  "connect_timeout",
1145  "The number of seconds the mysqld server is waiting for a connect "
1146  "packet before responding with 'Bad handshake'",
1147  GLOBAL_VAR(connect_timeout), CMD_LINE(REQUIRED_ARG),
1148  VALID_RANGE(2, LONG_TIMEOUT), DEFAULT(CONNECT_TIMEOUT), BLOCK_SIZE(1));
1149 
1150 static Sys_var_charptr Sys_datadir(
1151  "datadir", "Path to the database root directory",
1152  READ_ONLY GLOBAL_VAR(mysql_real_data_home_ptr),
1153  CMD_LINE(REQUIRED_ARG, 'h'), IN_FS_CHARSET, DEFAULT(mysql_real_data_home));
1154 
1155 #ifndef DBUG_OFF
1156 static Sys_var_dbug Sys_dbug(
1157  "debug", "Debug log", sys_var::SESSION,
1158  CMD_LINE(OPT_ARG, '#'), DEFAULT(""), NO_MUTEX_GUARD, NOT_IN_BINLOG,
1159  ON_CHECK(check_has_super));
1160 #endif
1161 
1168 export bool fix_delay_key_write(sys_var *self, THD *thd, enum_var_type type)
1169 {
1170  switch (delay_key_write_options) {
1171  case DELAY_KEY_WRITE_NONE:
1172  myisam_delay_key_write=0;
1173  break;
1174  case DELAY_KEY_WRITE_ON:
1175  myisam_delay_key_write=1;
1176  break;
1177  case DELAY_KEY_WRITE_ALL:
1178  myisam_delay_key_write=1;
1179  ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
1180  break;
1181  }
1182  return false;
1183 }
1184 static const char *delay_key_write_names[]= { "OFF", "ON", "ALL", NullS };
1185 static Sys_var_enum Sys_delay_key_write(
1186  "delay_key_write", "Type of DELAY_KEY_WRITE",
1187  GLOBAL_VAR(delay_key_write_options), CMD_LINE(OPT_ARG),
1188  delay_key_write_names, DEFAULT(DELAY_KEY_WRITE_ON),
1189  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1190  ON_UPDATE(fix_delay_key_write));
1191 
1192 static Sys_var_ulong Sys_delayed_insert_limit(
1193  "delayed_insert_limit",
1194  "After inserting delayed_insert_limit rows, the INSERT DELAYED "
1195  "handler will check if there are any SELECT statements pending. "
1196  "If so, it allows these to execute before continuing. "
1197  "This variable is deprecated along with INSERT DELAYED.",
1198  GLOBAL_VAR(delayed_insert_limit), CMD_LINE(REQUIRED_ARG),
1199  VALID_RANGE(1, ULONG_MAX), DEFAULT(DELAYED_LIMIT), BLOCK_SIZE(1),
1200  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
1201  DEPRECATED(""));
1202 
1203 static Sys_var_ulong Sys_delayed_insert_timeout(
1204  "delayed_insert_timeout",
1205  "How long a INSERT DELAYED thread should wait for INSERT statements "
1206  "before terminating."
1207  "This variable is deprecated along with INSERT DELAYED.",
1208  GLOBAL_VAR(delayed_insert_timeout), CMD_LINE(REQUIRED_ARG),
1209  VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(DELAYED_WAIT_TIMEOUT),
1210  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1211  ON_UPDATE(0), DEPRECATED(""));
1212 
1213 static Sys_var_ulong Sys_delayed_queue_size(
1214  "delayed_queue_size",
1215  "What size queue (in rows) should be allocated for handling INSERT "
1216  "DELAYED. If the queue becomes full, any client that does INSERT "
1217  "DELAYED will wait until there is room in the queue again."
1218  "This variable is deprecated along with INSERT DELAYED.",
1219  GLOBAL_VAR(delayed_queue_size), CMD_LINE(REQUIRED_ARG),
1220  VALID_RANGE(1, ULONG_MAX), DEFAULT(DELAYED_QUEUE_SIZE), BLOCK_SIZE(1),
1221  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
1222  DEPRECATED(""));
1223 
1224 #ifdef HAVE_EVENT_SCHEDULER
1225 static const char *event_scheduler_names[]= { "OFF", "ON", "DISABLED", NullS };
1226 static bool event_scheduler_check(sys_var *self, THD *thd, set_var *var)
1227 {
1228  /* DISABLED is only accepted on the command line */
1229  if (var->save_result.ulonglong_value == Events::EVENTS_DISABLED)
1230  return true;
1231  /*
1232  If the scheduler was disabled because there are no/bad
1233  system tables, produce a more meaningful error message
1234  than ER_OPTION_PREVENTS_STATEMENT
1235  */
1237  return true;
1238  if (Events::opt_event_scheduler == Events::EVENTS_DISABLED)
1239  {
1240  my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
1241  "--event-scheduler=DISABLED or --skip-grant-tables");
1242  return true;
1243  }
1244  return false;
1245 }
1246 static bool event_scheduler_update(sys_var *self, THD *thd, enum_var_type type)
1247 {
1248  int err_no= 0;
1249  uint opt_event_scheduler_value= Events::opt_event_scheduler;
1250  mysql_mutex_unlock(&LOCK_global_system_variables);
1251  /*
1252  Events::start() is heavyweight. In particular it creates a new THD,
1253  which takes LOCK_global_system_variables internally.
1254  Thus we have to release it here.
1255  We need to re-take it before returning, though.
1256 
1257  Note that since we release LOCK_global_system_variables before calling
1258  start/stop, there is a possibility that the server variable
1259  can become out of sync with the real event scheduler state.
1260 
1261  This can happen with two concurrent statments if the first gets
1262  interrupted after start/stop but before retaking
1263  LOCK_global_system_variables. However, this problem should be quite
1264  rare and it's difficult to avoid it without opening up possibilities
1265  for deadlocks. See bug#51160.
1266  */
1267  bool ret= opt_event_scheduler_value == Events::EVENTS_ON
1268  ? Events::start(&err_no)
1269  : Events::stop();
1270  mysql_mutex_lock(&LOCK_global_system_variables);
1271  if (ret)
1272  {
1273  Events::opt_event_scheduler= Events::EVENTS_OFF;
1274  my_error(ER_EVENT_SET_VAR_ERROR, MYF(0), err_no);
1275  }
1276  return ret;
1277 }
1278 
1279 static Sys_var_enum Sys_event_scheduler(
1280  "event_scheduler", "Enable the event scheduler. Possible values are "
1281  "ON, OFF, and DISABLED (keep the event scheduler completely "
1282  "deactivated, it cannot be activated run-time)",
1283  GLOBAL_VAR(Events::opt_event_scheduler), CMD_LINE(OPT_ARG),
1284  event_scheduler_names, DEFAULT(Events::EVENTS_OFF),
1285  NO_MUTEX_GUARD, NOT_IN_BINLOG,
1286  ON_CHECK(event_scheduler_check), ON_UPDATE(event_scheduler_update));
1287 #endif
1288 
1289 static Sys_var_ulong Sys_expire_logs_days(
1290  "expire_logs_days",
1291  "If non-zero, binary logs will be purged after expire_logs_days "
1292  "days; possible purges happen at startup and at binary log rotation",
1293  GLOBAL_VAR(expire_logs_days),
1294  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 99), DEFAULT(0), BLOCK_SIZE(1));
1295 
1296 static Sys_var_mybool Sys_flush(
1297  "flush", "Flush MyISAM tables to disk between SQL commands",
1298  GLOBAL_VAR(myisam_flush),
1299  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1300 
1301 static Sys_var_ulong Sys_flush_time(
1302  "flush_time",
1303  "A dedicated thread is created to flush all tables at the "
1304  "given interval",
1305  GLOBAL_VAR(flush_time),
1306  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, LONG_TIMEOUT),
1307  DEFAULT(0), BLOCK_SIZE(1));
1308 
1309 static bool check_ftb_syntax(sys_var *self, THD *thd, set_var *var)
1310 {
1311  return ft_boolean_check_syntax_string((uchar*)
1312  (var->save_result.string_value.str));
1313 }
1314 static bool query_cache_flush(sys_var *self, THD *thd, enum_var_type type)
1315 {
1316 #ifdef HAVE_QUERY_CACHE
1317  query_cache.flush();
1318 #endif /* HAVE_QUERY_CACHE */
1319  return false;
1320 }
1322 static Sys_var_charptr Sys_ft_boolean_syntax(
1323  "ft_boolean_syntax", "List of operators for "
1324  "MATCH ... AGAINST ( ... IN BOOLEAN MODE)",
1325  GLOBAL_VAR(ft_boolean_syntax),
1326  CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
1327  DEFAULT(DEFAULT_FTB_SYNTAX), NO_MUTEX_GUARD,
1328  NOT_IN_BINLOG, ON_CHECK(check_ftb_syntax), ON_UPDATE(query_cache_flush));
1329 
1330 static Sys_var_ulong Sys_ft_max_word_len(
1331  "ft_max_word_len",
1332  "The maximum length of the word to be included in a FULLTEXT index. "
1333  "Note: FULLTEXT indexes must be rebuilt after changing this variable",
1334  READ_ONLY GLOBAL_VAR(ft_max_word_len), CMD_LINE(REQUIRED_ARG),
1335  VALID_RANGE(10, HA_FT_MAXCHARLEN), DEFAULT(HA_FT_MAXCHARLEN),
1336  BLOCK_SIZE(1));
1337 
1338 static Sys_var_ulong Sys_ft_min_word_len(
1339  "ft_min_word_len",
1340  "The minimum length of the word to be included in a FULLTEXT index. "
1341  "Note: FULLTEXT indexes must be rebuilt after changing this variable",
1342  READ_ONLY GLOBAL_VAR(ft_min_word_len), CMD_LINE(REQUIRED_ARG),
1343  VALID_RANGE(1, HA_FT_MAXCHARLEN), DEFAULT(4), BLOCK_SIZE(1));
1344 
1346 static Sys_var_ulong Sys_ft_query_expansion_limit(
1347  "ft_query_expansion_limit",
1348  "Number of best matches to use for query expansion",
1349  READ_ONLY GLOBAL_VAR(ft_query_expansion_limit),
1350  CMD_LINE(REQUIRED_ARG),
1351  VALID_RANGE(0, 1000), DEFAULT(20), BLOCK_SIZE(1));
1352 
1353 static Sys_var_charptr Sys_ft_stopword_file(
1354  "ft_stopword_file",
1355  "Use stopwords from this file instead of built-in list",
1356  READ_ONLY GLOBAL_VAR(ft_stopword_file), CMD_LINE(REQUIRED_ARG),
1357  IN_FS_CHARSET, DEFAULT(0));
1358 
1359 static Sys_var_mybool Sys_ignore_builtin_innodb(
1360  "ignore_builtin_innodb",
1361  "IGNORED. This option will be removed in future releases. "
1362  "Disable initialization of builtin InnoDB plugin",
1363  READ_ONLY GLOBAL_VAR(opt_ignore_builtin_innodb),
1364  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1365 
1366 static bool check_init_string(sys_var *self, THD *thd, set_var *var)
1367 {
1368  if (var->save_result.string_value.str == 0)
1369  {
1370  var->save_result.string_value.str= const_cast<char*>("");
1371  var->save_result.string_value.length= 0;
1372  }
1373  return false;
1374 }
1375 static PolyLock_rwlock PLock_sys_init_connect(&LOCK_sys_init_connect);
1376 static Sys_var_lexstring Sys_init_connect(
1377  "init_connect", "Command(s) that are executed for each "
1378  "new connection", GLOBAL_VAR(opt_init_connect),
1379  CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
1380  DEFAULT(""), &PLock_sys_init_connect, NOT_IN_BINLOG,
1381  ON_CHECK(check_init_string));
1382 
1383 static Sys_var_charptr Sys_init_file(
1384  "init_file", "Read SQL commands from this file at startup",
1385  READ_ONLY GLOBAL_VAR(opt_init_file),
1386 #ifdef DISABLE_GRANT_OPTIONS
1387  NO_CMD_LINE,
1388 #else
1389  CMD_LINE(REQUIRED_ARG),
1390 #endif
1391  IN_FS_CHARSET, DEFAULT(0));
1392 
1393 static PolyLock_rwlock PLock_sys_init_slave(&LOCK_sys_init_slave);
1394 static Sys_var_lexstring Sys_init_slave(
1395  "init_slave", "Command(s) that are executed by a slave server "
1396  "each time the SQL thread starts", GLOBAL_VAR(opt_init_slave),
1397  CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
1398  DEFAULT(""), &PLock_sys_init_slave,
1399  NOT_IN_BINLOG, ON_CHECK(check_init_string));
1400 
1401 static Sys_var_ulong Sys_interactive_timeout(
1402  "interactive_timeout",
1403  "The number of seconds the server waits for activity on an interactive "
1404  "connection before closing it",
1405  SESSION_VAR(net_interactive_timeout),
1406  CMD_LINE(REQUIRED_ARG),
1407  VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(NET_WAIT_TIMEOUT), BLOCK_SIZE(1));
1408 
1409 static Sys_var_ulong Sys_join_buffer_size(
1410  "join_buffer_size",
1411  "The size of the buffer that is used for full joins",
1412  SESSION_VAR(join_buff_size), CMD_LINE(REQUIRED_ARG),
1413  VALID_RANGE(128, ULONG_MAX), DEFAULT(256 * 1024), BLOCK_SIZE(128));
1414 
1415 static Sys_var_keycache Sys_key_buffer_size(
1416  "key_buffer_size", "The size of the buffer used for "
1417  "index blocks for MyISAM tables. Increase this to get better index "
1418  "handling (for all reads and multiple writes) to as much as you can "
1419  "afford",
1420  KEYCACHE_VAR(param_buff_size),
1421  CMD_LINE(REQUIRED_ARG, OPT_KEY_BUFFER_SIZE),
1422  VALID_RANGE(0, SIZE_T_MAX), DEFAULT(KEY_CACHE_SIZE),
1423  BLOCK_SIZE(IO_SIZE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1424  ON_UPDATE(update_buffer_size));
1425 
1426 static Sys_var_keycache Sys_key_cache_block_size(
1427  "key_cache_block_size", "The default size of key cache blocks",
1428  KEYCACHE_VAR(param_block_size),
1429  CMD_LINE(REQUIRED_ARG, OPT_KEY_CACHE_BLOCK_SIZE),
1430  VALID_RANGE(512, 1024*16), DEFAULT(KEY_CACHE_BLOCK_SIZE),
1431  BLOCK_SIZE(512), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1432  ON_UPDATE(update_keycache_param));
1433 
1434 static Sys_var_keycache Sys_key_cache_division_limit(
1435  "key_cache_division_limit",
1436  "The minimum percentage of warm blocks in key cache",
1437  KEYCACHE_VAR(param_division_limit),
1438  CMD_LINE(REQUIRED_ARG, OPT_KEY_CACHE_DIVISION_LIMIT),
1439  VALID_RANGE(1, 100), DEFAULT(100),
1440  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1441  ON_UPDATE(update_keycache_param));
1442 
1443 static Sys_var_keycache Sys_key_cache_age_threshold(
1444  "key_cache_age_threshold", "This characterizes the number of "
1445  "hits a hot block has to be untouched until it is considered aged "
1446  "enough to be downgraded to a warm block. This specifies the "
1447  "percentage ratio of that number of hits to the total number of "
1448  "blocks in key cache",
1449  KEYCACHE_VAR(param_age_threshold),
1450  CMD_LINE(REQUIRED_ARG, OPT_KEY_CACHE_AGE_THRESHOLD),
1451  VALID_RANGE(100, ULONG_MAX), DEFAULT(300),
1452  BLOCK_SIZE(100), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1453  ON_UPDATE(update_keycache_param));
1454 
1455 static Sys_var_mybool Sys_large_files_support(
1456  "large_files_support",
1457  "Whether mysqld was compiled with options for large file support",
1458  READ_ONLY GLOBAL_VAR(opt_large_files),
1459  NO_CMD_LINE, DEFAULT(sizeof(my_off_t) > 4));
1460 
1461 static Sys_var_uint Sys_large_page_size(
1462  "large_page_size",
1463  "If large page support is enabled, this shows the size of memory pages",
1464  READ_ONLY GLOBAL_VAR(opt_large_page_size), NO_CMD_LINE,
1465  VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
1466 
1467 static Sys_var_mybool Sys_large_pages(
1468  "large_pages", "Enable support for large pages",
1469  READ_ONLY GLOBAL_VAR(opt_large_pages),
1470  IF_WIN(NO_CMD_LINE, CMD_LINE(OPT_ARG)), DEFAULT(FALSE));
1471 
1472 static Sys_var_charptr Sys_language(
1473  "lc_messages_dir", "Directory where error messages are",
1474  READ_ONLY GLOBAL_VAR(lc_messages_dir_ptr),
1475  CMD_LINE(REQUIRED_ARG, OPT_LC_MESSAGES_DIRECTORY),
1476  IN_FS_CHARSET, DEFAULT(0));
1477 
1478 static Sys_var_mybool Sys_local_infile(
1479  "local_infile", "Enable LOAD DATA LOCAL INFILE",
1480  GLOBAL_VAR(opt_local_infile), CMD_LINE(OPT_ARG), DEFAULT(TRUE));
1481 
1482 static Sys_var_ulong Sys_lock_wait_timeout(
1483  "lock_wait_timeout",
1484  "Timeout in seconds to wait for a lock before returning an error.",
1485  SESSION_VAR(lock_wait_timeout), CMD_LINE(REQUIRED_ARG),
1486  VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(LONG_TIMEOUT), BLOCK_SIZE(1));
1487 
1488 #ifdef HAVE_MLOCKALL
1489 static Sys_var_mybool Sys_locked_in_memory(
1490  "locked_in_memory",
1491  "Whether mysqld was locked in memory with --memlock",
1492  READ_ONLY GLOBAL_VAR(locked_in_memory), NO_CMD_LINE, DEFAULT(FALSE));
1493 #endif
1494 
1495 /* this says NO_CMD_LINE, as command-line option takes a string, not a bool */
1496 static Sys_var_mybool Sys_log_bin(
1497  "log_bin", "Whether the binary log is enabled",
1498  READ_ONLY GLOBAL_VAR(opt_bin_log), NO_CMD_LINE, DEFAULT(FALSE));
1499 
1500 static Sys_var_ulong Sys_rpl_stop_slave_timeout(
1501  "rpl_stop_slave_timeout",
1502  "Timeout in seconds to wait for slave to stop before returning a "
1503  "warning.",
1504  GLOBAL_VAR(rpl_stop_slave_timeout), CMD_LINE(REQUIRED_ARG),
1505  VALID_RANGE(2, LONG_TIMEOUT), DEFAULT(LONG_TIMEOUT), BLOCK_SIZE(1));
1506 
1507 static Sys_var_mybool Sys_trust_function_creators(
1508  "log_bin_trust_function_creators",
1509  "If set to FALSE (the default), then when --log-bin is used, creation "
1510  "of a stored function (or trigger) is allowed only to users having the "
1511  "SUPER privilege and only if this stored function (trigger) may not "
1512  "break binary logging. Note that if ALL connections to this server "
1513  "ALWAYS use row-based binary logging, the security issues do not "
1514  "exist and the binary logging cannot break, so you can safely set "
1515  "this to TRUE",
1516  GLOBAL_VAR(trust_function_creators),
1517  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1518 
1519 static Sys_var_mybool Sys_use_v1_row_events(
1520  "log_bin_use_v1_row_events",
1521  "If equal to 1 then version 1 row events are written to a row based "
1522  "binary log. If equal to 0, then the latest version of events are "
1523  "written. "
1524  "This option is useful during some upgrades.",
1525  GLOBAL_VAR(log_bin_use_v1_row_events),
1526  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1527 
1528 static Sys_var_charptr Sys_log_error(
1529  "log_error", "Error log file",
1530  READ_ONLY GLOBAL_VAR(log_error_file_ptr),
1531  CMD_LINE(OPT_ARG, OPT_LOG_ERROR),
1532  IN_FS_CHARSET, DEFAULT(disabled_my_option));
1533 
1534 static Sys_var_mybool Sys_log_queries_not_using_indexes(
1535  "log_queries_not_using_indexes",
1536  "Log queries that are executed without benefit of any index to the "
1537  "slow log if it is open",
1538  GLOBAL_VAR(opt_log_queries_not_using_indexes),
1539  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1540 
1541 static Sys_var_mybool Sys_log_slow_admin_statements(
1542  "log_slow_admin_statements",
1543  "Log slow OPTIMIZE, ANALYZE, ALTER and other administrative statements to "
1544  "the slow log if it is open.",
1545  GLOBAL_VAR(opt_log_slow_admin_statements),
1546  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1547 
1548 static Sys_var_mybool Sys_log_slow_slave_statements(
1549  "log_slow_slave_statements",
1550  "Log slow statements executed by slave thread to the slow log if it is open.",
1551  GLOBAL_VAR(opt_log_slow_slave_statements),
1552  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
1553 
1554 static bool update_log_throttle_queries_not_using_indexes(sys_var *self,
1555  THD *thd,
1556  enum_var_type type)
1557 {
1558  // Check if we should print a summary of any suppressed lines to the slow log
1559  // now since opt_log_throttle_queries_not_using_indexes was changed.
1560  log_throttle_qni.flush(thd);
1561  return false;
1562 }
1563 
1564 static Sys_var_ulong Sys_log_throttle_queries_not_using_indexes(
1565  "log_throttle_queries_not_using_indexes",
1566  "Log at most this many 'not using index' warnings per minute to the "
1567  "slow log. Any further warnings will be condensed into a single "
1568  "summary line. A value of 0 disables throttling. "
1569  "Option has no effect unless --log_queries_not_using_indexes is set.",
1570  GLOBAL_VAR(opt_log_throttle_queries_not_using_indexes),
1571  CMD_LINE(OPT_ARG),
1572  VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1),
1573  NO_MUTEX_GUARD, NOT_IN_BINLOG,
1574  ON_CHECK(0),
1575  ON_UPDATE(update_log_throttle_queries_not_using_indexes));
1576 
1577 static Sys_var_ulong Sys_log_warnings(
1578  "log_warnings",
1579  "Log some not critical warnings to the log file",
1580  GLOBAL_VAR(log_warnings),
1581  CMD_LINE(OPT_ARG, 'W'),
1582  VALID_RANGE(0, ULONG_MAX), DEFAULT(1), BLOCK_SIZE(1));
1583 
1584 static bool update_cached_long_query_time(sys_var *self, THD *thd,
1585  enum_var_type type)
1586 {
1587  if (type == OPT_SESSION)
1588  thd->variables.long_query_time=
1589  double2ulonglong(thd->variables.long_query_time_double * 1e6);
1590  else
1591  global_system_variables.long_query_time=
1592  double2ulonglong(global_system_variables.long_query_time_double * 1e6);
1593  return false;
1594 }
1595 
1596 static Sys_var_double Sys_long_query_time(
1597  "long_query_time",
1598  "Log all queries that have taken more than long_query_time seconds "
1599  "to execute to file. The argument will be treated as a decimal value "
1600  "with microsecond precision",
1601  SESSION_VAR(long_query_time_double),
1602  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(10),
1603  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1604  ON_UPDATE(update_cached_long_query_time));
1605 
1606 static bool fix_low_prio_updates(sys_var *self, THD *thd, enum_var_type type)
1607 {
1608  if (type == OPT_SESSION)
1609  thd->update_lock_default= (thd->variables.low_priority_updates ?
1610  TL_WRITE_LOW_PRIORITY : TL_WRITE);
1611  else
1612  thr_upgraded_concurrent_insert_lock=
1613  (global_system_variables.low_priority_updates ?
1614  TL_WRITE_LOW_PRIORITY : TL_WRITE);
1615  return false;
1616 }
1617 static Sys_var_mybool Sys_low_priority_updates(
1618  "low_priority_updates",
1619  "INSERT/DELETE/UPDATE has lower priority than selects",
1620  SESSION_VAR(low_priority_updates),
1621  CMD_LINE(OPT_ARG),
1622  DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1623  ON_UPDATE(fix_low_prio_updates));
1624 
1625 static Sys_var_mybool Sys_lower_case_file_system(
1626  "lower_case_file_system",
1627  "Case sensitivity of file names on the file system where the "
1628  "data directory is located",
1629  READ_ONLY GLOBAL_VAR(lower_case_file_system), NO_CMD_LINE,
1630  DEFAULT(FALSE));
1631 
1632 static Sys_var_uint Sys_lower_case_table_names(
1633  "lower_case_table_names",
1634  "If set to 1 table names are stored in lowercase on disk and table "
1635  "names will be case-insensitive. Should be set to 2 if you are using "
1636  "a case insensitive file system",
1637  READ_ONLY GLOBAL_VAR(lower_case_table_names),
1638  CMD_LINE(OPT_ARG, OPT_LOWER_CASE_TABLE_NAMES),
1639  VALID_RANGE(0, 2),
1640 #ifdef FN_NO_CASE_SENSE
1641  DEFAULT(1),
1642 #else
1643  DEFAULT(0),
1644 #endif
1645  BLOCK_SIZE(1));
1646 
1647 static bool session_readonly(sys_var *self, THD *thd, set_var *var)
1648 {
1649  if (var->type == OPT_GLOBAL)
1650  return false;
1651  my_error(ER_VARIABLE_IS_READONLY, MYF(0), "SESSION",
1652  self->name.str, "GLOBAL");
1653  return true;
1654 }
1655 
1656 static bool
1657 check_max_allowed_packet(sys_var *self, THD *thd, set_var *var)
1658 {
1659  longlong val;
1660  if (session_readonly(self, thd, var))
1661  return true;
1662 
1663  val= var->save_result.ulonglong_value;
1664  if (val < (longlong) global_system_variables.net_buffer_length)
1665  {
1666  push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
1667  WARN_OPTION_BELOW_LIMIT, ER(WARN_OPTION_BELOW_LIMIT),
1668  "max_allowed_packet", "net_buffer_length");
1669  }
1670  return false;
1671 }
1672 
1673 
1674 static Sys_var_ulong Sys_max_allowed_packet(
1675  "max_allowed_packet",
1676  "Max packet length to send to or receive from the server",
1677  SESSION_VAR(max_allowed_packet), CMD_LINE(REQUIRED_ARG),
1678  VALID_RANGE(1024, 1024 * 1024 * 1024), DEFAULT(4096 * 1024),
1679  BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG,
1680  ON_CHECK(check_max_allowed_packet));
1681 
1682 static Sys_var_ulong Sys_slave_max_allowed_packet(
1683  "slave_max_allowed_packet",
1684  "The maximum packet length to sent successfully from the master to slave.",
1685  GLOBAL_VAR(slave_max_allowed_packet), CMD_LINE(REQUIRED_ARG),
1686  VALID_RANGE(1024, MAX_MAX_ALLOWED_PACKET),
1687  DEFAULT(MAX_MAX_ALLOWED_PACKET),
1688  BLOCK_SIZE(1024));
1689 
1690 static Sys_var_ulonglong Sys_max_binlog_cache_size(
1691  "max_binlog_cache_size",
1692  "Sets the total size of the transactional cache",
1693  GLOBAL_VAR(max_binlog_cache_size), CMD_LINE(REQUIRED_ARG),
1694  VALID_RANGE(IO_SIZE, ULONGLONG_MAX),
1695  DEFAULT((ULONGLONG_MAX/IO_SIZE)*IO_SIZE),
1696  BLOCK_SIZE(IO_SIZE),
1697  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1698  ON_UPDATE(fix_binlog_cache_size));
1699 
1700 static Sys_var_ulonglong Sys_max_binlog_stmt_cache_size(
1701  "max_binlog_stmt_cache_size",
1702  "Sets the total size of the statement cache",
1703  GLOBAL_VAR(max_binlog_stmt_cache_size), CMD_LINE(REQUIRED_ARG),
1704  VALID_RANGE(IO_SIZE, ULONGLONG_MAX),
1705  DEFAULT((ULONGLONG_MAX/IO_SIZE)*IO_SIZE),
1706  BLOCK_SIZE(IO_SIZE),
1707  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1708  ON_UPDATE(fix_binlog_stmt_cache_size));
1709 
1710 static bool fix_max_binlog_size(sys_var *self, THD *thd, enum_var_type type)
1711 {
1712  mysql_bin_log.set_max_size(max_binlog_size);
1713 #ifdef HAVE_REPLICATION
1714  if (active_mi != NULL && !max_relay_log_size)
1715  active_mi->rli->relay_log.set_max_size(max_binlog_size);
1716 #endif
1717  return false;
1718 }
1719 static Sys_var_ulong Sys_max_binlog_size(
1720  "max_binlog_size",
1721  "Binary log will be rotated automatically when the size exceeds this "
1722  "value. Will also apply to relay logs if max_relay_log_size is 0",
1723  GLOBAL_VAR(max_binlog_size), CMD_LINE(REQUIRED_ARG),
1724  VALID_RANGE(IO_SIZE, 1024*1024L*1024L), DEFAULT(1024*1024L*1024L),
1725  BLOCK_SIZE(IO_SIZE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1726  ON_UPDATE(fix_max_binlog_size));
1727 
1728 static bool fix_max_connections(sys_var *self, THD *thd, enum_var_type type)
1729 {
1730 #ifndef EMBEDDED_LIBRARY
1731  resize_thr_alarm(max_connections +
1732  global_system_variables.max_insert_delayed_threads + 10);
1733 #endif
1734  return false;
1735 }
1736 
1737 static Sys_var_ulong Sys_max_connections(
1738  "max_connections", "The number of simultaneous clients allowed",
1739  GLOBAL_VAR(max_connections), CMD_LINE(REQUIRED_ARG),
1740  VALID_RANGE(1, 100000),
1741  DEFAULT(MAX_CONNECTIONS_DEFAULT),
1742  BLOCK_SIZE(1),
1743  NO_MUTEX_GUARD,
1744  NOT_IN_BINLOG,
1745  ON_CHECK(0),
1746  ON_UPDATE(fix_max_connections),
1747  NULL,
1748  /* max_connections is used as a sizing hint by the performance schema. */
1749  sys_var::PARSE_EARLY);
1750 
1751 static Sys_var_ulong Sys_max_connect_errors(
1752  "max_connect_errors",
1753  "If there is more than this number of interrupted connections from "
1754  "a host this host will be blocked from further connections",
1755  GLOBAL_VAR(max_connect_errors), CMD_LINE(REQUIRED_ARG),
1756  VALID_RANGE(1, ULONG_MAX), DEFAULT(100),
1757  BLOCK_SIZE(1));
1758 
1759 static bool check_max_delayed_threads(sys_var *self, THD *thd, set_var *var)
1760 {
1761  return var->type != OPT_GLOBAL &&
1762  var->save_result.ulonglong_value != 0 &&
1763  var->save_result.ulonglong_value !=
1764  global_system_variables.max_insert_delayed_threads;
1765 }
1766 
1767 // Alias for max_delayed_threads
1768 static Sys_var_ulong Sys_max_insert_delayed_threads(
1769  "max_insert_delayed_threads",
1770  "Don't start more than this number of threads to handle INSERT "
1771  "DELAYED statements. If set to zero INSERT DELAYED will be not used."
1772  "This variable is deprecated along with INSERT DELAYED.",
1773  SESSION_VAR(max_insert_delayed_threads),
1774  NO_CMD_LINE, VALID_RANGE(0, 16384), DEFAULT(20),
1775  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG,
1776  ON_CHECK(check_max_delayed_threads), ON_UPDATE(fix_max_connections),
1777  DEPRECATED(""));
1778 
1779 static Sys_var_ulong Sys_max_delayed_threads(
1780  "max_delayed_threads",
1781  "Don't start more than this number of threads to handle INSERT "
1782  "DELAYED statements. If set to zero INSERT DELAYED will be not used."
1783  "This variable is deprecated along with INSERT DELAYED.",
1784  SESSION_VAR(max_insert_delayed_threads),
1785  CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 16384), DEFAULT(20),
1786  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG,
1787  ON_CHECK(check_max_delayed_threads), ON_UPDATE(fix_max_connections),
1788  DEPRECATED(""));
1789 
1790 static Sys_var_ulong Sys_max_error_count(
1791  "max_error_count",
1792  "Max number of errors/warnings to store for a statement",
1793  SESSION_VAR(max_error_count), CMD_LINE(REQUIRED_ARG),
1794  VALID_RANGE(0, 65535), DEFAULT(DEFAULT_ERROR_COUNT), BLOCK_SIZE(1));
1795 
1796 static Sys_var_ulonglong Sys_max_heap_table_size(
1797  "max_heap_table_size",
1798  "Don't allow creation of heap tables bigger than this",
1799  SESSION_VAR(max_heap_table_size), CMD_LINE(REQUIRED_ARG),
1800  VALID_RANGE(16384, (ulonglong)~(intptr)0), DEFAULT(16*1024*1024),
1801  BLOCK_SIZE(1024));
1802 
1803 static Sys_var_ulong Sys_metadata_locks_cache_size(
1804  "metadata_locks_cache_size", "Size of unused metadata locks cache",
1805  READ_ONLY GLOBAL_VAR(mdl_locks_cache_size), CMD_LINE(REQUIRED_ARG),
1806  VALID_RANGE(1, 1024*1024), DEFAULT(MDL_LOCKS_CACHE_SIZE_DEFAULT),
1807  BLOCK_SIZE(1));
1808 
1809 static Sys_var_ulong Sys_metadata_locks_hash_instances(
1810  "metadata_locks_hash_instances", "Number of metadata locks hash instances",
1811  READ_ONLY GLOBAL_VAR(mdl_locks_hash_partitions), CMD_LINE(REQUIRED_ARG),
1812  VALID_RANGE(1, 1024), DEFAULT(MDL_LOCKS_HASH_PARTITIONS_DEFAULT),
1813  BLOCK_SIZE(1));
1814 
1815 static Sys_var_ulong Sys_pseudo_thread_id(
1816  "pseudo_thread_id",
1817  "This variable is for internal server use",
1818  SESSION_ONLY(pseudo_thread_id),
1819  NO_CMD_LINE, VALID_RANGE(0, ULONG_MAX), DEFAULT(0),
1820  BLOCK_SIZE(1), NO_MUTEX_GUARD, IN_BINLOG,
1821  ON_CHECK(check_has_super));
1822 
1823 static bool fix_max_join_size(sys_var *self, THD *thd, enum_var_type type)
1824 {
1825  SV *sv= type == OPT_GLOBAL ? &global_system_variables : &thd->variables;
1826  if (sv->max_join_size == HA_POS_ERROR)
1827  sv->option_bits|= OPTION_BIG_SELECTS;
1828  else
1829  sv->option_bits&= ~OPTION_BIG_SELECTS;
1830  return false;
1831 }
1832 static Sys_var_harows Sys_max_join_size(
1833  "max_join_size",
1834  "Joins that are probably going to read more than max_join_size "
1835  "records return an error",
1836  SESSION_VAR(max_join_size), CMD_LINE(REQUIRED_ARG),
1837  VALID_RANGE(1, HA_POS_ERROR), DEFAULT(HA_POS_ERROR), BLOCK_SIZE(1),
1838  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1839  ON_UPDATE(fix_max_join_size));
1840 
1841 static Sys_var_ulong Sys_max_seeks_for_key(
1842  "max_seeks_for_key",
1843  "Limit assumed max number of seeks when looking up rows based on a key",
1844  SESSION_VAR(max_seeks_for_key), CMD_LINE(REQUIRED_ARG),
1845  VALID_RANGE(1, ULONG_MAX), DEFAULT(ULONG_MAX), BLOCK_SIZE(1));
1846 
1847 static Sys_var_ulong Sys_max_length_for_sort_data(
1848  "max_length_for_sort_data",
1849  "Max number of bytes in sorted records",
1850  SESSION_VAR(max_length_for_sort_data), CMD_LINE(REQUIRED_ARG),
1851  VALID_RANGE(4, 8192*1024L), DEFAULT(1024), BLOCK_SIZE(1));
1852 
1853 static PolyLock_mutex PLock_prepared_stmt_count(&LOCK_prepared_stmt_count);
1854 static Sys_var_ulong Sys_max_prepared_stmt_count(
1855  "max_prepared_stmt_count",
1856  "Maximum number of prepared statements in the server",
1857  GLOBAL_VAR(max_prepared_stmt_count), CMD_LINE(REQUIRED_ARG),
1858  VALID_RANGE(0, 1024*1024), DEFAULT(16382), BLOCK_SIZE(1),
1859  &PLock_prepared_stmt_count);
1860 
1861 static bool fix_max_relay_log_size(sys_var *self, THD *thd, enum_var_type type)
1862 {
1863 #ifdef HAVE_REPLICATION
1864  if (active_mi != NULL)
1865  active_mi->rli->relay_log.set_max_size(max_relay_log_size ?
1866  max_relay_log_size: max_binlog_size);
1867 #endif
1868  return false;
1869 }
1870 static Sys_var_ulong Sys_max_relay_log_size(
1871  "max_relay_log_size",
1872  "If non-zero: relay log will be rotated automatically when the "
1873  "size exceeds this value; if zero: when the size "
1874  "exceeds max_binlog_size",
1875  GLOBAL_VAR(max_relay_log_size), CMD_LINE(REQUIRED_ARG),
1876  VALID_RANGE(0, 1024L*1024*1024), DEFAULT(0), BLOCK_SIZE(IO_SIZE),
1877  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1878  ON_UPDATE(fix_max_relay_log_size));
1879 
1880 static Sys_var_ulong Sys_max_sort_length(
1881  "max_sort_length",
1882  "The number of bytes to use when sorting BLOB or TEXT values (only "
1883  "the first max_sort_length bytes of each value are used; the rest "
1884  "are ignored)",
1885  SESSION_VAR(max_sort_length), CMD_LINE(REQUIRED_ARG),
1886  VALID_RANGE(4, 8192*1024L), DEFAULT(1024), BLOCK_SIZE(1));
1887 
1888 static Sys_var_ulong Sys_max_sp_recursion_depth(
1889  "max_sp_recursion_depth",
1890  "Maximum stored procedure recursion depth",
1891  SESSION_VAR(max_sp_recursion_depth), CMD_LINE(OPT_ARG),
1892  VALID_RANGE(0, 255), DEFAULT(0), BLOCK_SIZE(1));
1893 
1894 // non-standard session_value_ptr() here
1895 static Sys_var_max_user_conn Sys_max_user_connections(
1896  "max_user_connections",
1897  "The maximum number of active connections for a single user "
1898  "(0 = no limit)",
1899  SESSION_VAR(max_user_connections), CMD_LINE(REQUIRED_ARG),
1900  VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
1901  NOT_IN_BINLOG, ON_CHECK(session_readonly));
1902 
1903 static Sys_var_ulong Sys_max_tmp_tables(
1904  "max_tmp_tables",
1905  "Maximum number of temporary tables a client can keep open at a time",
1906  SESSION_VAR(max_tmp_tables), CMD_LINE(REQUIRED_ARG),
1907  VALID_RANGE(1, ULONG_MAX), DEFAULT(32), BLOCK_SIZE(1), NO_MUTEX_GUARD,
1908  NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED(""));
1909 
1910 static Sys_var_ulong Sys_max_write_lock_count(
1911  "max_write_lock_count",
1912  "After this many write locks, allow some read locks to run in between",
1913  GLOBAL_VAR(max_write_lock_count), CMD_LINE(REQUIRED_ARG),
1914  VALID_RANGE(1, ULONG_MAX), DEFAULT(ULONG_MAX), BLOCK_SIZE(1));
1915 
1916 static Sys_var_ulong Sys_min_examined_row_limit(
1917  "min_examined_row_limit",
1918  "Don't write queries to slow log that examine fewer rows "
1919  "than that",
1920  SESSION_VAR(min_examined_row_limit), CMD_LINE(REQUIRED_ARG),
1921  VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
1922 
1923 #ifdef _WIN32
1924 static Sys_var_mybool Sys_named_pipe(
1925  "named_pipe", "Enable the named pipe (NT)",
1926  READ_ONLY GLOBAL_VAR(opt_enable_named_pipe), CMD_LINE(OPT_ARG),
1927  DEFAULT(FALSE));
1928 #endif
1929 
1930 
1931 static bool
1932 check_net_buffer_length(sys_var *self, THD *thd, set_var *var)
1933 {
1934  longlong val;
1935  if (session_readonly(self, thd, var))
1936  return true;
1937 
1938  val= var->save_result.ulonglong_value;
1939  if (val > (longlong) global_system_variables.max_allowed_packet)
1940  {
1941  push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
1942  WARN_OPTION_BELOW_LIMIT, ER(WARN_OPTION_BELOW_LIMIT),
1943  "max_allowed_packet", "net_buffer_length");
1944  }
1945  return false;
1946 }
1947 static Sys_var_ulong Sys_net_buffer_length(
1948  "net_buffer_length",
1949  "Buffer length for TCP/IP and socket communication",
1950  SESSION_VAR(net_buffer_length), CMD_LINE(REQUIRED_ARG),
1951  VALID_RANGE(1024, 1024*1024), DEFAULT(16384), BLOCK_SIZE(1024),
1952  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_net_buffer_length));
1953 
1954 static bool fix_net_read_timeout(sys_var *self, THD *thd, enum_var_type type)
1955 {
1956  if (type != OPT_GLOBAL)
1957  my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
1958  return false;
1959 }
1960 static Sys_var_ulong Sys_net_read_timeout(
1961  "net_read_timeout",
1962  "Number of seconds to wait for more data from a connection before "
1963  "aborting the read",
1964  SESSION_VAR(net_read_timeout), CMD_LINE(REQUIRED_ARG),
1965  VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(NET_READ_TIMEOUT), BLOCK_SIZE(1),
1966  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1967  ON_UPDATE(fix_net_read_timeout));
1968 
1969 static bool fix_net_write_timeout(sys_var *self, THD *thd, enum_var_type type)
1970 {
1971  if (type != OPT_GLOBAL)
1972  my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
1973  return false;
1974 }
1975 static Sys_var_ulong Sys_net_write_timeout(
1976  "net_write_timeout",
1977  "Number of seconds to wait for a block to be written to a connection "
1978  "before aborting the write",
1979  SESSION_VAR(net_write_timeout), CMD_LINE(REQUIRED_ARG),
1980  VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(NET_WRITE_TIMEOUT), BLOCK_SIZE(1),
1981  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1982  ON_UPDATE(fix_net_write_timeout));
1983 
1984 static bool fix_net_retry_count(sys_var *self, THD *thd, enum_var_type type)
1985 {
1986  if (type != OPT_GLOBAL)
1987  thd->net.retry_count=thd->variables.net_retry_count;
1988  return false;
1989 }
1990 static Sys_var_ulong Sys_net_retry_count(
1991  "net_retry_count",
1992  "If a read on a communication port is interrupted, retry this "
1993  "many times before giving up",
1994  SESSION_VAR(net_retry_count), CMD_LINE(REQUIRED_ARG),
1995  VALID_RANGE(1, ULONG_MAX), DEFAULT(MYSQLD_NET_RETRY_COUNT),
1996  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
1997  ON_UPDATE(fix_net_retry_count));
1998 
1999 static Sys_var_mybool Sys_new_mode(
2000  "new", "Use very new possible \"unsafe\" functions",
2001  SESSION_VAR(new_mode), CMD_LINE(OPT_ARG, 'n'), DEFAULT(FALSE));
2002 
2003 static Sys_var_mybool Sys_old_mode(
2004  "old", "Use compatible behavior",
2005  READ_ONLY GLOBAL_VAR(old_mode), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2006 
2007 static Sys_var_mybool Sys_old_alter_table(
2008  "old_alter_table", "Use old, non-optimized alter table",
2009  SESSION_VAR(old_alter_table), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2010 
2011 static Sys_var_uint Sys_old_passwords(
2012  "old_passwords",
2013  "Determine which hash algorithm to use when generating passwords using "
2014  "the PASSWORD() function",
2015  SESSION_VAR(old_passwords), CMD_LINE(REQUIRED_ARG),
2016  VALID_RANGE(0, 2), DEFAULT(0), BLOCK_SIZE(1));
2017 
2018 static Sys_var_ulong Sys_open_files_limit(
2019  "open_files_limit",
2020  "If this is not 0, then mysqld will use this value to reserve file "
2021  "descriptors to use with setrlimit(). If this value is 0 then mysqld "
2022  "will reserve max_connections*5 or max_connections + table_cache*2 "
2023  "(whichever is larger) number of file descriptors",
2024  READ_ONLY GLOBAL_VAR(open_files_limit), CMD_LINE(REQUIRED_ARG),
2025  VALID_RANGE(0, OS_FILE_LIMIT), DEFAULT(0), BLOCK_SIZE(1),
2026  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL), ON_UPDATE(NULL),
2027  NULL,
2028  /* open_files_limit is used as a sizing hint by the performance schema. */
2029  sys_var::PARSE_EARLY);
2030 
2032 static Sys_var_ulong Sys_optimizer_prune_level(
2033  "optimizer_prune_level",
2034  "Controls the heuristic(s) applied during query optimization to prune "
2035  "less-promising partial plans from the optimizer search space. "
2036  "Meaning: 0 - do not apply any heuristic, thus perform exhaustive "
2037  "search; 1 - prune plans based on number of retrieved rows",
2038  SESSION_VAR(optimizer_prune_level), CMD_LINE(REQUIRED_ARG),
2039  VALID_RANGE(0, 1), DEFAULT(1), BLOCK_SIZE(1));
2040 
2041 static Sys_var_ulong Sys_optimizer_search_depth(
2042  "optimizer_search_depth",
2043  "Maximum depth of search performed by the query optimizer. Values "
2044  "larger than the number of relations in a query result in better "
2045  "query plans, but take longer to compile a query. Values smaller "
2046  "than the number of tables in a relation result in faster "
2047  "optimization, but may produce very bad query plans. If set to 0, "
2048  "the system will automatically pick a reasonable value",
2049  SESSION_VAR(optimizer_search_depth), CMD_LINE(REQUIRED_ARG),
2050  VALID_RANGE(0, MAX_TABLES+1), DEFAULT(MAX_TABLES+1), BLOCK_SIZE(1));
2051 
2052 static const char *optimizer_switch_names[]=
2053 {
2054  "index_merge", "index_merge_union", "index_merge_sort_union",
2055  "index_merge_intersection", "engine_condition_pushdown",
2056  "index_condition_pushdown" , "mrr", "mrr_cost_based",
2057  "block_nested_loop", "batched_key_access",
2058 #ifdef OPTIMIZER_SWITCH_ALL
2059  "materialization", "semijoin", "loosescan", "firstmatch",
2060  "subquery_materialization_cost_based",
2061 #endif
2062  "use_index_extensions", "default", NullS
2063 };
2065 static bool fix_optimizer_switch(sys_var *self, THD *thd,
2066  enum_var_type type)
2067 {
2068  SV *sv= (type == OPT_GLOBAL) ? &global_system_variables : &thd->variables;
2069  sv->engine_condition_pushdown=
2070  test(sv->optimizer_switch & OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN);
2071 
2072  return false;
2073 }
2074 static Sys_var_flagset Sys_optimizer_switch(
2075  "optimizer_switch",
2076  "optimizer_switch=option=val[,option=val...], where option is one of "
2077  "{index_merge, index_merge_union, index_merge_sort_union, "
2078  "index_merge_intersection, engine_condition_pushdown, "
2079  "index_condition_pushdown, mrr, mrr_cost_based"
2080 #ifdef OPTIMIZER_SWITCH_ALL
2081  ", materialization, semijoin, loosescan, firstmatch,"
2082  " subquery_materialization_cost_based"
2083 #endif
2084  ", block_nested_loop, batched_key_access, use_index_extensions"
2085  "} and val is one of {on, off, default}",
2086  SESSION_VAR(optimizer_switch), CMD_LINE(REQUIRED_ARG),
2087  optimizer_switch_names, DEFAULT(OPTIMIZER_SWITCH_DEFAULT),
2088  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
2089  ON_UPDATE(fix_optimizer_switch));
2090 
2091 static Sys_var_mybool Sys_var_end_markers_in_json(
2092  "end_markers_in_json",
2093  "In JSON output (\"EXPLAIN FORMAT=JSON\" and optimizer trace), "
2094  "if variable is set to 1, repeats the structure's key (if it has one) "
2095  "near the closing bracket",
2096  SESSION_VAR(end_markers_in_json), CMD_LINE(OPT_ARG),
2097  DEFAULT(FALSE));
2098 
2099 #ifdef OPTIMIZER_TRACE
2100 
2101 static Sys_var_flagset Sys_optimizer_trace(
2102  "optimizer_trace",
2103  "Controls tracing of the Optimizer:"
2104  " optimizer_trace=option=val[,option=val...], where option is one of"
2105  " {enabled, one_line}"
2106  " and val is one of {on, default}",
2107  SESSION_VAR(optimizer_trace), CMD_LINE(REQUIRED_ARG),
2108  Opt_trace_context::flag_names,
2109  DEFAULT(Opt_trace_context::FLAG_DEFAULT));
2110 // @see set_var::is_var_optimizer_trace()
2111 export sys_var *Sys_optimizer_trace_ptr= &Sys_optimizer_trace;
2112 
2117 static Sys_var_flagset Sys_optimizer_trace_features(
2118  "optimizer_trace_features",
2119  "Enables/disables tracing of selected features of the Optimizer:"
2120  " optimizer_trace_features=option=val[,option=val...], where option is one of"
2121  " {greedy_search, range_optimizer, dynamic_range, repeated_subselect}"
2122  " and val is one of {on, off, default}",
2123  SESSION_VAR(optimizer_trace_features), CMD_LINE(REQUIRED_ARG),
2124  Opt_trace_context::feature_names,
2125  DEFAULT(Opt_trace_context::default_features));
2126 
2128 static bool optimizer_trace_update(sys_var *self, THD *thd,
2129  enum_var_type type)
2130 {
2131  thd->opt_trace.reset();
2132  return false;
2133 }
2134 
2135 static Sys_var_long Sys_optimizer_trace_offset(
2136  "optimizer_trace_offset",
2137  "Offset of first optimizer trace to show; see manual",
2138  SESSION_VAR(optimizer_trace_offset), CMD_LINE(REQUIRED_ARG),
2139  VALID_RANGE(LONG_MIN, LONG_MAX), DEFAULT(-1), BLOCK_SIZE(1),
2140  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
2141  ON_UPDATE(optimizer_trace_update));
2142 
2143 static Sys_var_long Sys_optimizer_trace_limit(
2144  "optimizer_trace_limit",
2145  "Maximum number of shown optimizer traces",
2146  SESSION_VAR(optimizer_trace_limit), CMD_LINE(REQUIRED_ARG),
2147  VALID_RANGE(0, LONG_MAX), DEFAULT(1), BLOCK_SIZE(1),
2148  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
2149  ON_UPDATE(optimizer_trace_update));
2150 
2151 static Sys_var_ulong Sys_optimizer_trace_max_mem_size(
2152  "optimizer_trace_max_mem_size",
2153  "Maximum allowed cumulated size of stored optimizer traces",
2154  SESSION_VAR(optimizer_trace_max_mem_size), CMD_LINE(REQUIRED_ARG),
2155  VALID_RANGE(0, ULONG_MAX), DEFAULT(1024*16), BLOCK_SIZE(1));
2156 
2157 #endif
2158 
2159 static Sys_var_charptr Sys_pid_file(
2160  "pid_file", "Pid file used by safe_mysqld",
2161  READ_ONLY GLOBAL_VAR(pidfile_name_ptr), CMD_LINE(REQUIRED_ARG),
2162  IN_FS_CHARSET, DEFAULT(0));
2163 
2164 static Sys_var_charptr Sys_plugin_dir(
2165  "plugin_dir", "Directory for plugins",
2166  READ_ONLY GLOBAL_VAR(opt_plugin_dir_ptr), CMD_LINE(REQUIRED_ARG),
2167  IN_FS_CHARSET, DEFAULT(0));
2168 
2169 static Sys_var_uint Sys_port(
2170  "port",
2171  "Port number to use for connection or 0 to default to, "
2172  "my.cnf, $MYSQL_TCP_PORT, "
2173 #if MYSQL_PORT_DEFAULT == 0
2174  "/etc/services, "
2175 #endif
2176  "built-in default (" STRINGIFY_ARG(MYSQL_PORT) "), whatever comes first",
2177  READ_ONLY GLOBAL_VAR(mysqld_port), CMD_LINE(REQUIRED_ARG, 'P'),
2178  VALID_RANGE(0, UINT_MAX32), DEFAULT(0), BLOCK_SIZE(1));
2179 
2180 static Sys_var_ulong Sys_preload_buff_size(
2181  "preload_buffer_size",
2182  "The size of the buffer that is allocated when preloading indexes",
2183  SESSION_VAR(preload_buff_size), CMD_LINE(REQUIRED_ARG),
2184  VALID_RANGE(1024, 1024*1024*1024), DEFAULT(32768), BLOCK_SIZE(1));
2185 
2186 static Sys_var_uint Sys_protocol_version(
2187  "protocol_version",
2188  "The version of the client/server protocol used by the MySQL server",
2189  READ_ONLY GLOBAL_VAR(protocol_version), NO_CMD_LINE,
2190  VALID_RANGE(0, ~0), DEFAULT(PROTOCOL_VERSION), BLOCK_SIZE(1));
2191 
2192 static Sys_var_proxy_user Sys_proxy_user(
2193  "proxy_user", "The proxy user account name used when logging in",
2194  IN_SYSTEM_CHARSET);
2195 
2196 static Sys_var_external_user Sys_external_user(
2197  "external_user", "The external user account used when logging in",
2198  IN_SYSTEM_CHARSET);
2199 
2200 static Sys_var_ulong Sys_read_buff_size(
2201  "read_buffer_size",
2202  "Each thread that does a sequential scan allocates a buffer of "
2203  "this size for each table it scans. If you do many sequential scans, "
2204  "you may want to increase this value",
2205  SESSION_VAR(read_buff_size), CMD_LINE(REQUIRED_ARG),
2206  VALID_RANGE(IO_SIZE*2, INT_MAX32), DEFAULT(128*1024),
2207  BLOCK_SIZE(IO_SIZE));
2208 
2209 static bool check_read_only(sys_var *self, THD *thd, set_var *var)
2210 {
2211  /* Prevent self dead-lock */
2212  if (thd->locked_tables_mode || thd->in_active_multi_stmt_transaction())
2213  {
2214  my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
2215  return true;
2216  }
2217  return false;
2218 }
2219 static bool fix_read_only(sys_var *self, THD *thd, enum_var_type type)
2220 {
2221  bool result= true;
2222  my_bool new_read_only= read_only; // make a copy before releasing a mutex
2223  DBUG_ENTER("sys_var_opt_readonly::update");
2224 
2225  if (read_only == FALSE || read_only == opt_readonly)
2226  {
2227  opt_readonly= read_only;
2228  DBUG_RETURN(false);
2229  }
2230 
2231  if (check_read_only(self, thd, 0)) // just in case
2232  goto end;
2233 
2234  if (thd->global_read_lock.is_acquired())
2235  {
2236  /*
2237  This connection already holds the global read lock.
2238  This can be the case with:
2239  - FLUSH TABLES WITH READ LOCK
2240  - SET GLOBAL READ_ONLY = 1
2241  */
2242  opt_readonly= read_only;
2243  DBUG_RETURN(false);
2244  }
2245 
2246  /*
2247  READ_ONLY=1 prevents write locks from being taken on tables and
2248  blocks transactions from committing. We therefore should make sure
2249  that no such events occur while setting the read_only variable.
2250  This is a 2 step process:
2251  [1] lock_global_read_lock()
2252  Prevents connections from obtaining new write locks on
2253  tables. Note that we can still have active rw transactions.
2254  [2] make_global_read_lock_block_commit()
2255  Prevents transactions from committing.
2256  */
2257 
2258  read_only= opt_readonly;
2259  mysql_mutex_unlock(&LOCK_global_system_variables);
2260 
2261  if (thd->global_read_lock.lock_global_read_lock(thd))
2262  goto end_with_mutex_unlock;
2263 
2264  if ((result= thd->global_read_lock.make_global_read_lock_block_commit(thd)))
2265  goto end_with_read_lock;
2266 
2267  /* Change the opt_readonly system variable, safe because the lock is held */
2268  opt_readonly= new_read_only;
2269  result= false;
2270 
2271  end_with_read_lock:
2272  /* Release the lock */
2273  thd->global_read_lock.unlock_global_read_lock(thd);
2274  end_with_mutex_unlock:
2275  mysql_mutex_lock(&LOCK_global_system_variables);
2276  end:
2277  read_only= opt_readonly;
2278  DBUG_RETURN(result);
2279 }
2280 
2281 
2290 static Sys_var_mybool Sys_readonly(
2291  "read_only",
2292  "Make all non-temporary tables read-only, with the exception for "
2293  "replication (slave) threads and users with the SUPER privilege",
2294  GLOBAL_VAR(read_only), CMD_LINE(OPT_ARG), DEFAULT(FALSE),
2295  NO_MUTEX_GUARD, NOT_IN_BINLOG,
2296  ON_CHECK(check_read_only), ON_UPDATE(fix_read_only));
2297 
2298 // Small lower limit to be able to test MRR
2299 static Sys_var_ulong Sys_read_rnd_buff_size(
2300  "read_rnd_buffer_size",
2301  "When reading rows in sorted order after a sort, the rows are read "
2302  "through this buffer to avoid a disk seeks",
2303  SESSION_VAR(read_rnd_buff_size), CMD_LINE(REQUIRED_ARG),
2304  VALID_RANGE(1, INT_MAX32), DEFAULT(256*1024), BLOCK_SIZE(1));
2305 
2306 static Sys_var_ulong Sys_div_precincrement(
2307  "div_precision_increment", "Precision of the result of '/' "
2308  "operator will be increased on that value",
2309  SESSION_VAR(div_precincrement), CMD_LINE(REQUIRED_ARG),
2310  VALID_RANGE(0, DECIMAL_MAX_SCALE), DEFAULT(4), BLOCK_SIZE(1));
2311 
2312 static Sys_var_uint Sys_eq_range_index_dive_limit(
2313  "eq_range_index_dive_limit",
2314  "The optimizer will use existing index statistics instead of "
2315  "doing index dives for equality ranges if the number of equality "
2316  "ranges for the index is larger than or equal to this number. "
2317  "If set to 0, index dives are always used.",
2318  SESSION_VAR(eq_range_index_dive_limit), CMD_LINE(REQUIRED_ARG),
2319  VALID_RANGE(0, UINT_MAX32), DEFAULT(10), BLOCK_SIZE(1));
2320 
2321 static Sys_var_ulong Sys_range_alloc_block_size(
2322  "range_alloc_block_size",
2323  "Allocation block size for storing ranges during optimization",
2324  SESSION_VAR(range_alloc_block_size), CMD_LINE(REQUIRED_ARG),
2325  VALID_RANGE(RANGE_ALLOC_BLOCK_SIZE, ULONG_MAX),
2326  DEFAULT(RANGE_ALLOC_BLOCK_SIZE), BLOCK_SIZE(1024));
2327 
2328 static Sys_var_ulong Sys_multi_range_count(
2329  "multi_range_count",
2330  "Number of key ranges to request at once. "
2331  "This variable has no effect, and is deprecated. "
2332  "It will be removed in a future release.",
2333  SESSION_VAR(multi_range_count), CMD_LINE(REQUIRED_ARG),
2334  VALID_RANGE(1, ULONG_MAX), DEFAULT(256), BLOCK_SIZE(1),
2335  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
2336  DEPRECATED(""));
2337 
2338 static bool fix_thd_mem_root(sys_var *self, THD *thd, enum_var_type type)
2339 {
2340  if (type != OPT_GLOBAL)
2341  reset_root_defaults(thd->mem_root,
2342  thd->variables.query_alloc_block_size,
2343  thd->variables.query_prealloc_size);
2344  return false;
2345 }
2346 static Sys_var_ulong Sys_query_alloc_block_size(
2347  "query_alloc_block_size",
2348  "Allocation block size for query parsing and execution",
2349  SESSION_VAR(query_alloc_block_size), CMD_LINE(REQUIRED_ARG),
2350  VALID_RANGE(1024, ULONG_MAX), DEFAULT(QUERY_ALLOC_BLOCK_SIZE),
2351  BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2352  ON_UPDATE(fix_thd_mem_root));
2353 
2354 static Sys_var_ulong Sys_query_prealloc_size(
2355  "query_prealloc_size",
2356  "Persistent buffer for query parsing and execution",
2357  SESSION_VAR(query_prealloc_size), CMD_LINE(REQUIRED_ARG),
2358  VALID_RANGE(QUERY_ALLOC_PREALLOC_SIZE, ULONG_MAX),
2359  DEFAULT(QUERY_ALLOC_PREALLOC_SIZE),
2360  BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2361  ON_UPDATE(fix_thd_mem_root));
2362 
2363 #ifdef HAVE_SMEM
2364 static Sys_var_mybool Sys_shared_memory(
2365  "shared_memory", "Enable the shared memory",
2366  READ_ONLY GLOBAL_VAR(opt_enable_shared_memory), CMD_LINE(OPT_ARG),
2367  DEFAULT(FALSE));
2368 
2369 static Sys_var_charptr Sys_shared_memory_base_name(
2370  "shared_memory_base_name", "Base name of shared memory",
2371  READ_ONLY GLOBAL_VAR(shared_memory_base_name), CMD_LINE(REQUIRED_ARG),
2372  IN_FS_CHARSET, DEFAULT(0));
2373 #endif
2374 
2375 // this has to be NO_CMD_LINE as the command-line option has a different name
2376 static Sys_var_mybool Sys_skip_external_locking(
2377  "skip_external_locking", "Don't use system (external) locking",
2378  READ_ONLY GLOBAL_VAR(my_disable_locking), NO_CMD_LINE, DEFAULT(TRUE));
2379 
2380 static Sys_var_mybool Sys_skip_networking(
2381  "skip_networking", "Don't allow connection with TCP/IP",
2382  READ_ONLY GLOBAL_VAR(opt_disable_networking), CMD_LINE(OPT_ARG),
2383  DEFAULT(FALSE));
2384 
2385 static Sys_var_mybool Sys_skip_name_resolve(
2386  "skip_name_resolve",
2387  "Don't resolve hostnames. All hostnames are IP's or 'localhost'.",
2388  READ_ONLY GLOBAL_VAR(opt_skip_name_resolve),
2389  CMD_LINE(OPT_ARG, OPT_SKIP_RESOLVE),
2390  DEFAULT(FALSE));
2391 
2392 static Sys_var_mybool Sys_skip_show_database(
2393  "skip_show_database", "Don't allow 'SHOW DATABASE' commands",
2394  READ_ONLY GLOBAL_VAR(opt_skip_show_db), CMD_LINE(OPT_ARG),
2395  DEFAULT(FALSE));
2396 
2397 static Sys_var_charptr Sys_socket(
2398  "socket", "Socket file to use for connection",
2399  READ_ONLY GLOBAL_VAR(mysqld_unix_port), CMD_LINE(REQUIRED_ARG),
2400  IN_FS_CHARSET, DEFAULT(0));
2401 
2402 /*
2403  thread_concurrency is a no-op on all platforms since
2404  MySQL 5.1. It will be removed in the context of
2405  WL#5265
2406 */
2407 static Sys_var_ulong Sys_thread_concurrency(
2408  "thread_concurrency",
2409  "Permits the application to give the threads system a hint for "
2410  "the desired number of threads that should be run at the same time. "
2411  "This variable has no effect, and is deprecated. "
2412  "It will be removed in a future release. ",
2413  READ_ONLY GLOBAL_VAR(concurrency), CMD_LINE(REQUIRED_ARG),
2414  VALID_RANGE(1, 512), DEFAULT(DEFAULT_CONCURRENCY), BLOCK_SIZE(1),
2415  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
2416  DEPRECATED(""));
2417 
2418 static Sys_var_ulong Sys_thread_stack(
2419  "thread_stack", "The stack size for each thread",
2420  READ_ONLY GLOBAL_VAR(my_thread_stack_size), CMD_LINE(REQUIRED_ARG),
2421  VALID_RANGE(128*1024, ULONG_MAX), DEFAULT(DEFAULT_THREAD_STACK),
2422  BLOCK_SIZE(1024));
2423 
2424 static Sys_var_charptr Sys_tmpdir(
2425  "tmpdir", "Path for temporary files. Several paths may "
2426  "be specified, separated by a "
2427 #if defined(__WIN__)
2428  "semicolon (;)"
2429 #else
2430  "colon (:)"
2431 #endif
2432  ", in this case they are used in a round-robin fashion",
2433  READ_ONLY GLOBAL_VAR(opt_mysql_tmpdir), CMD_LINE(REQUIRED_ARG, 't'),
2434  IN_FS_CHARSET, DEFAULT(0));
2435 
2436 static bool fix_trans_mem_root(sys_var *self, THD *thd, enum_var_type type)
2437 {
2438  if (type != OPT_GLOBAL)
2439  reset_root_defaults(&thd->transaction.mem_root,
2440  thd->variables.trans_alloc_block_size,
2441  thd->variables.trans_prealloc_size);
2442  return false;
2443 }
2444 static Sys_var_ulong Sys_trans_alloc_block_size(
2445  "transaction_alloc_block_size",
2446  "Allocation block size for transactions to be stored in binary log",
2447  SESSION_VAR(trans_alloc_block_size), CMD_LINE(REQUIRED_ARG),
2448  VALID_RANGE(1024, ULONG_MAX), DEFAULT(QUERY_ALLOC_BLOCK_SIZE),
2449  BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2450  ON_UPDATE(fix_trans_mem_root));
2451 
2452 static Sys_var_ulong Sys_trans_prealloc_size(
2453  "transaction_prealloc_size",
2454  "Persistent buffer for transactions to be stored in binary log",
2455  SESSION_VAR(trans_prealloc_size), CMD_LINE(REQUIRED_ARG),
2456  VALID_RANGE(1024, ULONG_MAX), DEFAULT(TRANS_ALLOC_PREALLOC_SIZE),
2457  BLOCK_SIZE(1024), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2458  ON_UPDATE(fix_trans_mem_root));
2459 
2460 static const char *thread_handling_names[]=
2461 {
2462  "one-thread-per-connection", "no-threads", "loaded-dynamically",
2463  0
2464 };
2465 static Sys_var_enum Sys_thread_handling(
2466  "thread_handling",
2467  "Define threads usage for handling queries, one of "
2468  "one-thread-per-connection, no-threads, loaded-dynamically"
2469  , READ_ONLY GLOBAL_VAR(thread_handling), CMD_LINE(REQUIRED_ARG),
2470  thread_handling_names, DEFAULT(0));
2471 
2472 #ifdef HAVE_QUERY_CACHE
2473 static bool fix_query_cache_size(sys_var *self, THD *thd, enum_var_type type)
2474 {
2475  ulong new_cache_size= query_cache.resize(query_cache_size);
2476  /*
2477  Note: query_cache_size is a global variable reflecting the
2478  requested cache size. See also query_cache_size_arg
2479  */
2480  if (query_cache_size != new_cache_size)
2481  push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
2482  ER_WARN_QC_RESIZE, ER(ER_WARN_QC_RESIZE),
2483  query_cache_size, new_cache_size);
2484 
2485  query_cache_size= new_cache_size;
2486  return false;
2487 }
2488 static Sys_var_ulong Sys_query_cache_size(
2489  "query_cache_size",
2490  "The memory allocated to store results from old queries",
2491  GLOBAL_VAR(query_cache_size), CMD_LINE(REQUIRED_ARG),
2492  VALID_RANGE(0, ULONG_MAX), DEFAULT(1024U*1024U), BLOCK_SIZE(1024),
2493  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2494  ON_UPDATE(fix_query_cache_size));
2495 
2496 static Sys_var_ulong Sys_query_cache_limit(
2497  "query_cache_limit",
2498  "Don't cache results that are bigger than this",
2499  GLOBAL_VAR(query_cache.query_cache_limit), CMD_LINE(REQUIRED_ARG),
2500  VALID_RANGE(0, ULONG_MAX), DEFAULT(1024*1024), BLOCK_SIZE(1));
2501 
2502 static bool fix_qcache_min_res_unit(sys_var *self, THD *thd, enum_var_type type)
2503 {
2504  query_cache_min_res_unit=
2505  query_cache.set_min_res_unit(query_cache_min_res_unit);
2506  return false;
2507 }
2508 static Sys_var_ulong Sys_query_cache_min_res_unit(
2509  "query_cache_min_res_unit",
2510  "The minimum size for blocks allocated by the query cache",
2511  GLOBAL_VAR(query_cache_min_res_unit), CMD_LINE(REQUIRED_ARG),
2512  VALID_RANGE(0, ULONG_MAX), DEFAULT(QUERY_CACHE_MIN_RESULT_DATA_SIZE),
2513  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
2514  ON_UPDATE(fix_qcache_min_res_unit));
2515 
2516 static const char *query_cache_type_names[]= { "OFF", "ON", "DEMAND", 0 };
2517 static bool check_query_cache_type(sys_var *self, THD *thd, set_var *var)
2518 {
2519  if (query_cache.is_disabled())
2520  {
2521  my_error(ER_QUERY_CACHE_DISABLED, MYF(0));
2522  return true;
2523  }
2524  return false;
2525 }
2526 static Sys_var_enum Sys_query_cache_type(
2527  "query_cache_type",
2528  "OFF = Don't cache or retrieve results. ON = Cache all results "
2529  "except SELECT SQL_NO_CACHE ... queries. DEMAND = Cache only "
2530  "SELECT SQL_CACHE ... queries",
2531  SESSION_VAR(query_cache_type), CMD_LINE(REQUIRED_ARG),
2532  query_cache_type_names, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG,
2533  ON_CHECK(check_query_cache_type));
2534 
2535 static Sys_var_mybool Sys_query_cache_wlock_invalidate(
2536  "query_cache_wlock_invalidate",
2537  "Invalidate queries in query cache on LOCK for write",
2538  SESSION_VAR(query_cache_wlock_invalidate), CMD_LINE(OPT_ARG),
2539  DEFAULT(FALSE));
2540 #endif /* HAVE_QUERY_CACHE */
2541 
2542 static bool
2543 on_check_opt_secure_auth(sys_var *self, THD *thd, set_var *var)
2544 {
2545  if (!var->save_result.ulonglong_value)
2546  {
2547  WARN_DEPRECATED(thd, "pre-4.1 password hash", "post-4.1 password hash");
2548  }
2549  return false;
2550 }
2551 
2552 static Sys_var_mybool Sys_secure_auth(
2553  "secure_auth",
2554  "Disallow authentication for accounts that have old (pre-4.1) "
2555  "passwords",
2556  GLOBAL_VAR(opt_secure_auth), CMD_LINE(OPT_ARG, OPT_SECURE_AUTH),
2557  DEFAULT(TRUE),
2558  NO_MUTEX_GUARD, NOT_IN_BINLOG,
2559  ON_CHECK(on_check_opt_secure_auth)
2560  );
2561 
2562 static Sys_var_charptr Sys_secure_file_priv(
2563  "secure_file_priv",
2564  "Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to files "
2565  "within specified directory",
2566  READ_ONLY GLOBAL_VAR(opt_secure_file_priv),
2567  CMD_LINE(REQUIRED_ARG), IN_FS_CHARSET, DEFAULT(0));
2568 
2569 static bool fix_server_id(sys_var *self, THD *thd, enum_var_type type)
2570 {
2571  server_id_supplied = 1;
2572  thd->server_id= server_id;
2573  return false;
2574 }
2575 static Sys_var_ulong Sys_server_id(
2576  "server_id",
2577  "Uniquely identifies the server instance in the community of "
2578  "replication partners",
2579  GLOBAL_VAR(server_id), CMD_LINE(REQUIRED_ARG, OPT_SERVER_ID),
2580  VALID_RANGE(0, UINT_MAX32), DEFAULT(0), BLOCK_SIZE(1), NO_MUTEX_GUARD,
2581  NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(fix_server_id));
2582 
2583 static Sys_var_charptr Sys_server_uuid(
2584  "server_uuid",
2585  "Uniquely identifies the server instance in the universe",
2586  READ_ONLY GLOBAL_VAR(server_uuid_ptr),
2587  NO_CMD_LINE, IN_FS_CHARSET, DEFAULT(server_uuid));
2588 
2589 static Sys_var_uint Sys_server_id_bits(
2590  "server_id_bits",
2591  "Set number of significant bits in server-id",
2592  GLOBAL_VAR(opt_server_id_bits), CMD_LINE(REQUIRED_ARG),
2593  VALID_RANGE(0, 32), DEFAULT(32), BLOCK_SIZE(1));
2594 
2595 static Sys_var_mybool Sys_slave_compressed_protocol(
2596  "slave_compressed_protocol",
2597  "Use compression on master/slave protocol",
2598  GLOBAL_VAR(opt_slave_compressed_protocol), CMD_LINE(OPT_ARG),
2599  DEFAULT(FALSE));
2600 
2601 #ifdef HAVE_REPLICATION
2602 static const char *slave_exec_mode_names[]=
2603  {"STRICT", "IDEMPOTENT", 0};
2604 static Sys_var_enum Slave_exec_mode(
2605  "slave_exec_mode",
2606  "Modes for how replication events should be executed. Legal values "
2607  "are STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, "
2608  "replication will not stop for operations that are idempotent. "
2609  "In STRICT mode, replication will stop on any unexpected difference "
2610  "between the master and the slave",
2611  GLOBAL_VAR(slave_exec_mode_options), CMD_LINE(REQUIRED_ARG),
2612  slave_exec_mode_names, DEFAULT(SLAVE_EXEC_MODE_STRICT));
2613 const char *slave_type_conversions_name[]=
2614  {"ALL_LOSSY", "ALL_NON_LOSSY", "ALL_UNSIGNED", "ALL_SIGNED", 0};
2615 static Sys_var_set Slave_type_conversions(
2616  "slave_type_conversions",
2617  "Set of slave type conversions that are enabled. Legal values are:"
2618  " ALL_LOSSY to enable lossy conversions,"
2619  " ALL_NON_LOSSY to enable non-lossy conversions,"
2620  " ALL_UNSIGNED to treat all integer column type data to be unsigned values, and"
2621  " ALL_SIGNED to treat all integer column type data to be signed values."
2622  " Default treatment is ALL_SIGNED. If ALL_SIGNED and ALL_UNSIGNED both are"
2623  " specifed, ALL_SIGNED will take high priority than ALL_UNSIGNED."
2624  " If the variable is assigned the empty set, no conversions are"
2625  " allowed and it is expected that the types match exactly.",
2626  GLOBAL_VAR(slave_type_conversions_options), CMD_LINE(REQUIRED_ARG),
2627  slave_type_conversions_name,
2628  DEFAULT(0));
2629 
2630 static Sys_var_mybool Sys_slave_sql_verify_checksum(
2631  "slave_sql_verify_checksum",
2632  "Force checksum verification of replication events after reading them "
2633  "from relay log. Note: Events are always checksum-verified by slave on "
2634  "receiving them from the network before writing them to the relay "
2635  "log. Enabled by default.",
2636  GLOBAL_VAR(opt_slave_sql_verify_checksum), CMD_LINE(OPT_ARG), DEFAULT(TRUE));
2637 
2638 static bool slave_rows_search_algorithms_check(sys_var *self, THD *thd, set_var *var)
2639 {
2640  String str, *res;
2641  /* null value is not allowed */
2642  if (check_not_null(self, thd, var))
2643  return true;
2644 
2646  res= var->value? var->value->val_str(&str) : NULL;
2647  if (res && res->is_empty())
2648  return true;
2649 
2650  return false;
2651 }
2652 
2653 static const char *slave_rows_search_algorithms_names[]= {"TABLE_SCAN", "INDEX_SCAN", "HASH_SCAN", 0};
2654 static Sys_var_set Slave_rows_search_algorithms(
2655  "slave_rows_search_algorithms",
2656  "Set of searching algorithms that the slave will use while "
2657  "searching for records from the storage engine to either "
2658  "updated or deleted them. Possible values are: INDEX_SCAN, "
2659  "TABLE_SCAN and HASH_SCAN. Any combination is allowed, and "
2660  "the slave will always pick the most suitable algorithm for "
2661  "any given scenario. "
2662  "(Default: INDEX_SCAN, TABLE_SCAN).",
2663  GLOBAL_VAR(slave_rows_search_algorithms_options), CMD_LINE(REQUIRED_ARG),
2664  slave_rows_search_algorithms_names,
2665  DEFAULT(SLAVE_ROWS_INDEX_SCAN | SLAVE_ROWS_TABLE_SCAN), NO_MUTEX_GUARD,
2666  NOT_IN_BINLOG, ON_CHECK(slave_rows_search_algorithms_check), ON_UPDATE(NULL));
2667 #endif
2668 
2669 bool Sys_var_enum_binlog_checksum::global_update(THD *thd, set_var *var)
2670 {
2671  bool check_purge= false;
2672 
2673  mysql_mutex_lock(mysql_bin_log.get_log_lock());
2674  if(mysql_bin_log.is_open())
2675  {
2676  bool alg_changed=
2677  (binlog_checksum_options != (uint) var->save_result.ulonglong_value);
2678  if (alg_changed)
2679  mysql_bin_log.checksum_alg_reset= (uint8) var->save_result.ulonglong_value;
2680  mysql_bin_log.rotate(true, &check_purge);
2681  if (alg_changed)
2682  mysql_bin_log.checksum_alg_reset= BINLOG_CHECKSUM_ALG_UNDEF; // done
2683  }
2684  else
2685  {
2686  binlog_checksum_options= var->save_result.ulonglong_value;
2687  }
2688  DBUG_ASSERT((ulong) binlog_checksum_options == var->save_result.ulonglong_value);
2689  DBUG_ASSERT(mysql_bin_log.checksum_alg_reset == BINLOG_CHECKSUM_ALG_UNDEF);
2690  mysql_mutex_unlock(mysql_bin_log.get_log_lock());
2691 
2692  if (check_purge)
2693  mysql_bin_log.purge();
2694 
2695  return 0;
2696 }
2697 
2698 static Sys_var_enum_binlog_checksum Binlog_checksum_enum(
2699  "binlog_checksum", "Type of BINLOG_CHECKSUM_ALG. Include checksum for "
2700  "log events in the binary log. Possible values are NONE and CRC32; "
2701  "default is CRC32.",
2702  GLOBAL_VAR(binlog_checksum_options), CMD_LINE(REQUIRED_ARG),
2703  binlog_checksum_type_names, DEFAULT(BINLOG_CHECKSUM_ALG_CRC32),
2704  NO_MUTEX_GUARD, NOT_IN_BINLOG);
2705 
2706 static Sys_var_mybool Sys_master_verify_checksum(
2707  "master_verify_checksum",
2708  "Force checksum verification of logged events in binary log before "
2709  "sending them to slaves or printing them in output of SHOW BINLOG EVENTS. "
2710  "Disabled by default.",
2711  GLOBAL_VAR(opt_master_verify_checksum), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
2712 
2713 static Sys_var_ulong Sys_slow_launch_time(
2714  "slow_launch_time",
2715  "If creating the thread takes longer than this value (in seconds), "
2716  "the Slow_launch_threads counter will be incremented",
2717  GLOBAL_VAR(slow_launch_time), CMD_LINE(REQUIRED_ARG),
2718  VALID_RANGE(0, LONG_TIMEOUT), DEFAULT(2), BLOCK_SIZE(1));
2719 
2720 static Sys_var_ulong Sys_sort_buffer(
2721  "sort_buffer_size",
2722  "Each thread that needs to do a sort allocates a buffer of this size",
2723  SESSION_VAR(sortbuff_size), CMD_LINE(REQUIRED_ARG),
2724  VALID_RANGE(MIN_SORT_MEMORY, ULONG_MAX), DEFAULT(DEFAULT_SORT_MEMORY),
2725  BLOCK_SIZE(1));
2726 
2727 export sql_mode_t expand_sql_mode(sql_mode_t sql_mode)
2728 {
2729  if (sql_mode & MODE_ANSI)
2730  {
2731  /*
2732  Note that we dont set
2733  MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | MODE_NO_FIELD_OPTIONS
2734  to allow one to get full use of MySQL in this mode.
2735 
2736  MODE_ONLY_FULL_GROUP_BY was removed from ANSI mode because it is
2737  currently overly restrictive (see BUG#8510).
2738  */
2739  sql_mode|= (MODE_REAL_AS_FLOAT | MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
2740  MODE_IGNORE_SPACE);
2741  }
2742  if (sql_mode & MODE_ORACLE)
2743  sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
2744  MODE_IGNORE_SPACE |
2745  MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
2746  MODE_NO_FIELD_OPTIONS | MODE_NO_AUTO_CREATE_USER);
2747  if (sql_mode & MODE_MSSQL)
2748  sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
2749  MODE_IGNORE_SPACE |
2750  MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
2751  MODE_NO_FIELD_OPTIONS);
2752  if (sql_mode & MODE_POSTGRESQL)
2753  sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
2754  MODE_IGNORE_SPACE |
2755  MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
2756  MODE_NO_FIELD_OPTIONS);
2757  if (sql_mode & MODE_DB2)
2758  sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
2759  MODE_IGNORE_SPACE |
2760  MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
2761  MODE_NO_FIELD_OPTIONS);
2762  if (sql_mode & MODE_MAXDB)
2763  sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
2764  MODE_IGNORE_SPACE |
2765  MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS |
2766  MODE_NO_FIELD_OPTIONS | MODE_NO_AUTO_CREATE_USER);
2767  if (sql_mode & MODE_MYSQL40)
2768  sql_mode|= MODE_HIGH_NOT_PRECEDENCE;
2769  if (sql_mode & MODE_MYSQL323)
2770  sql_mode|= MODE_HIGH_NOT_PRECEDENCE;
2771  if (sql_mode & MODE_TRADITIONAL)
2772  sql_mode|= (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES |
2773  MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE |
2774  MODE_ERROR_FOR_DIVISION_BY_ZERO | MODE_NO_AUTO_CREATE_USER |
2775  MODE_NO_ENGINE_SUBSTITUTION);
2776  return sql_mode;
2777 }
2778 static bool check_sql_mode(sys_var *self, THD *thd, set_var *var)
2779 {
2780  var->save_result.ulonglong_value=
2781  expand_sql_mode(var->save_result.ulonglong_value);
2782  return false;
2783 }
2784 static bool fix_sql_mode(sys_var *self, THD *thd, enum_var_type type)
2785 {
2786  if (type != OPT_GLOBAL)
2787  {
2788  /* Update thd->server_status */
2789  if (thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES)
2790  thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES;
2791  else
2792  thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES;
2793  }
2794  return false;
2795 }
2796 /*
2797  WARNING: When adding new SQL modes don't forget to update the
2798  tables definitions that stores it's value (ie: mysql.event, mysql.proc)
2799 */
2800 static const char *sql_mode_names[]=
2801 {
2802  "REAL_AS_FLOAT", "PIPES_AS_CONCAT", "ANSI_QUOTES", "IGNORE_SPACE", ",",
2803  "ONLY_FULL_GROUP_BY", "NO_UNSIGNED_SUBTRACTION", "NO_DIR_IN_CREATE",
2804  "POSTGRESQL", "ORACLE", "MSSQL", "DB2", "MAXDB", "NO_KEY_OPTIONS",
2805  "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "MYSQL323", "MYSQL40", "ANSI",
2806  "NO_AUTO_VALUE_ON_ZERO", "NO_BACKSLASH_ESCAPES", "STRICT_TRANS_TABLES",
2807  "STRICT_ALL_TABLES", "NO_ZERO_IN_DATE", "NO_ZERO_DATE",
2808  "ALLOW_INVALID_DATES", "ERROR_FOR_DIVISION_BY_ZERO", "TRADITIONAL",
2809  "NO_AUTO_CREATE_USER", "HIGH_NOT_PRECEDENCE", "NO_ENGINE_SUBSTITUTION",
2810  "PAD_CHAR_TO_FULL_LENGTH",
2811  0
2812 };
2813 export bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode,
2814  LEX_STRING *ls)
2815 {
2816  set_to_string(thd, ls, sql_mode, sql_mode_names);
2817  return ls->str == 0;
2818 }
2819 /*
2820  sql_mode should *not* be IN_BINLOG: even though it is written to the binlog,
2821  the slave ignores the MODE_NO_DIR_IN_CREATE variable, so slave's value
2822  differs from master's (see log_event.cc: Query_log_event::do_apply_event()).
2823 */
2824 static Sys_var_set Sys_sql_mode(
2825  "sql_mode",
2826  "Syntax: sql-mode=mode[,mode[,mode...]]. See the manual for the "
2827  "complete list of valid sql modes",
2828  SESSION_VAR(sql_mode), CMD_LINE(REQUIRED_ARG),
2829  sql_mode_names, DEFAULT(MODE_NO_ENGINE_SUBSTITUTION), NO_MUTEX_GUARD,
2830  NOT_IN_BINLOG, ON_CHECK(check_sql_mode), ON_UPDATE(fix_sql_mode));
2831 
2832 #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
2833 #define SSL_OPT(X) CMD_LINE(REQUIRED_ARG,X)
2834 #else
2835 #define SSL_OPT(X) NO_CMD_LINE
2836 #endif
2837 
2838 static Sys_var_charptr Sys_ssl_ca(
2839  "ssl_ca",
2840  "CA file in PEM format (check OpenSSL docs, implies --ssl)",
2841  READ_ONLY GLOBAL_VAR(opt_ssl_ca), SSL_OPT(OPT_SSL_CA),
2842  IN_FS_CHARSET, DEFAULT(0));
2843 
2844 static Sys_var_charptr Sys_ssl_capath(
2845  "ssl_capath",
2846  "CA directory (check OpenSSL docs, implies --ssl)",
2847  READ_ONLY GLOBAL_VAR(opt_ssl_capath), SSL_OPT(OPT_SSL_CAPATH),
2848  IN_FS_CHARSET, DEFAULT(0));
2849 
2850 static Sys_var_charptr Sys_ssl_cert(
2851  "ssl_cert", "X509 cert in PEM format (implies --ssl)",
2852  READ_ONLY GLOBAL_VAR(opt_ssl_cert), SSL_OPT(OPT_SSL_CERT),
2853  IN_FS_CHARSET, DEFAULT(0));
2854 
2855 static Sys_var_charptr Sys_ssl_cipher(
2856  "ssl_cipher", "SSL cipher to use (implies --ssl)",
2857  READ_ONLY GLOBAL_VAR(opt_ssl_cipher), SSL_OPT(OPT_SSL_CIPHER),
2858  IN_FS_CHARSET, DEFAULT(0));
2859 
2860 static Sys_var_charptr Sys_ssl_key(
2861  "ssl_key", "X509 key in PEM format (implies --ssl)",
2862  READ_ONLY GLOBAL_VAR(opt_ssl_key), SSL_OPT(OPT_SSL_KEY),
2863  IN_FS_CHARSET, DEFAULT(0));
2864 
2865 static Sys_var_charptr Sys_ssl_crl(
2866  "ssl_crl",
2867  "CRL file in PEM format (check OpenSSL docs, implies --ssl)",
2868  READ_ONLY GLOBAL_VAR(opt_ssl_crl), SSL_OPT(OPT_SSL_CRL),
2869  IN_FS_CHARSET, DEFAULT(0));
2870 
2871 static Sys_var_charptr Sys_ssl_crlpath(
2872  "ssl_crlpath",
2873  "CRL directory (check OpenSSL docs, implies --ssl)",
2874  READ_ONLY GLOBAL_VAR(opt_ssl_crlpath), SSL_OPT(OPT_SSL_CRLPATH),
2875  IN_FS_CHARSET, DEFAULT(0));
2876 
2877 
2878 // why ENUM and not BOOL ?
2879 static const char *updatable_views_with_limit_names[]= {"NO", "YES", 0};
2880 static Sys_var_enum Sys_updatable_views_with_limit(
2881  "updatable_views_with_limit",
2882  "YES = Don't issue an error message (warning only) if a VIEW without "
2883  "presence of a key of the underlying table is used in queries with a "
2884  "LIMIT clause for updating. NO = Prohibit update of a VIEW, which "
2885  "does not contain a key of the underlying table and the query uses "
2886  "a LIMIT clause (usually get from GUI tools)",
2887  SESSION_VAR(updatable_views_with_limit), CMD_LINE(REQUIRED_ARG),
2888  updatable_views_with_limit_names, DEFAULT(TRUE));
2889 
2890 static Sys_var_mybool Sys_sync_frm(
2891  "sync_frm", "Sync .frm files to disk on creation",
2892  GLOBAL_VAR(opt_sync_frm), CMD_LINE(OPT_ARG),
2893  DEFAULT(TRUE));
2894 
2895 static char *system_time_zone_ptr;
2896 static Sys_var_charptr Sys_system_time_zone(
2897  "system_time_zone", "The server system time zone",
2898  READ_ONLY GLOBAL_VAR(system_time_zone_ptr), NO_CMD_LINE,
2899  IN_FS_CHARSET, DEFAULT(system_time_zone));
2900 
2901 static Sys_var_ulong Sys_table_def_size(
2902  "table_definition_cache",
2903  "The number of cached table definitions",
2904  GLOBAL_VAR(table_def_size),
2905  CMD_LINE(REQUIRED_ARG, OPT_TABLE_DEFINITION_CACHE),
2906  VALID_RANGE(TABLE_DEF_CACHE_MIN, 512*1024),
2907  DEFAULT(TABLE_DEF_CACHE_DEFAULT),
2908  BLOCK_SIZE(1),
2909  NO_MUTEX_GUARD,
2910  NOT_IN_BINLOG,
2911  ON_CHECK(NULL),
2912  ON_UPDATE(NULL),
2913  NULL,
2914  /* table_definition_cache is used as a sizing hint by the performance schema. */
2915  sys_var::PARSE_EARLY);
2916 
2917 static bool fix_table_cache_size(sys_var *self, THD *thd, enum_var_type type)
2918 {
2919  /*
2920  table_open_cache parameter is a soft limit for total number of objects
2921  in all table cache instances. Once this value is updated we need to
2922  update value of a per-instance soft limit on table cache size.
2923  */
2924  table_cache_size_per_instance= table_cache_size / table_cache_instances;
2925  return false;
2926 }
2927 
2928 static Sys_var_ulong Sys_table_cache_size(
2929  "table_open_cache", "The number of cached open tables "
2930  "(total for all table cache instances)",
2931  GLOBAL_VAR(table_cache_size), CMD_LINE(REQUIRED_ARG),
2932  VALID_RANGE(1, 512*1024), DEFAULT(TABLE_OPEN_CACHE_DEFAULT),
2933  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
2934  ON_UPDATE(fix_table_cache_size),
2935  NULL,
2936  /* table_open_cache is used as a sizing hint by the performance schema. */
2937  sys_var::PARSE_EARLY);
2938 
2939 static Sys_var_ulong Sys_table_cache_instances(
2940  "table_open_cache_instances", "The number of table cache instances",
2941  READ_ONLY GLOBAL_VAR(table_cache_instances), CMD_LINE(REQUIRED_ARG),
2942  VALID_RANGE(1, Table_cache_manager::MAX_TABLE_CACHES), DEFAULT(1),
2943  BLOCK_SIZE(1), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
2944  ON_UPDATE(NULL), NULL,
2945  /*
2946  table_open_cache is used as a sizing hint by the performance schema,
2947  and 'table_open_cache' is a prefix of 'table_open_cache_instances'.
2948  Is is better to keep these options together, to avoid confusing
2949  handle_options() with partial name matches.
2950  */
2951  sys_var::PARSE_EARLY);
2952 
2953 static Sys_var_ulong Sys_thread_cache_size(
2954  "thread_cache_size",
2955  "How many threads we should keep in a cache for reuse",
2956  GLOBAL_VAR(max_blocked_pthreads),
2957  CMD_LINE(REQUIRED_ARG, OPT_THREAD_CACHE_SIZE),
2958  VALID_RANGE(0, 16384), DEFAULT(0), BLOCK_SIZE(1));
2959 
2965 static bool check_tx_isolation(sys_var *self, THD *thd, set_var *var)
2966 {
2967  if (var->type == OPT_DEFAULT && thd->in_active_multi_stmt_transaction())
2968  {
2969  DBUG_ASSERT(thd->in_multi_stmt_transaction_mode());
2970  my_error(ER_CANT_CHANGE_TX_CHARACTERISTICS, MYF(0));
2971  return TRUE;
2972  }
2973  return FALSE;
2974 }
2975 
2976 
2977 bool Sys_var_tx_isolation::session_update(THD *thd, set_var *var)
2978 {
2979  if (var->type == OPT_SESSION && Sys_var_enum::session_update(thd, var))
2980  return TRUE;
2981  if (var->type == OPT_DEFAULT || !thd->in_active_multi_stmt_transaction())
2982  {
2983  /*
2984  Update the isolation level of the next transaction.
2985  I.e. if one did:
2986  COMMIT;
2987  SET SESSION ISOLATION LEVEL ...
2988  BEGIN; <-- this transaction has the new isolation
2989  Note, that in case of:
2990  COMMIT;
2991  SET TRANSACTION ISOLATION LEVEL ...
2992  SET SESSION ISOLATION LEVEL ...
2993  BEGIN; <-- the session isolation level is used, not the
2994  result of SET TRANSACTION statement.
2995  */
2996  thd->tx_isolation= (enum_tx_isolation) var->save_result.ulonglong_value;
2997  }
2998  return FALSE;
2999 }
3000 
3001 
3002 // NO_CMD_LINE - different name of the option
3003 static Sys_var_tx_isolation Sys_tx_isolation(
3004  "tx_isolation", "Default transaction isolation level",
3005  SESSION_VAR(tx_isolation), NO_CMD_LINE,
3006  tx_isolation_names, DEFAULT(ISO_REPEATABLE_READ),
3007  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_tx_isolation));
3008 
3009 
3015 static bool check_tx_read_only(sys_var *self, THD *thd, set_var *var)
3016 {
3017  if (var->type == OPT_DEFAULT && thd->in_active_multi_stmt_transaction())
3018  {
3019  DBUG_ASSERT(thd->in_multi_stmt_transaction_mode());
3020  my_error(ER_CANT_CHANGE_TX_CHARACTERISTICS, MYF(0));
3021  return true;
3022  }
3023  return false;
3024 }
3025 
3026 
3027 bool Sys_var_tx_read_only::session_update(THD *thd, set_var *var)
3028 {
3029  if (var->type == OPT_SESSION && Sys_var_mybool::session_update(thd, var))
3030  return true;
3031  if (var->type == OPT_DEFAULT || !thd->in_active_multi_stmt_transaction())
3032  {
3033  // @see Sys_var_tx_isolation::session_update() above for the rules.
3034  thd->tx_read_only= var->save_result.ulonglong_value;
3035  }
3036  return false;
3037 }
3038 
3039 
3040 static Sys_var_tx_read_only Sys_tx_read_only(
3041  "tx_read_only", "Set default transaction access mode to read only.",
3042  SESSION_VAR(tx_read_only), NO_CMD_LINE, DEFAULT(0),
3043  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_tx_read_only));
3044 
3045 static Sys_var_ulonglong Sys_tmp_table_size(
3046  "tmp_table_size",
3047  "If an internal in-memory temporary table exceeds this size, MySQL "
3048  "will automatically convert it to an on-disk MyISAM table",
3049  SESSION_VAR(tmp_table_size), CMD_LINE(REQUIRED_ARG),
3050  VALID_RANGE(1024, (ulonglong)~(intptr)0), DEFAULT(16*1024*1024),
3051  BLOCK_SIZE(1));
3052 
3053 static Sys_var_mybool Sys_timed_mutexes(
3054  "timed_mutexes",
3055  "Specify whether to time mutexes (only InnoDB mutexes are currently "
3056  "supported)",
3057  GLOBAL_VAR(timed_mutexes), CMD_LINE(OPT_ARG), DEFAULT(0));
3058 
3059 static char *server_version_ptr;
3060 static Sys_var_charptr Sys_version(
3061  "version", "Server version",
3062  READ_ONLY GLOBAL_VAR(server_version_ptr), NO_CMD_LINE,
3063  IN_SYSTEM_CHARSET, DEFAULT(server_version));
3064 
3065 static char *server_version_comment_ptr;
3066 static Sys_var_charptr Sys_version_comment(
3067  "version_comment", "version_comment",
3068  READ_ONLY GLOBAL_VAR(server_version_comment_ptr), NO_CMD_LINE,
3069  IN_SYSTEM_CHARSET, DEFAULT(MYSQL_COMPILATION_COMMENT));
3070 
3071 static char *server_version_compile_machine_ptr;
3072 static Sys_var_charptr Sys_version_compile_machine(
3073  "version_compile_machine", "version_compile_machine",
3074  READ_ONLY GLOBAL_VAR(server_version_compile_machine_ptr), NO_CMD_LINE,
3075  IN_SYSTEM_CHARSET, DEFAULT(MACHINE_TYPE));
3076 
3077 static char *server_version_compile_os_ptr;
3078 static Sys_var_charptr Sys_version_compile_os(
3079  "version_compile_os", "version_compile_os",
3080  READ_ONLY GLOBAL_VAR(server_version_compile_os_ptr), NO_CMD_LINE,
3081  IN_SYSTEM_CHARSET, DEFAULT(SYSTEM_TYPE));
3082 
3083 static Sys_var_ulong Sys_net_wait_timeout(
3084  "wait_timeout",
3085  "The number of seconds the server waits for activity on a "
3086  "connection before closing it",
3087  SESSION_VAR(net_wait_timeout), CMD_LINE(REQUIRED_ARG),
3088  VALID_RANGE(1, IF_WIN(INT_MAX32/1000, LONG_TIMEOUT)),
3089  DEFAULT(NET_WAIT_TIMEOUT), BLOCK_SIZE(1));
3090 
3091 static Sys_var_plugin Sys_default_storage_engine(
3092  "default_storage_engine", "The default storage engine for new tables",
3093  SESSION_VAR(table_plugin), NO_CMD_LINE,
3094  MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_storage_engine),
3095  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_not_null));
3096 
3097 static Sys_var_plugin Sys_default_tmp_storage_engine(
3098  "default_tmp_storage_engine", "The default storage engine for new explict temporary tables",
3099  SESSION_VAR(temp_table_plugin), NO_CMD_LINE,
3100  MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_tmp_storage_engine),
3101  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_not_null));
3102 
3103 // Alias for @@default_storage_engine
3104 static Sys_var_plugin Sys_storage_engine(
3105  "storage_engine", "Alias for @@default_storage_engine. Deprecated",
3106  SESSION_VAR(table_plugin), NO_CMD_LINE,
3107  MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_storage_engine),
3108  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_not_null),
3109  ON_UPDATE(NULL), DEPRECATED("'@@default_storage_engine'"));
3110 
3111 #if defined(ENABLED_DEBUG_SYNC)
3112 /*
3113  Variable can be set for the session only.
3114 
3115  This could be changed later. Then we need to have a global array of
3116  actions in addition to the thread local ones. SET GLOBAL would
3117  manage the global array, SET [SESSION] the local array. A sync point
3118  would need to look for a local and a global action. Setting and
3119  executing of global actions need to be protected by a mutex.
3120 
3121  The purpose of global actions could be to allow synchronizing with
3122  connectionless threads that cannot execute SET statements.
3123 */
3124 static Sys_var_debug_sync Sys_debug_sync(
3125  "debug_sync", "Debug Sync Facility",
3126  sys_var::ONLY_SESSION, NO_CMD_LINE,
3127  DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_has_super));
3128 #endif /* defined(ENABLED_DEBUG_SYNC) */
3129 
3139 static Sys_var_charptr Sys_date_format(
3140  "date_format", "The DATE format (ignored)",
3141  READ_ONLY GLOBAL_VAR(global_date_format.format.str),
3142  CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
3143  DEFAULT(known_date_time_formats[ISO_FORMAT].date_format),
3144  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
3145  DEPRECATED(""));
3146 
3147 static Sys_var_charptr Sys_datetime_format(
3148  "datetime_format", "The DATETIME format (ignored)",
3149  READ_ONLY GLOBAL_VAR(global_datetime_format.format.str),
3150  CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
3151  DEFAULT(known_date_time_formats[ISO_FORMAT].datetime_format),
3152  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
3153  DEPRECATED(""));
3154 
3155 static Sys_var_charptr Sys_time_format(
3156  "time_format", "The TIME format (ignored)",
3157  READ_ONLY GLOBAL_VAR(global_time_format.format.str),
3158  CMD_LINE(REQUIRED_ARG), IN_SYSTEM_CHARSET,
3159  DEFAULT(known_date_time_formats[ISO_FORMAT].time_format),
3160  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0),
3161  DEPRECATED(""));
3162 
3163 static bool fix_autocommit(sys_var *self, THD *thd, enum_var_type type)
3164 {
3165  if (type == OPT_GLOBAL)
3166  {
3167  if (global_system_variables.option_bits & OPTION_AUTOCOMMIT)
3168  global_system_variables.option_bits&= ~OPTION_NOT_AUTOCOMMIT;
3169  else
3170  global_system_variables.option_bits|= OPTION_NOT_AUTOCOMMIT;
3171  return false;
3172  }
3173 
3174  if (thd->variables.option_bits & OPTION_AUTOCOMMIT &&
3175  thd->variables.option_bits & OPTION_NOT_AUTOCOMMIT)
3176  { // activating autocommit
3177 
3178  if (trans_commit_stmt(thd) || trans_commit(thd))
3179  {
3180  thd->variables.option_bits&= ~OPTION_AUTOCOMMIT;
3181  return true;
3182  }
3183  /*
3184  Don't close thread tables or release metadata locks: if we do so, we
3185  risk releasing locks/closing tables of expressions used to assign
3186  other variables, as in:
3187  set @var=my_stored_function1(), @@autocommit=1, @var2=(select max(a)
3188  from my_table), ...
3189  The locks will be released at statement end anyway, as SET
3190  statement that assigns autocommit is marked to commit
3191  transaction implicitly at the end (@sa stmt_causes_implicitcommit()).
3192  */
3193  thd->variables.option_bits&=
3194  ~(OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
3195  thd->transaction.all.reset_unsafe_rollback_flags();
3196  thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
3197  return false;
3198  }
3199 
3200  if (!(thd->variables.option_bits & OPTION_AUTOCOMMIT) &&
3201  !(thd->variables.option_bits & OPTION_NOT_AUTOCOMMIT))
3202  { // disabling autocommit
3203 
3204  thd->transaction.all.reset_unsafe_rollback_flags();
3205  thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
3206  thd->variables.option_bits|= OPTION_NOT_AUTOCOMMIT;
3207  return false;
3208  }
3209 
3210  return false; // autocommit value wasn't changed
3211 }
3212 static Sys_var_bit Sys_autocommit(
3213  "autocommit", "autocommit",
3214  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_AUTOCOMMIT, DEFAULT(TRUE),
3215  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(fix_autocommit));
3216 export sys_var *Sys_autocommit_ptr= &Sys_autocommit; // for sql_yacc.yy
3217 
3218 static Sys_var_mybool Sys_big_tables(
3219  "big_tables", "Allow big result sets by saving all "
3220  "temporary sets on file (Solves most 'table full' errors)",
3221  SESSION_VAR(big_tables), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
3222 
3223 static Sys_var_bit Sys_big_selects(
3224  "sql_big_selects", "sql_big_selects",
3225  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_BIG_SELECTS,
3226  DEFAULT(FALSE));
3227 
3228 static Sys_var_bit Sys_log_off(
3229  "sql_log_off", "sql_log_off",
3230  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_LOG_OFF,
3231  DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_has_super));
3232 
3242 static bool fix_sql_log_bin_after_update(sys_var *self, THD *thd,
3243  enum_var_type type)
3244 {
3245  if (type == OPT_SESSION)
3246  {
3247  if (thd->variables.sql_log_bin)
3248  thd->variables.option_bits |= OPTION_BIN_LOG;
3249  else
3250  thd->variables.option_bits &= ~OPTION_BIN_LOG;
3251  }
3252  return FALSE;
3253 }
3254 
3267 static bool check_sql_log_bin(sys_var *self, THD *thd, set_var *var)
3268 {
3269  if (check_has_super(self, thd, var))
3270  return TRUE;
3271 
3272  if (var->type == OPT_GLOBAL)
3273  return FALSE;
3274 
3275  /* If in a stored function/trigger, it's too late to change sql_log_bin. */
3276  if (thd->in_sub_stmt)
3277  {
3278  my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN, MYF(0));
3279  return TRUE;
3280  }
3281  /* Make the session variable 'sql_log_bin' read-only inside a transaction. */
3282  if (thd->in_active_multi_stmt_transaction())
3283  {
3284  my_error(ER_INSIDE_TRANSACTION_PREVENTS_SWITCH_SQL_LOG_BIN, MYF(0));
3285  return TRUE;
3286  }
3287 
3288  return FALSE;
3289 }
3290 
3291 static Sys_var_mybool Sys_log_binlog(
3292  "sql_log_bin", "sql_log_bin",
3293  SESSION_VAR(sql_log_bin), NO_CMD_LINE,
3294  DEFAULT(TRUE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_sql_log_bin),
3295  ON_UPDATE(fix_sql_log_bin_after_update));
3296 
3297 static Sys_var_bit Sys_transaction_allow_batching(
3298  "transaction_allow_batching", "transaction_allow_batching",
3299  SESSION_ONLY(option_bits), NO_CMD_LINE, OPTION_ALLOW_BATCH,
3300  DEFAULT(FALSE));
3301 
3302 static Sys_var_bit Sys_sql_warnings(
3303  "sql_warnings", "sql_warnings",
3304  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_WARNINGS,
3305  DEFAULT(FALSE));
3306 
3307 static Sys_var_bit Sys_sql_notes(
3308  "sql_notes", "sql_notes",
3309  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_SQL_NOTES,
3310  DEFAULT(TRUE));
3311 
3312 static Sys_var_bit Sys_auto_is_null(
3313  "sql_auto_is_null", "sql_auto_is_null",
3314  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_AUTO_IS_NULL,
3315  DEFAULT(FALSE), NO_MUTEX_GUARD, IN_BINLOG);
3316 
3317 static Sys_var_bit Sys_safe_updates(
3318  "sql_safe_updates", "sql_safe_updates",
3319  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_SAFE_UPDATES,
3320  DEFAULT(FALSE));
3321 
3322 static Sys_var_bit Sys_buffer_results(
3323  "sql_buffer_result", "sql_buffer_result",
3324  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_BUFFER_RESULT,
3325  DEFAULT(FALSE));
3326 
3327 static Sys_var_bit Sys_quote_show_create(
3328  "sql_quote_show_create", "sql_quote_show_create",
3329  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_QUOTE_SHOW_CREATE,
3330  DEFAULT(TRUE));
3331 
3332 static Sys_var_bit Sys_foreign_key_checks(
3333  "foreign_key_checks", "foreign_key_checks",
3334  SESSION_VAR(option_bits), NO_CMD_LINE,
3336  DEFAULT(TRUE), NO_MUTEX_GUARD, IN_BINLOG);
3337 
3338 static Sys_var_bit Sys_unique_checks(
3339  "unique_checks", "unique_checks",
3340  SESSION_VAR(option_bits), NO_CMD_LINE,
3342  DEFAULT(TRUE), NO_MUTEX_GUARD, IN_BINLOG);
3343 
3344 #ifdef ENABLED_PROFILING
3345 static Sys_var_bit Sys_profiling(
3346  "profiling", "profiling",
3347  SESSION_VAR(option_bits), NO_CMD_LINE, OPTION_PROFILING,
3348  DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3349  ON_UPDATE(0), DEPRECATED(""));
3350 
3351 static Sys_var_ulong Sys_profiling_history_size(
3352  "profiling_history_size", "Limit of query profiling memory",
3353  SESSION_VAR(profiling_history_size), CMD_LINE(REQUIRED_ARG),
3354  VALID_RANGE(0, 100), DEFAULT(15), BLOCK_SIZE(1), NO_MUTEX_GUARD,
3355  NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED(""));
3356 #endif
3357 
3358 static Sys_var_harows Sys_select_limit(
3359  "sql_select_limit",
3360  "The maximum number of rows to return from SELECT statements",
3361  SESSION_VAR(select_limit), NO_CMD_LINE,
3362  VALID_RANGE(0, HA_POS_ERROR), DEFAULT(HA_POS_ERROR), BLOCK_SIZE(1));
3363 
3364 static bool update_timestamp(THD *thd, set_var *var)
3365 {
3366  if (var->value)
3367  {
3368  double fl= floor(var->save_result.double_value); // Truncate integer part
3369  struct timeval tmp;
3370  tmp.tv_sec= (ulonglong) fl;
3371  /* Round nanoseconds to nearest microsecond */
3372  tmp.tv_usec= (ulonglong) rint((var->save_result.double_value - fl) * 1000000);
3373  thd->set_time(&tmp);
3374  }
3375  else // SET timestamp=DEFAULT
3376  {
3377  thd->user_time.tv_sec= 0;
3378  thd->user_time.tv_usec= 0;
3379  }
3380  return false;
3381 }
3382 static double read_timestamp(THD *thd)
3383 {
3384  return (double) thd->start_time.tv_sec +
3385  (double) thd->start_time.tv_usec / 1000000;
3386 }
3387 
3388 
3389 static bool check_timestamp(sys_var *self, THD *thd, set_var *var)
3390 {
3391  double val;
3392 
3393  if (!var->value)
3394  return FALSE;
3395 
3396  val= var->save_result.double_value;
3397  if (val != 0 && // this is how you set the default value
3398  (val < TIMESTAMP_MIN_VALUE || val > TIMESTAMP_MAX_VALUE))
3399  {
3400  ErrConvString prm(val);
3401  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "timestamp", prm.ptr());
3402  return TRUE;
3403  }
3404  return FALSE;
3405 }
3406 
3407 
3408 static Sys_var_session_special_double Sys_timestamp(
3409  "timestamp", "Set the time for this client",
3410  sys_var::ONLY_SESSION, NO_CMD_LINE,
3411  VALID_RANGE(0, 0), BLOCK_SIZE(1),
3412  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_timestamp),
3413  ON_UPDATE(update_timestamp), ON_READ(read_timestamp));
3414 
3415 static bool update_last_insert_id(THD *thd, set_var *var)
3416 {
3417  if (!var->value)
3418  {
3419  my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
3420  return true;
3421  }
3422  thd->first_successful_insert_id_in_prev_stmt=
3423  var->save_result.ulonglong_value;
3424  return false;
3425 }
3426 static ulonglong read_last_insert_id(THD *thd)
3427 {
3428  return (ulonglong) thd->read_first_successful_insert_id_in_prev_stmt();
3429 }
3430 static Sys_var_session_special Sys_last_insert_id(
3431  "last_insert_id", "The value to be returned from LAST_INSERT_ID()",
3432  sys_var::ONLY_SESSION, NO_CMD_LINE,
3433  VALID_RANGE(0, ULONGLONG_MAX), BLOCK_SIZE(1),
3434  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
3435  ON_UPDATE(update_last_insert_id), ON_READ(read_last_insert_id));
3436 
3437 // alias for last_insert_id(), Sybase-style
3438 static Sys_var_session_special Sys_identity(
3439  "identity", "Synonym for the last_insert_id variable",
3440  sys_var::ONLY_SESSION, NO_CMD_LINE,
3441  VALID_RANGE(0, ULONGLONG_MAX), BLOCK_SIZE(1),
3442  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
3443  ON_UPDATE(update_last_insert_id), ON_READ(read_last_insert_id));
3444 
3445 /*
3446  insert_id should *not* be marked as written to the binlog (i.e., it
3447  should *not* be IN_BINLOG), because we want any statement that
3448  refers to insert_id explicitly to be unsafe. (By "explicitly", we
3449  mean using @@session.insert_id, whereas insert_id is used
3450  "implicitly" when NULL value is inserted into an auto_increment
3451  column).
3452 
3453  We want statements referring explicitly to @@session.insert_id to be
3454  unsafe, because insert_id is modified internally by the slave sql
3455  thread when NULL values are inserted in an AUTO_INCREMENT column.
3456  This modification interfers with the value of the
3457  @@session.insert_id variable if @@session.insert_id is referred
3458  explicitly by an insert statement (as is seen by executing "SET
3459  @@session.insert_id=0; CREATE TABLE t (a INT, b INT KEY
3460  AUTO_INCREMENT); INSERT INTO t(a) VALUES (@@session.insert_id);" in
3461  statement-based logging mode: t will be different on master and
3462  slave).
3463 */
3464 static bool update_insert_id(THD *thd, set_var *var)
3465 {
3466  if (!var->value)
3467  {
3468  my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
3469  return true;
3470  }
3471  thd->force_one_auto_inc_interval(var->save_result.ulonglong_value);
3472  return false;
3473 }
3474 
3475 static ulonglong read_insert_id(THD *thd)
3476 {
3477  return thd->auto_inc_intervals_forced.minimum();
3478 }
3479 static Sys_var_session_special Sys_insert_id(
3480  "insert_id", "The value to be used by the following INSERT "
3481  "or ALTER TABLE statement when inserting an AUTO_INCREMENT value",
3482  sys_var::ONLY_SESSION, NO_CMD_LINE,
3483  VALID_RANGE(0, ULONGLONG_MAX), BLOCK_SIZE(1),
3484  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3485  ON_UPDATE(update_insert_id), ON_READ(read_insert_id));
3486 
3487 static bool update_rand_seed1(THD *thd, set_var *var)
3488 {
3489  if (!var->value)
3490  {
3491  my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
3492  return true;
3493  }
3494  thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
3495  return false;
3496 }
3497 static ulonglong read_rand_seed(THD *thd)
3498 {
3499  return 0;
3500 }
3501 static Sys_var_session_special Sys_rand_seed1(
3502  "rand_seed1", "Sets the internal state of the RAND() "
3503  "generator for replication purposes",
3504  sys_var::ONLY_SESSION, NO_CMD_LINE,
3505  VALID_RANGE(0, ULONG_MAX), BLOCK_SIZE(1),
3506  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
3507  ON_UPDATE(update_rand_seed1), ON_READ(read_rand_seed));
3508 
3509 static bool update_rand_seed2(THD *thd, set_var *var)
3510 {
3511  if (!var->value)
3512  {
3513  my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
3514  return true;
3515  }
3516  thd->rand.seed2= (ulong) var->save_result.ulonglong_value;
3517  return false;
3518 }
3519 static Sys_var_session_special Sys_rand_seed2(
3520  "rand_seed2", "Sets the internal state of the RAND() "
3521  "generator for replication purposes",
3522  sys_var::ONLY_SESSION, NO_CMD_LINE,
3523  VALID_RANGE(0, ULONG_MAX), BLOCK_SIZE(1),
3524  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(0),
3525  ON_UPDATE(update_rand_seed2), ON_READ(read_rand_seed));
3526 
3527 static ulonglong read_error_count(THD *thd)
3528 {
3529  return thd->get_stmt_da()->error_count();
3530 }
3531 // this really belongs to the SHOW STATUS
3532 static Sys_var_session_special Sys_error_count(
3533  "error_count", "The number of errors that resulted from the "
3534  "last statement that generated messages",
3535  READ_ONLY sys_var::ONLY_SESSION, NO_CMD_LINE,
3536  VALID_RANGE(0, ULONGLONG_MAX), BLOCK_SIZE(1), NO_MUTEX_GUARD,
3537  NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), ON_READ(read_error_count));
3538 
3539 static ulonglong read_warning_count(THD *thd)
3540 {
3541  return thd->get_stmt_da()->warn_count();
3542 }
3543 // this really belongs to the SHOW STATUS
3544 static Sys_var_session_special Sys_warning_count(
3545  "warning_count", "The number of errors, warnings, and notes "
3546  "that resulted from the last statement that generated messages",
3547  READ_ONLY sys_var::ONLY_SESSION, NO_CMD_LINE,
3548  VALID_RANGE(0, ULONGLONG_MAX), BLOCK_SIZE(1), NO_MUTEX_GUARD,
3549  NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), ON_READ(read_warning_count));
3550 
3551 static Sys_var_ulong Sys_default_week_format(
3552  "default_week_format",
3553  "The default week format used by WEEK() functions",
3554  SESSION_VAR(default_week_format), CMD_LINE(REQUIRED_ARG),
3555  VALID_RANGE(0, 7), DEFAULT(0), BLOCK_SIZE(1));
3556 
3557 static Sys_var_ulong Sys_group_concat_max_len(
3558  "group_concat_max_len",
3559  "The maximum length of the result of function GROUP_CONCAT()",
3560  SESSION_VAR(group_concat_max_len), CMD_LINE(REQUIRED_ARG),
3561  VALID_RANGE(4, ULONG_MAX), DEFAULT(1024), BLOCK_SIZE(1));
3562 
3563 static char *glob_hostname_ptr;
3564 static Sys_var_charptr Sys_hostname(
3565  "hostname", "Server host name",
3566  READ_ONLY GLOBAL_VAR(glob_hostname_ptr), NO_CMD_LINE,
3567  IN_FS_CHARSET, DEFAULT(glob_hostname));
3568 
3569 #ifndef EMBEDDED_LIBRARY
3570 static Sys_var_charptr Sys_repl_report_host(
3571  "report_host",
3572  "Hostname or IP of the slave to be reported to the master during "
3573  "slave registration. Will appear in the output of SHOW SLAVE HOSTS. "
3574  "Leave unset if you do not want the slave to register itself with the "
3575  "master. Note that it is not sufficient for the master to simply read "
3576  "the IP of the slave off the socket once the slave connects. Due to "
3577  "NAT and other routing issues, that IP may not be valid for connecting "
3578  "to the slave from the master or other hosts",
3579  READ_ONLY GLOBAL_VAR(report_host), CMD_LINE(REQUIRED_ARG),
3580  IN_FS_CHARSET, DEFAULT(0));
3581 
3582 static Sys_var_charptr Sys_repl_report_user(
3583  "report_user",
3584  "The account user name of the slave to be reported to the master "
3585  "during slave registration",
3586  READ_ONLY GLOBAL_VAR(report_user), CMD_LINE(REQUIRED_ARG),
3587  IN_FS_CHARSET, DEFAULT(0));
3588 
3589 static Sys_var_charptr Sys_repl_report_password(
3590  "report_password",
3591  "The account password of the slave to be reported to the master "
3592  "during slave registration",
3593  READ_ONLY GLOBAL_VAR(report_password), CMD_LINE(REQUIRED_ARG),
3594  IN_FS_CHARSET, DEFAULT(0));
3595 
3596 static Sys_var_uint Sys_repl_report_port(
3597  "report_port",
3598  "Port for connecting to slave reported to the master during slave "
3599  "registration. Set it only if the slave is listening on a non-default "
3600  "port or if you have a special tunnel from the master or other clients "
3601  "to the slave. If not sure, leave this option unset",
3602  READ_ONLY GLOBAL_VAR(report_port), CMD_LINE(REQUIRED_ARG),
3603  VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
3604 #endif
3605 
3606 static Sys_var_mybool Sys_keep_files_on_create(
3607  "keep_files_on_create",
3608  "Don't overwrite stale .MYD and .MYI even if no directory is specified",
3609  SESSION_VAR(keep_files_on_create), CMD_LINE(OPT_ARG),
3610  DEFAULT(FALSE));
3611 
3612 static char *license;
3613 static Sys_var_charptr Sys_license(
3614  "license", "The type of license the server has",
3615  READ_ONLY GLOBAL_VAR(license), NO_CMD_LINE, IN_SYSTEM_CHARSET,
3616  DEFAULT(STRINGIFY_ARG(LICENSE)));
3617 
3618 static bool check_log_path(sys_var *self, THD *thd, set_var *var)
3619 {
3620  if (!var->value)
3621  return false; // DEFAULT is ok
3622 
3623  if (!var->save_result.string_value.str)
3624  return true;
3625 
3626  if (var->save_result.string_value.length > FN_REFLEN)
3627  { // path is too long
3628  my_error(ER_PATH_LENGTH, MYF(0), self->name.str);
3629  return true;
3630  }
3631 
3632  char path[FN_REFLEN];
3633  size_t path_length= unpack_filename(path, var->save_result.string_value.str);
3634 
3635  if (!path_length)
3636  return true;
3637 
3638  if (!is_filename_allowed(var->save_result.string_value.str,
3639  var->save_result.string_value.length, TRUE))
3640  {
3641  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
3642  self->name.str, var->save_result.string_value.str);
3643  return true;
3644  }
3645 
3646  MY_STAT f_stat;
3647 
3648  if (my_stat(path, &f_stat, MYF(0)))
3649  {
3650  if (!MY_S_ISREG(f_stat.st_mode) || !(f_stat.st_mode & MY_S_IWRITE))
3651  return true; // not a regular writable file
3652  return false;
3653  }
3654 
3655  (void) dirname_part(path, var->save_result.string_value.str, &path_length);
3656 
3657  if (var->save_result.string_value.length - path_length >= FN_LEN)
3658  { // filename is too long
3659  my_error(ER_PATH_LENGTH, MYF(0), self->name.str);
3660  return true;
3661  }
3662 
3663  if (!path_length) // no path is good path (remember, relative to datadir)
3664  return false;
3665 
3666  if (my_access(path, (F_OK|W_OK)))
3667  return true; // directory is not writable
3668 
3669  return false;
3670 }
3671 static bool fix_log(char** logname, const char* default_logname,
3672  const char*ext, bool enabled, void (*reopen)(char*))
3673 {
3674  if (!*logname) // SET ... = DEFAULT
3675  {
3676  char buff[FN_REFLEN];
3677  *logname= my_strdup(make_log_name(buff, default_logname, ext),
3678  MYF(MY_FAE+MY_WME));
3679  if (!*logname)
3680  return true;
3681  }
3682  logger.lock_exclusive();
3683  mysql_mutex_unlock(&LOCK_global_system_variables);
3684  if (enabled)
3685  reopen(*logname);
3686  logger.unlock();
3687  mysql_mutex_lock(&LOCK_global_system_variables);
3688  return false;
3689 }
3690 static void reopen_general_log(char* name)
3691 {
3692  logger.get_log_file_handler()->close(0);
3693  logger.get_log_file_handler()->open_query_log(name);
3694 }
3695 static bool fix_general_log_file(sys_var *self, THD *thd, enum_var_type type)
3696 {
3697  return fix_log(&opt_logname, default_logfile_name, ".log", opt_log,
3698  reopen_general_log);
3699 }
3700 static Sys_var_charptr Sys_general_log_path(
3701  "general_log_file", "Log connections and queries to given file",
3702  GLOBAL_VAR(opt_logname), CMD_LINE(REQUIRED_ARG),
3703  IN_FS_CHARSET, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG,
3704  ON_CHECK(check_log_path), ON_UPDATE(fix_general_log_file));
3705 
3706 static void reopen_slow_log(char* name)
3707 {
3708  logger.get_slow_log_file_handler()->close(0);
3709  logger.get_slow_log_file_handler()->open_slow_log(name);
3710 }
3711 static bool fix_slow_log_file(sys_var *self, THD *thd, enum_var_type type)
3712 {
3713  return fix_log(&opt_slow_logname, default_logfile_name, "-slow.log",
3714  opt_slow_log, reopen_slow_log);
3715 }
3716 static Sys_var_charptr Sys_slow_log_path(
3717  "slow_query_log_file", "Log slow queries to given log file. "
3718  "Defaults logging to hostname-slow.log. Must be enabled to activate "
3719  "other slow log options",
3720  GLOBAL_VAR(opt_slow_logname), CMD_LINE(REQUIRED_ARG),
3721  IN_FS_CHARSET, DEFAULT(0), NO_MUTEX_GUARD, NOT_IN_BINLOG,
3722  ON_CHECK(check_log_path), ON_UPDATE(fix_slow_log_file));
3723 
3724 static Sys_var_have Sys_have_compress(
3725  "have_compress", "have_compress",
3726  READ_ONLY GLOBAL_VAR(have_compress), NO_CMD_LINE);
3727 
3728 static Sys_var_have Sys_have_crypt(
3729  "have_crypt", "have_crypt",
3730  READ_ONLY GLOBAL_VAR(have_crypt), NO_CMD_LINE);
3731 
3732 static Sys_var_have Sys_have_dlopen(
3733  "have_dynamic_loading", "have_dynamic_loading",
3734  READ_ONLY GLOBAL_VAR(have_dlopen), NO_CMD_LINE);
3735 
3736 static Sys_var_have Sys_have_geometry(
3737  "have_geometry", "have_geometry",
3738  READ_ONLY GLOBAL_VAR(have_geometry), NO_CMD_LINE);
3739 
3740 static Sys_var_have Sys_have_openssl(
3741  "have_openssl", "have_openssl",
3742  READ_ONLY GLOBAL_VAR(have_ssl), NO_CMD_LINE);
3743 
3744 static Sys_var_have Sys_have_profiling(
3745  "have_profiling", "have_profiling",
3746  READ_ONLY GLOBAL_VAR(have_profiling), NO_CMD_LINE, NO_MUTEX_GUARD,
3747  NOT_IN_BINLOG, ON_CHECK(0), ON_UPDATE(0), DEPRECATED(""));
3748 
3749 static Sys_var_have Sys_have_query_cache(
3750  "have_query_cache", "have_query_cache",
3751  READ_ONLY GLOBAL_VAR(have_query_cache), NO_CMD_LINE);
3752 
3753 static Sys_var_have Sys_have_rtree_keys(
3754  "have_rtree_keys", "have_rtree_keys",
3755  READ_ONLY GLOBAL_VAR(have_rtree_keys), NO_CMD_LINE);
3756 
3757 static Sys_var_have Sys_have_ssl(
3758  "have_ssl", "have_ssl",
3759  READ_ONLY GLOBAL_VAR(have_ssl), NO_CMD_LINE);
3760 
3761 static Sys_var_have Sys_have_symlink(
3762  "have_symlink", "have_symlink",
3763  READ_ONLY GLOBAL_VAR(have_symlink), NO_CMD_LINE);
3764 
3765 static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type);
3766 static Sys_var_mybool Sys_general_log(
3767  "general_log", "Log connections and queries to a table or log file. "
3768  "Defaults logging to a file hostname.log or a table mysql.general_log"
3769  "if --log-output=TABLE is used",
3770  GLOBAL_VAR(opt_log), CMD_LINE(OPT_ARG),
3771  DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3772  ON_UPDATE(fix_log_state));
3773 
3774 static Sys_var_mybool Sys_slow_query_log(
3775  "slow_query_log",
3776  "Log slow queries to a table or log file. Defaults logging to a file "
3777  "hostname-slow.log or a table mysql.slow_log if --log-output=TABLE is "
3778  "used. Must be enabled to activate other slow log options",
3779  GLOBAL_VAR(opt_slow_log), CMD_LINE(OPT_ARG),
3780  DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0),
3781  ON_UPDATE(fix_log_state));
3782 
3783 
3784 static bool fix_log_state(sys_var *self, THD *thd, enum_var_type type)
3785 {
3786  bool res;
3787  my_bool *UNINIT_VAR(newvalptr), newval, UNINIT_VAR(oldval);
3788  uint UNINIT_VAR(log_type);
3789 
3790  if (self == &Sys_general_log)
3791  {
3792  newvalptr= &opt_log;
3793  oldval= logger.get_log_file_handler()->is_open();
3794  log_type= QUERY_LOG_GENERAL;
3795  }
3796  else if (self == &Sys_slow_query_log)
3797  {
3798  newvalptr= &opt_slow_log;
3799  oldval= logger.get_slow_log_file_handler()->is_open();
3800  log_type= QUERY_LOG_SLOW;
3801  }
3802  else
3803  DBUG_ASSERT(FALSE);
3804 
3805  newval= *newvalptr;
3806  if (oldval == newval)
3807  return false;
3808 
3809  *newvalptr= oldval; // [de]activate_log_handler works that way (sigh)
3810 
3811  mysql_mutex_unlock(&LOCK_global_system_variables);
3812  if (!newval)
3813  {
3814  logger.deactivate_log_handler(thd, log_type);
3815  res= false;
3816  }
3817  else
3818  res= logger.activate_log_handler(thd, log_type);
3819  mysql_mutex_lock(&LOCK_global_system_variables);
3820  return res;
3821 }
3822 
3823 static bool check_not_empty_set(sys_var *self, THD *thd, set_var *var)
3824 {
3825  return var->save_result.ulonglong_value == 0;
3826 }
3827 static bool fix_log_output(sys_var *self, THD *thd, enum_var_type type)
3828 {
3829  logger.lock_exclusive();
3830  logger.init_slow_log(log_output_options);
3831  logger.init_general_log(log_output_options);
3832  logger.unlock();
3833  return false;
3834 }
3835 
3836 static const char *log_output_names[] = { "NONE", "FILE", "TABLE", NULL};
3837 
3838 static Sys_var_set Sys_log_output(
3839  "log_output", "Syntax: log-output=value[,value...], "
3840  "where \"value\" could be TABLE, FILE or NONE",
3841  GLOBAL_VAR(log_output_options), CMD_LINE(REQUIRED_ARG),
3842  log_output_names, DEFAULT(LOG_FILE), NO_MUTEX_GUARD, NOT_IN_BINLOG,
3843  ON_CHECK(check_not_empty_set), ON_UPDATE(fix_log_output));
3844 
3845 #ifdef HAVE_REPLICATION
3846 static Sys_var_mybool Sys_log_slave_updates(
3847  "log_slave_updates", "Tells the slave to log the updates from "
3848  "the slave thread to the binary log. You will need to turn it on if "
3849  "you plan to daisy-chain the slaves",
3850  READ_ONLY GLOBAL_VAR(opt_log_slave_updates), CMD_LINE(OPT_ARG),
3851  DEFAULT(0));
3852 
3853 static Sys_var_charptr Sys_relay_log(
3854  "relay_log", "The location and name to use for relay logs",
3855  READ_ONLY GLOBAL_VAR(opt_relay_logname), CMD_LINE(REQUIRED_ARG),
3856  IN_FS_CHARSET, DEFAULT(0));
3857 
3858 /*
3859  Uses NO_CMD_LINE since the --relay-log-index option set
3860  opt_relaylog_index_name variable and computes a value for the
3861  relay_log_index variable.
3862 */
3863 static Sys_var_charptr Sys_relay_log_index(
3864  "relay_log_index", "The location and name to use for the file "
3865  "that keeps a list of the last relay logs",
3866  READ_ONLY GLOBAL_VAR(relay_log_index), NO_CMD_LINE,
3867  IN_FS_CHARSET, DEFAULT(0));
3868 
3869 /*
3870  Uses NO_CMD_LINE since the --log-bin-index option set
3871  opt_binlog_index_name variable and computes a value for the
3872  log_bin_index variable.
3873 */
3874 static Sys_var_charptr Sys_binlog_index(
3875  "log_bin_index", "File that holds the names for last binary log files.",
3876  READ_ONLY GLOBAL_VAR(log_bin_index), NO_CMD_LINE,
3877  IN_FS_CHARSET, DEFAULT(0));
3878 
3879 static Sys_var_charptr Sys_relay_log_basename(
3880  "relay_log_basename",
3881  "The full path of the relay log file names, excluding the extension.",
3882  READ_ONLY GLOBAL_VAR(relay_log_basename), NO_CMD_LINE,
3883  IN_FS_CHARSET, DEFAULT(0));
3884 
3885 static Sys_var_charptr Sys_log_bin_basename(
3886  "log_bin_basename",
3887  "The full path of the binary log file names, excluding the extension.",
3888  READ_ONLY GLOBAL_VAR(log_bin_basename), NO_CMD_LINE,
3889  IN_FS_CHARSET, DEFAULT(0));
3890 
3891 static Sys_var_charptr Sys_relay_log_info_file(
3892  "relay_log_info_file", "The location and name of the file that "
3893  "remembers where the SQL replication thread is in the relay logs",
3894  READ_ONLY GLOBAL_VAR(relay_log_info_file), CMD_LINE(REQUIRED_ARG),
3895  IN_FS_CHARSET, DEFAULT(0));
3896 
3897 static Sys_var_mybool Sys_relay_log_purge(
3898  "relay_log_purge", "if disabled - do not purge relay logs. "
3899  "if enabled - purge them as soon as they are no more needed",
3900  GLOBAL_VAR(relay_log_purge), CMD_LINE(OPT_ARG), DEFAULT(TRUE));
3901 
3902 static Sys_var_mybool Sys_relay_log_recovery(
3903  "relay_log_recovery", "Enables automatic relay log recovery "
3904  "right after the database startup, which means that the IO Thread "
3905  "starts re-fetching from the master right after the last transaction "
3906  "processed",
3907  READ_ONLY GLOBAL_VAR(relay_log_recovery), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
3908 
3909 static Sys_var_mybool Sys_slave_allow_batching(
3910  "slave_allow_batching", "Allow slave to batch requests",
3911  GLOBAL_VAR(opt_slave_allow_batching),
3912  CMD_LINE(OPT_ARG), DEFAULT(FALSE));
3913 
3914 static Sys_var_charptr Sys_slave_load_tmpdir(
3915  "slave_load_tmpdir", "The location where the slave should put "
3916  "its temporary files when replicating a LOAD DATA INFILE command",
3917  READ_ONLY GLOBAL_VAR(slave_load_tmpdir), CMD_LINE(REQUIRED_ARG),
3918  IN_FS_CHARSET, DEFAULT(0));
3919 
3920 static bool fix_slave_net_timeout(sys_var *self, THD *thd, enum_var_type type)
3921 {
3922  DEBUG_SYNC(thd, "fix_slave_net_timeout");
3923 
3924  /*
3925  Here we have lock on LOCK_global_system_variables and we need
3926  lock on LOCK_active_mi. In START_SLAVE handler, we take these
3927  two locks in different order. This can lead to DEADLOCKs. See
3928  BUG#14236151 for more details.
3929  So we release lock on LOCK_global_system_variables before acquiring
3930  lock on LOCK_active_mi. But this could lead to isolation issues
3931  between multiple seters. Hence introducing secondary guard
3932  for this global variable and releasing the lock here and acquiring
3933  locks back again at the end of this function.
3934  */
3935  mysql_mutex_unlock(&LOCK_slave_net_timeout);
3936  mysql_mutex_unlock(&LOCK_global_system_variables);
3937  mysql_mutex_lock(&LOCK_active_mi);
3938  DBUG_PRINT("info", ("slave_net_timeout=%u mi->heartbeat_period=%.3f",
3939  slave_net_timeout,
3940  (active_mi ? active_mi->heartbeat_period : 0.0)));
3941  if (active_mi != NULL && slave_net_timeout < active_mi->heartbeat_period)
3942  push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
3943  ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX,
3944  ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX));
3945  mysql_mutex_unlock(&LOCK_active_mi);
3946  mysql_mutex_lock(&LOCK_global_system_variables);
3947  mysql_mutex_lock(&LOCK_slave_net_timeout);
3948  return false;
3949 }
3950 static PolyLock_mutex PLock_slave_net_timeout(&LOCK_slave_net_timeout);
3951 static Sys_var_uint Sys_slave_net_timeout(
3952  "slave_net_timeout", "Number of seconds to wait for more data "
3953  "from a master/slave connection before aborting the read",
3954  GLOBAL_VAR(slave_net_timeout), CMD_LINE(REQUIRED_ARG),
3955  VALID_RANGE(1, LONG_TIMEOUT), DEFAULT(SLAVE_NET_TIMEOUT), BLOCK_SIZE(1),
3956  &PLock_slave_net_timeout, NOT_IN_BINLOG, ON_CHECK(0),
3957  ON_UPDATE(fix_slave_net_timeout));
3958 
3959 static bool check_slave_skip_counter(sys_var *self, THD *thd, set_var *var)
3960 {
3961  bool result= false;
3962  mysql_mutex_lock(&LOCK_active_mi);
3963  if (active_mi != NULL)
3964  {
3965  mysql_mutex_lock(&active_mi->rli->run_lock);
3966  if (active_mi->rli->slave_running)
3967  {
3968  my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0));
3969  result= true;
3970  }
3971  if (gtid_mode == 3)
3972  {
3973  my_message(ER_SQL_SLAVE_SKIP_COUNTER_NOT_SETTABLE_IN_GTID_MODE,
3974  ER(ER_SQL_SLAVE_SKIP_COUNTER_NOT_SETTABLE_IN_GTID_MODE),
3975  MYF(0));
3976  result= true;
3977  }
3978  mysql_mutex_unlock(&active_mi->rli->run_lock);
3979  }
3980  mysql_mutex_unlock(&LOCK_active_mi);
3981  return result;
3982 }
3983 static bool fix_slave_skip_counter(sys_var *self, THD *thd, enum_var_type type)
3984 {
3985 
3986  /*
3987  To understand the below two unlock statments, please see comments in
3988  fix_slave_net_timeout function above
3989  */
3990  mysql_mutex_unlock(&LOCK_sql_slave_skip_counter);
3991  mysql_mutex_unlock(&LOCK_global_system_variables);
3992  mysql_mutex_lock(&LOCK_active_mi);
3993  if (active_mi != NULL)
3994  {
3995  mysql_mutex_lock(&active_mi->rli->run_lock);
3996  /*
3997  The following test should normally never be true as we test this
3998  in the check function; To be safe against multiple
3999  SQL_SLAVE_SKIP_COUNTER request, we do the check anyway
4000  */
4001  if (!active_mi->rli->slave_running)
4002  {
4003  mysql_mutex_lock(&active_mi->rli->data_lock);
4004  active_mi->rli->slave_skip_counter= sql_slave_skip_counter;
4005  mysql_mutex_unlock(&active_mi->rli->data_lock);
4006  }
4007  mysql_mutex_unlock(&active_mi->rli->run_lock);
4008  }
4009  mysql_mutex_unlock(&LOCK_active_mi);
4010  mysql_mutex_lock(&LOCK_global_system_variables);
4011  mysql_mutex_lock(&LOCK_sql_slave_skip_counter);
4012  return 0;
4013 }
4014 static PolyLock_mutex PLock_sql_slave_skip_counter(&LOCK_sql_slave_skip_counter);
4015 static Sys_var_uint Sys_slave_skip_counter(
4016  "sql_slave_skip_counter", "sql_slave_skip_counter",
4017  GLOBAL_VAR(sql_slave_skip_counter), NO_CMD_LINE,
4018  VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1),
4019  &PLock_sql_slave_skip_counter, NOT_IN_BINLOG,
4020  ON_CHECK(check_slave_skip_counter), ON_UPDATE(fix_slave_skip_counter));
4021 
4022 static Sys_var_charptr Sys_slave_skip_errors(
4023  "slave_skip_errors", "Tells the slave thread to continue "
4024  "replication when a query event returns an error from the "
4025  "provided list",
4026  READ_ONLY GLOBAL_VAR(opt_slave_skip_errors), CMD_LINE(REQUIRED_ARG),
4027  IN_SYSTEM_CHARSET, DEFAULT(0));
4028 
4029 static Sys_var_ulonglong Sys_relay_log_space_limit(
4030  "relay_log_space_limit", "Maximum space to use for all relay logs",
4031  READ_ONLY GLOBAL_VAR(relay_log_space_limit), CMD_LINE(REQUIRED_ARG),
4032  VALID_RANGE(0, ULONG_MAX), DEFAULT(0), BLOCK_SIZE(1));
4033 
4034 static Sys_var_uint Sys_sync_relaylog_period(
4035  "sync_relay_log", "Synchronously flush relay log to disk after "
4036  "every #th event. Use 0 to disable synchronous flushing",
4037  GLOBAL_VAR(sync_relaylog_period), CMD_LINE(REQUIRED_ARG),
4038  VALID_RANGE(0, UINT_MAX), DEFAULT(10000), BLOCK_SIZE(1));
4039 
4040 static Sys_var_uint Sys_sync_relayloginfo_period(
4041  "sync_relay_log_info", "Synchronously flush relay log info "
4042  "to disk after every #th transaction. Use 0 to disable "
4043  "synchronous flushing",
4044  GLOBAL_VAR(sync_relayloginfo_period), CMD_LINE(REQUIRED_ARG),
4045  VALID_RANGE(0, UINT_MAX), DEFAULT(10000), BLOCK_SIZE(1));
4046 
4047 static Sys_var_uint Sys_checkpoint_mts_period(
4048  "slave_checkpoint_period", "Gather workers' activities to "
4049  "Update progress status of Multi-threaded slave and flush "
4050  "the relay log info to disk after every #th milli-seconds.",
4051  GLOBAL_VAR(opt_mts_checkpoint_period), CMD_LINE(REQUIRED_ARG),
4052 #ifndef DBUG_OFF
4053  VALID_RANGE(0, UINT_MAX), DEFAULT(300), BLOCK_SIZE(1));
4054 #else
4055  VALID_RANGE(1, UINT_MAX), DEFAULT(300), BLOCK_SIZE(1));
4056 #endif /* DBUG_OFF */
4057 
4058 static Sys_var_uint Sys_checkpoint_mts_group(
4059  "slave_checkpoint_group",
4060  "Maximum number of processed transactions by Multi-threaded slave "
4061  "before a checkpoint operation is called to update progress status.",
4062  GLOBAL_VAR(opt_mts_checkpoint_group), CMD_LINE(REQUIRED_ARG),
4063 #ifndef DBUG_OFF
4064  VALID_RANGE(1, MTS_MAX_BITS_IN_GROUP), DEFAULT(512), BLOCK_SIZE(1));
4065 #else
4066  VALID_RANGE(32, MTS_MAX_BITS_IN_GROUP), DEFAULT(512), BLOCK_SIZE(8));
4067 #endif /* DBUG_OFF */
4068 #endif /* HAVE_REPLICATION */
4069 
4070 static Sys_var_uint Sys_sync_binlog_period(
4071  "sync_binlog", "Synchronously flush binary log to disk after"
4072  " every #th write to the file. Use 0 (default) to disable synchronous"
4073  " flushing",
4074  GLOBAL_VAR(sync_binlog_period), CMD_LINE(REQUIRED_ARG),
4075  VALID_RANGE(0, UINT_MAX), DEFAULT(0), BLOCK_SIZE(1));
4076 
4077 static Sys_var_uint Sys_sync_masterinfo_period(
4078  "sync_master_info", "Synchronously flush master info to disk "
4079  "after every #th event. Use 0 to disable synchronous flushing",
4080  GLOBAL_VAR(sync_masterinfo_period), CMD_LINE(REQUIRED_ARG),
4081  VALID_RANGE(0, UINT_MAX), DEFAULT(10000), BLOCK_SIZE(1));
4082 
4083 #ifdef HAVE_REPLICATION
4084 static Sys_var_ulong Sys_slave_trans_retries(
4085  "slave_transaction_retries", "Number of times the slave SQL "
4086  "thread will retry a transaction in case it failed with a deadlock "
4087  "or elapsed lock wait timeout, before giving up and stopping",
4088  GLOBAL_VAR(slave_trans_retries), CMD_LINE(REQUIRED_ARG),
4089  VALID_RANGE(0, ULONG_MAX), DEFAULT(10), BLOCK_SIZE(1));
4090 
4091 static Sys_var_ulong Sys_slave_parallel_workers(
4092  "slave_parallel_workers",
4093  "Number of worker threads for executing events in parallel ",
4094  GLOBAL_VAR(opt_mts_slave_parallel_workers), CMD_LINE(REQUIRED_ARG),
4095  VALID_RANGE(0, MTS_MAX_WORKERS), DEFAULT(0), BLOCK_SIZE(1));
4096 
4097 static Sys_var_ulonglong Sys_mts_pending_jobs_size_max(
4098  "slave_pending_jobs_size_max",
4099  "Max size of Slave Worker queues holding yet not applied events."
4100  "The least possible value must be not less than the master side "
4101  "max_allowed_packet.",
4102  GLOBAL_VAR(opt_mts_pending_jobs_size_max), CMD_LINE(REQUIRED_ARG),
4103  VALID_RANGE(1024, (ulonglong)~(intptr)0), DEFAULT(16 * 1024*1024),
4104  BLOCK_SIZE(1024), ON_CHECK(0));
4105 #endif
4106 
4107 static bool check_locale(sys_var *self, THD *thd, set_var *var)
4108 {
4109  if (!var->value)
4110  return false;
4111 
4112  MY_LOCALE *locale;
4113  char buff[STRING_BUFFER_USUAL_SIZE];
4114  if (var->value->result_type() == INT_RESULT)
4115  {
4116  int lcno= (int)var->value->val_int();
4117  if (!(locale= my_locale_by_number(lcno)))
4118  {
4119  my_error(ER_UNKNOWN_LOCALE, MYF(0), llstr(lcno, buff));
4120  return true;
4121  }
4122  if (check_not_null(self, thd, var))
4123  return true;
4124  }
4125  else // STRING_RESULT
4126  {
4127  String str(buff, sizeof(buff), system_charset_info), *res;
4128  if (!(res=var->value->val_str(&str)))
4129  return true;
4130  else if (!(locale= my_locale_by_name(res->c_ptr_safe())))
4131  {
4132  ErrConvString err(res);
4133  my_error(ER_UNKNOWN_LOCALE, MYF(0), err.ptr());
4134  return true;
4135  }
4136  }
4137 
4138  var->save_result.ptr= locale;
4139 
4140  if (!locale->errmsgs->errmsgs)
4141  {
4142  mysql_mutex_lock(&LOCK_error_messages);
4143  if (!locale->errmsgs->errmsgs &&
4144  read_texts(ERRMSG_FILE, locale->errmsgs->language,
4145  &locale->errmsgs->errmsgs,
4146  ER_ERROR_LAST - ER_ERROR_FIRST + 1))
4147  {
4148  push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
4149  "Can't process error message file for locale '%s'",
4150  locale->name);
4151  mysql_mutex_unlock(&LOCK_error_messages);
4152  return true;
4153  }
4154  mysql_mutex_unlock(&LOCK_error_messages);
4155  }
4156  return false;
4157 }
4158 static Sys_var_struct Sys_lc_messages(
4159  "lc_messages", "Set the language used for the error messages",
4160  SESSION_VAR(lc_messages), NO_CMD_LINE,
4161  my_offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_messages),
4162  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_locale));
4163 
4164 static Sys_var_struct Sys_lc_time_names(
4165  "lc_time_names", "Set the language used for the month "
4166  "names and the days of the week",
4167  SESSION_VAR(lc_time_names), NO_CMD_LINE,
4168  my_offsetof(MY_LOCALE, name), DEFAULT(&my_default_lc_time_names),
4169  NO_MUTEX_GUARD, IN_BINLOG, ON_CHECK(check_locale));
4170 
4171 static Sys_var_tz Sys_time_zone(
4172  "time_zone", "time_zone",
4173  SESSION_VAR(time_zone), NO_CMD_LINE,
4174  DEFAULT(&default_tz), NO_MUTEX_GUARD, IN_BINLOG);
4175 
4176 static bool fix_host_cache_size(sys_var *, THD *, enum_var_type)
4177 {
4178  hostname_cache_resize((uint) host_cache_size);
4179  return false;
4180 }
4181 
4182 static Sys_var_ulong Sys_host_cache_size(
4183  "host_cache_size",
4184  "How many host names should be cached to avoid resolving.",
4185  GLOBAL_VAR(host_cache_size),
4186  CMD_LINE(REQUIRED_ARG, OPT_HOST_CACHE_SIZE), VALID_RANGE(0, 65536),
4187  DEFAULT(HOST_CACHE_SIZE),
4188  BLOCK_SIZE(1),
4189  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(NULL),
4190  ON_UPDATE(fix_host_cache_size));
4191 
4192 static Sys_var_charptr Sys_ignore_db_dirs(
4193  "ignore_db_dirs",
4194  "The list of directories to ignore when collecting database lists",
4195  READ_ONLY GLOBAL_VAR(opt_ignore_db_dirs),
4196  NO_CMD_LINE,
4197  IN_FS_CHARSET, DEFAULT(0));
4198 
4199 /*
4200  This code is not being used but we will keep it as it may be
4201  useful if we decide to keeep enforce_gtid_consistency.
4202 */
4203 #ifdef NON_DISABLED_GTID
4204 static bool check_enforce_gtid_consistency(
4205  sys_var *self, THD *thd, set_var *var)
4206 {
4207  DBUG_ENTER("check_enforce_gtid_consistency");
4208 
4209  my_error(ER_NOT_SUPPORTED_YET, MYF(0),
4210  "ENFORCE_GTID_CONSISTENCY");
4211  DBUG_RETURN(true);
4212 
4213  if (check_top_level_stmt_and_super(self, thd, var) ||
4214  check_outside_transaction(self, thd, var))
4215  DBUG_RETURN(true);
4216  if (gtid_mode >= 2 && var->value->val_int() == 0)
4217  {
4218  my_error(ER_GTID_MODE_2_OR_3_REQUIRES_ENFORCE_GTID_CONSISTENCY_ON, MYF(0));
4219  DBUG_RETURN(true);
4220  }
4221  DBUG_RETURN(false);
4222 }
4223 #endif
4224 
4225 static Sys_var_mybool Sys_enforce_gtid_consistency(
4226  "enforce_gtid_consistency",
4227  "Prevents execution of statements that would be impossible to log "
4228  "in a transactionally safe manner. Currently, the disallowed "
4229  "statements include CREATE TEMPORARY TABLE inside transactions, "
4230  "all updates to non-transactional tables, and CREATE TABLE ... SELECT.",
4231  READ_ONLY GLOBAL_VAR(enforce_gtid_consistency),
4232  CMD_LINE(OPT_ARG), DEFAULT(FALSE),
4233  NO_MUTEX_GUARD, NOT_IN_BINLOG
4234 #ifdef NON_DISABLED_GTID
4235  , ON_CHECK(check_enforce_gtid_consistency));
4236 #else
4237  );
4238 #endif
4239 
4240 static Sys_var_ulong Sys_sp_cache_size(
4241  "stored_program_cache",
4242  "The soft upper limit for number of cached stored routines for "
4243  "one connection.",
4244  GLOBAL_VAR(stored_program_cache_size), CMD_LINE(REQUIRED_ARG),
4245  VALID_RANGE(256, 512 * 1024), DEFAULT(256), BLOCK_SIZE(1));
4246 
4247 static bool check_pseudo_slave_mode(sys_var *self, THD *thd, set_var *var)
4248 {
4249  longlong previous_val= thd->variables.pseudo_slave_mode;
4250  longlong val= (longlong) var->save_result.ulonglong_value;
4251  bool rli_fake= false;
4252 
4253 #ifndef EMBEDDED_LIBRARY
4254  rli_fake= thd->rli_fake ? true : false;
4255 #endif
4256 
4257  if (rli_fake)
4258  {
4259  if (!val)
4260  {
4261 #ifndef EMBEDDED_LIBRARY
4262  thd->rli_fake->end_info();
4263  delete thd->rli_fake;
4264  thd->rli_fake= NULL;
4265 #endif
4266  }
4267  else if (previous_val && val)
4268  goto ineffective;
4269  else if (!previous_val && val)
4270  push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
4271  ER_WRONG_VALUE_FOR_VAR,
4272  "'pseudo_slave_mode' is already ON.");
4273  }
4274  else
4275  {
4276  if (!previous_val && !val)
4277  goto ineffective;
4278  else if (previous_val && !val)
4279  push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
4280  ER_WRONG_VALUE_FOR_VAR,
4281  "Slave applier execution mode not active, "
4282  "statement ineffective.");
4283  }
4284  goto end;
4285 
4286 ineffective:
4287  push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
4288  ER_WRONG_VALUE_FOR_VAR,
4289  "'pseudo_slave_mode' change was ineffective.");
4290 
4291 end:
4292  return FALSE;
4293 }
4294 static Sys_var_mybool Sys_pseudo_slave_mode(
4295  "pseudo_slave_mode",
4296  "SET pseudo_slave_mode= 0,1 are commands that mysqlbinlog "
4297  "adds to beginning and end of binary log dumps. While zero "
4298  "value indeed disables, the actual enabling of the slave "
4299  "applier execution mode is done implicitly when a "
4300  "Format_description_event is sent through the session.",
4301  SESSION_ONLY(pseudo_slave_mode), NO_CMD_LINE, DEFAULT(FALSE),
4302  NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_pseudo_slave_mode));
4303 
4304 
4305 #ifdef HAVE_REPLICATION
4306 static bool check_gtid_next(sys_var *self, THD *thd, set_var *var)
4307 {
4308  DBUG_ENTER("check_gtid_next");
4309 
4310  // Note: we also check in sql_yacc.yy:set_system_variable that the
4311  // SET GTID_NEXT statement does not invoke a stored function.
4312 
4313  DBUG_PRINT("info", ("thd->in_sub_stmt=%d", thd->in_sub_stmt));
4314 
4315  // GTID_NEXT must be set by SUPER in a top-level statement
4316  if (check_top_level_stmt_and_super(self, thd, var))
4317  DBUG_RETURN(true);
4318 
4319  // check compatibility with GTID_NEXT
4320  const Gtid_set *gtid_next_list= thd->get_gtid_next_list_const();
4321 
4322  // Inside a transaction, GTID_NEXT is read-only if GTID_NEXT_LIST is
4323  // NULL.
4324  if (thd->in_active_multi_stmt_transaction() && gtid_next_list == NULL)
4325  {
4326  my_error(ER_CANT_CHANGE_GTID_NEXT_IN_TRANSACTION_WHEN_GTID_NEXT_LIST_IS_NULL, MYF(0));
4327  DBUG_RETURN(true);
4328  }
4329 
4330  // Read specification
4331  Gtid_specification spec;
4332  global_sid_lock->rdlock();
4333  if (spec.parse(global_sid_map, var->save_result.string_value.str) !=
4334  RETURN_STATUS_OK)
4335  {
4336  // fail on out of memory
4337  global_sid_lock->unlock();
4338  DBUG_RETURN(true);
4339  }
4340  global_sid_lock->unlock();
4341 
4342  // check compatibility with GTID_MODE
4343  if (gtid_mode == 0 && spec.type == GTID_GROUP)
4344  my_error(ER_CANT_SET_GTID_NEXT_TO_GTID_WHEN_GTID_MODE_IS_OFF, MYF(0));
4345  if (gtid_mode == 3 && spec.type == ANONYMOUS_GROUP)
4346  my_error(ER_CANT_SET_GTID_NEXT_TO_ANONYMOUS_WHEN_GTID_MODE_IS_ON, MYF(0));
4347 
4348  if (gtid_next_list != NULL)
4349  {
4350 #ifdef HAVE_GTID_NEXT_LIST
4351  // If GTID_NEXT==SID:GNO, then SID:GNO must be listed in GTID_NEXT_LIST
4352  if (spec.type == GTID_GROUP && !gtid_next_list->contains_gtid(spec.gtid))
4353  {
4354  char buf[Gtid_specification::MAX_TEXT_LENGTH + 1];
4355  global_sid_lock->rdlock();
4356  spec.gtid.to_string(global_sid_map, buf);
4357  global_sid_lock->unlock();
4358  my_error(ER_GTID_NEXT_IS_NOT_IN_GTID_NEXT_LIST, MYF(0), buf);
4359  DBUG_RETURN(true);
4360  }
4361 
4362  // GTID_NEXT cannot be "AUTOMATIC" when GTID_NEXT_LIST != NULL.
4363  if (spec.type == AUTOMATIC_GROUP)
4364  {
4365  my_error(ER_GTID_NEXT_CANT_BE_AUTOMATIC_IF_GTID_NEXT_LIST_IS_NON_NULL,
4366  MYF(0));
4367  DBUG_RETURN(true);
4368  }
4369 #else
4370  DBUG_ASSERT(0);
4371 #endif
4372  }
4373  // check that we don't own a GTID
4374  else if(thd->owned_gtid.sidno != 0)
4375  {
4376  char buf[Gtid::MAX_TEXT_LENGTH + 1];
4377 #ifndef DBUG_OFF
4378  DBUG_ASSERT(thd->owned_gtid.sidno > 0);
4379  global_sid_lock->wrlock();
4380  DBUG_ASSERT(gtid_state->get_owned_gtids()->
4381  thread_owns_anything(thd->thread_id));
4382 #else
4383  global_sid_lock->rdlock();
4384 #endif
4385  thd->owned_gtid.to_string(global_sid_map, buf);
4386  global_sid_lock->unlock();
4387  my_error(ER_CANT_SET_GTID_NEXT_WHEN_OWNING_GTID, MYF(0), buf);
4388  DBUG_RETURN(true);
4389  }
4390 
4391  DBUG_RETURN(false);
4392 }
4393 
4394 static bool update_gtid_next(sys_var *self, THD *thd, enum_var_type type)
4395 {
4396  DBUG_ASSERT(type == OPT_SESSION);
4397  if (thd->variables.gtid_next.type == GTID_GROUP)
4398  return gtid_acquire_ownership_single(thd) != 0 ? true : false;
4399  return false;
4400 }
4401 
4402 #ifdef HAVE_GTID_NEXT_LIST
4403 static bool check_gtid_next_list(sys_var *self, THD *thd, set_var *var)
4404 {
4405  DBUG_ENTER("check_gtid_next_list");
4406  my_error(ER_NOT_SUPPORTED_YET, MYF(0), "GTID_NEXT_LIST");
4407  if (check_top_level_stmt_and_super(self, thd, var) ||
4408  check_outside_transaction(self, thd, var))
4409  DBUG_RETURN(true);
4410  if (gtid_mode == 0 && var->save_result.string_value.str != NULL)
4411  my_error(ER_CANT_SET_GTID_NEXT_LIST_TO_NON_NULL_WHEN_GTID_MODE_IS_OFF,
4412  MYF(0));
4413  DBUG_RETURN(false);
4414 }
4415 
4416 static bool update_gtid_next_list(sys_var *self, THD *thd, enum_var_type type)
4417 {
4418  DBUG_ASSERT(type == OPT_SESSION);
4419  if (thd->get_gtid_next_list() != NULL)
4420  return gtid_acquire_ownership_multiple(thd) != 0 ? true : false;
4421  return false;
4422 }
4423 
4424 static Sys_var_gtid_set Sys_gtid_next_list(
4425  "gtid_next_list",
4426  "Before re-executing a transaction that contains multiple "
4427  "Global Transaction Identifiers, this variable must be set "
4428  "to the set of all re-executed transactions.",
4429  SESSION_ONLY(gtid_next_list), NO_CMD_LINE,
4430  DEFAULT(NULL), NO_MUTEX_GUARD,
4431  NOT_IN_BINLOG, ON_CHECK(check_gtid_next_list),
4432  ON_UPDATE(update_gtid_next_list)
4433 );
4434 export sys_var *Sys_gtid_next_list_ptr= &Sys_gtid_next_list;
4435 #endif
4436 
4437 static Sys_var_gtid_specification Sys_gtid_next(
4438  "gtid_next",
4439  "Specified the Global Transaction Identifier for the following "
4440  "re-executed statement.",
4441  SESSION_ONLY(gtid_next), NO_CMD_LINE,
4442  DEFAULT("AUTOMATIC"), NO_MUTEX_GUARD,
4443  NOT_IN_BINLOG, ON_CHECK(check_gtid_next), ON_UPDATE(update_gtid_next));
4444 export sys_var *Sys_gtid_next_ptr= &Sys_gtid_next;
4445 
4446 static Sys_var_gtid_executed Sys_gtid_executed(
4447  "gtid_executed",
4448  "The global variable contains the set of GTIDs in the "
4449  "binary log. The session variable contains the set of GTIDs "
4450  "in the current, ongoing transaction.");
4451 
4452 static bool check_gtid_purged(sys_var *self, THD *thd, set_var *var)
4453 {
4454  DBUG_ENTER("check_gtid_purged");
4455 
4456  if (!var->value || check_top_level_stmt(self, thd, var) ||
4457  check_outside_transaction(self, thd, var) ||
4458  check_outside_sp(self, thd, var))
4459  DBUG_RETURN(true);
4460 
4461  if (0 == gtid_mode)
4462  {
4463  my_error(ER_CANT_SET_GTID_PURGED_WHEN_GTID_MODE_IS_OFF, MYF(0));
4464  DBUG_RETURN(true);
4465  }
4466 
4467  if (var->value->result_type() != STRING_RESULT ||
4468  !var->save_result.string_value.str)
4469  DBUG_RETURN(true);
4470 
4471  DBUG_RETURN(false);
4472 }
4473 
4474 Gtid_set *gtid_purged;
4475 static Sys_var_gtid_purged Sys_gtid_purged(
4476  "gtid_purged",
4477  "The set of GTIDs that existed in previous, purged binary logs.",
4478  GLOBAL_VAR(gtid_purged), NO_CMD_LINE,
4479  DEFAULT(NULL), NO_MUTEX_GUARD,
4480  NOT_IN_BINLOG, ON_CHECK(check_gtid_purged));
4481 export sys_var *Sys_gtid_purged_ptr= &Sys_gtid_purged;
4482 
4483 static Sys_var_gtid_owned Sys_gtid_owned(
4484  "gtid_owned",
4485  "The global variable lists all GTIDs owned by all threads. "
4486  "The session variable lists all GTIDs owned by the current thread.");
4487 
4488 /*
4489  This code is not being used but we will keep it as it may be
4490  useful when we improve the code around Sys_gtid_mode.
4491 */
4492 #ifdef NON_DISABLED_GTID
4493 static bool check_gtid_mode(sys_var *self, THD *thd, set_var *var)
4494 {
4495  DBUG_ENTER("check_gtid_mode");
4496 
4497  my_error(ER_NOT_SUPPORTED_YET, MYF(0), "GTID_MODE");
4498  DBUG_RETURN(true);
4499 
4500  if (check_top_level_stmt_and_super(self, thd, var) ||
4501  check_outside_transaction(self, thd, var))
4502  DBUG_RETURN(true);
4503  uint new_gtid_mode= var->value->val_int();
4504  if (abs((long)(new_gtid_mode - gtid_mode)) > 1)
4505  {
4506  my_error(ER_GTID_MODE_CAN_ONLY_CHANGE_ONE_STEP_AT_A_TIME, MYF(0));
4507  DBUG_RETURN(true);
4508  }
4509  if (new_gtid_mode >= 1)
4510  {
4511  if (!opt_bin_log || !opt_log_slave_updates)
4512  {
4513  my_error(ER_GTID_MODE_REQUIRES_BINLOG, MYF(0));
4514  DBUG_RETURN(false);
4515  }
4516  }
4517  if (new_gtid_mode >= 2)
4518  {
4519  /*
4520  if (new_gtid_mode == 3 &&
4521  (there are un-processed anonymous transactions in relay log ||
4522  there is a client executing an anonymous transaction))
4523  {
4524  my_error(ER_CANT_SET_GTID_MODE_3_WITH_UNPROCESSED_ANONYMOUS_GROUPS,
4525  MYF(0));
4526  DBUG_RETURN(true);
4527  }
4528  */
4529  if (!enforce_gtid_consistency)
4530  {
4531  //my_error(ER_GTID_MODE_2_OR_3_REQUIRES_ENFORCE_GTID_CONSISTENCY), MYF(0));
4532  DBUG_RETURN(true);
4533  }
4534  }
4535  else
4536  {
4537  /*
4538  if (new_gtid_mode == 0 &&
4539  (there are un-processed GTIDs in relay log ||
4540  there is a client executing a GTID transaction))
4541  {
4542  my_error(ER_CANT_SET_GTID_MODE_0_WITH_UNPROCESSED_GTID_GROUPS, MYF(0));
4543  DBUG_RETURN(true);
4544  }
4545  */
4546  }
4547  DBUG_RETURN(false);
4548 }
4549 #endif
4550 
4551 static Sys_var_enum Sys_gtid_mode(
4552  "gtid_mode",
4553  /*
4554  "Whether Global Transaction Identifiers (GTIDs) are enabled: OFF, "
4555  "UPGRADE_STEP_1, UPGRADE_STEP_2, or ON. OFF means GTIDs are not "
4556  "supported at all, ON means GTIDs are supported by all servers in "
4557  "the replication topology. To safely switch from OFF to ON, first "
4558  "set all servers to UPGRADE_STEP_1, then set all servers to "
4559  "UPGRADE_STEP_2, then wait for all anonymous transactions to "
4560  "be re-executed on all servers, and finally set all servers to ON.",
4561  */
4562  "Whether Global Transaction Identifiers (GTIDs) are enabled. Can be "
4563  "ON or OFF.",
4564  READ_ONLY GLOBAL_VAR(gtid_mode), CMD_LINE(REQUIRED_ARG),
4565  gtid_mode_names, DEFAULT(GTID_MODE_OFF),
4566  NO_MUTEX_GUARD, NOT_IN_BINLOG
4567 #ifdef NON_DISABLED_GTID
4568  , ON_CHECK(check_gtid_mode));
4569 #else
4570  );
4571 #endif
4572 
4573 #endif // HAVE_REPLICATION
4574 
4575 
4576 static Sys_var_mybool Sys_disconnect_on_expired_password(
4577  "disconnect_on_expired_password",
4578  "Give clients that don't signal password expiration support execution time error(s) instead of connection error",
4579  READ_ONLY GLOBAL_VAR(disconnect_on_expired_password),
4580  CMD_LINE(OPT_ARG), DEFAULT(TRUE));
4581 
4582 #ifndef NO_EMBEDDED_ACCESS_CHECKS
4583 static Sys_var_mybool Sys_validate_user_plugins(
4584  "validate_user_plugins",
4585  "Turns on additional validation of authentication plugins assigned "
4586  "to user accounts. ",
4587  READ_ONLY NOT_VISIBLE GLOBAL_VAR(validate_user_plugins),
4588  CMD_LINE(OPT_ARG), DEFAULT(TRUE),
4589  NO_MUTEX_GUARD, NOT_IN_BINLOG);
4590 #endif
4591