00001 /* Copyright (C) 2000-2003 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* 00018 Handling of MySQL SQL variables 00019 00020 To add a new variable, one has to do the following: 00021 00022 - Use one of the 'sys_var... classes from set_var.h or write a specific 00023 one for the variable type. 00024 - Define it in the 'variable definition list' in this file. 00025 - If the variable is thread specific, add it to 'system_variables' struct. 00026 If not, add it to mysqld.cc and an declaration in 'mysql_priv.h' 00027 - If the variable should be changed from the command line, add a definition 00028 of it in the my_option structure list in mysqld.cc 00029 - Don't forget to initialize new fields in global_system_variables and 00030 max_system_variables! 00031 - If the variable should show up in 'show variables' add it to the 00032 init_vars[] struct in this file 00033 00034 NOTES: 00035 - Be careful with var->save_result: sys_var::check() only updates 00036 ulonglong_value; so other members of the union are garbage then; to use 00037 them you must first assign a value to them (in specific ::check() for 00038 example). 00039 00040 TODO: 00041 - Add full support for the variable character_set (for 4.1) 00042 00043 - When updating myisam_delay_key_write, we should do a 'flush tables' 00044 of all MyISAM tables to ensure that they are reopen with the 00045 new attribute. 00046 */ 00047 00048 #ifdef USE_PRAGMA_IMPLEMENTATION 00049 #pragma implementation // gcc: Class implementation 00050 #endif 00051 00052 #include "mysql_priv.h" 00053 #include <mysql.h> 00054 #include "slave.h" 00055 #include <my_getopt.h> 00056 #include <thr_alarm.h> 00057 #include <myisam.h> 00058 #include <my_dir.h> 00059 00060 #include "event_scheduler.h" 00061 00062 /* WITH_INNOBASE_STORAGE_ENGINE */ 00063 extern uint innobase_flush_log_at_trx_commit; 00064 extern ulong innobase_fast_shutdown; 00065 extern long innobase_mirrored_log_groups, innobase_log_files_in_group; 00066 extern longlong innobase_log_file_size; 00067 extern long innobase_log_buffer_size; 00068 extern longlong innobase_buffer_pool_size; 00069 extern long innobase_additional_mem_pool_size; 00070 extern long innobase_buffer_pool_awe_mem_mb; 00071 extern long innobase_file_io_threads, innobase_lock_wait_timeout; 00072 extern long innobase_force_recovery; 00073 extern long innobase_open_files; 00074 extern char *innobase_data_home_dir, *innobase_data_file_path; 00075 extern char *innobase_log_group_home_dir, *innobase_log_arch_dir; 00076 extern char *innobase_unix_file_flush_method; 00077 /* The following variables have to be my_bool for SHOW VARIABLES to work */ 00078 extern my_bool innobase_log_archive, 00079 innobase_use_doublewrite, 00080 innobase_use_checksums, 00081 innobase_file_per_table, 00082 innobase_locks_unsafe_for_binlog; 00083 00084 extern "C" { 00085 extern ulong srv_max_buf_pool_modified_pct; 00086 extern ulong srv_max_purge_lag; 00087 extern ulong srv_auto_extend_increment; 00088 extern ulong srv_n_spin_wait_rounds; 00089 extern ulong srv_n_free_tickets_to_enter; 00090 extern ulong srv_thread_sleep_delay; 00091 extern ulong srv_thread_concurrency; 00092 extern ulong srv_commit_concurrency; 00093 extern ulong srv_flush_log_at_trx_commit; 00094 } 00095 00096 /* WITH_NDBCLUSTER_STORAGE_ENGINE */ 00097 extern ulong ndb_cache_check_time; 00098 extern ulong ndb_extra_logging; 00099 #ifdef HAVE_NDB_BINLOG 00100 extern ulong ndb_report_thresh_binlog_epoch_slip; 00101 extern ulong ndb_report_thresh_binlog_mem_usage; 00102 #endif 00103 00104 00105 00106 static HASH system_variable_hash; 00107 const char *bool_type_names[]= { "OFF", "ON", NullS }; 00108 TYPELIB bool_typelib= 00109 { 00110 array_elements(bool_type_names)-1, "", bool_type_names, NULL 00111 }; 00112 00113 const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS }; 00114 TYPELIB delay_key_write_typelib= 00115 { 00116 array_elements(delay_key_write_type_names)-1, "", 00117 delay_key_write_type_names, NULL 00118 }; 00119 00120 static int sys_check_charset(THD *thd, set_var *var); 00121 static bool sys_update_charset(THD *thd, set_var *var); 00122 static void sys_set_default_charset(THD *thd, enum_var_type type); 00123 static int sys_check_ftb_syntax(THD *thd, set_var *var); 00124 static bool sys_update_ftb_syntax(THD *thd, set_var * var); 00125 static void sys_default_ftb_syntax(THD *thd, enum_var_type type); 00126 static bool sys_update_init_connect(THD*, set_var*); 00127 static void sys_default_init_connect(THD*, enum_var_type type); 00128 static bool sys_update_init_slave(THD*, set_var*); 00129 static void sys_default_init_slave(THD*, enum_var_type type); 00130 static bool set_option_bit(THD *thd, set_var *var); 00131 static bool set_option_autocommit(THD *thd, set_var *var); 00132 static int check_log_update(THD *thd, set_var *var); 00133 static bool set_log_update(THD *thd, set_var *var); 00134 static int check_pseudo_thread_id(THD *thd, set_var *var); 00135 void fix_binlog_format_after_update(THD *thd, enum_var_type type); 00136 static void fix_low_priority_updates(THD *thd, enum_var_type type); 00137 static int check_tx_isolation(THD *thd, set_var *var); 00138 static void fix_tx_isolation(THD *thd, enum_var_type type); 00139 static int check_completion_type(THD *thd, set_var *var); 00140 static void fix_completion_type(THD *thd, enum_var_type type); 00141 static void fix_net_read_timeout(THD *thd, enum_var_type type); 00142 static void fix_net_write_timeout(THD *thd, enum_var_type type); 00143 static void fix_net_retry_count(THD *thd, enum_var_type type); 00144 static void fix_max_join_size(THD *thd, enum_var_type type); 00145 static void fix_query_cache_size(THD *thd, enum_var_type type); 00146 static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type); 00147 static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type); 00148 static void fix_max_binlog_size(THD *thd, enum_var_type type); 00149 static void fix_max_relay_log_size(THD *thd, enum_var_type type); 00150 static void fix_max_connections(THD *thd, enum_var_type type); 00151 static int check_max_delayed_threads(THD *thd, set_var *var); 00152 static void fix_thd_mem_root(THD *thd, enum_var_type type); 00153 static void fix_trans_mem_root(THD *thd, enum_var_type type); 00154 static void fix_server_id(THD *thd, enum_var_type type); 00155 static KEY_CACHE *create_key_cache(const char *name, uint length); 00156 void fix_sql_mode_var(THD *thd, enum_var_type type); 00157 static byte *get_error_count(THD *thd); 00158 static byte *get_warning_count(THD *thd); 00159 static byte *get_prepared_stmt_count(THD *thd); 00160 static byte *get_tmpdir(THD *thd); 00161 static int sys_check_log_path(THD *thd, set_var *var); 00162 static bool sys_update_general_log_path(THD *thd, set_var * var); 00163 static void sys_default_general_log_path(THD *thd, enum_var_type type); 00164 static bool sys_update_slow_log_path(THD *thd, set_var * var); 00165 static void sys_default_slow_log_path(THD *thd, enum_var_type type); 00166 00167 /* 00168 Variable definition list 00169 00170 These are variables that can be set from the command line, in 00171 alphabetic order. 00172 00173 The variables are linked into the list. A variable is added to 00174 it in the constructor (see sys_var class for details). 00175 */ 00176 00177 sys_var *sys_var::first= NULL; 00178 uint sys_var::sys_vars= 0; 00179 00180 sys_var_thd_ulong sys_auto_increment_increment("auto_increment_increment", 00181 &SV::auto_increment_increment); 00182 sys_var_thd_ulong sys_auto_increment_offset("auto_increment_offset", 00183 &SV::auto_increment_offset); 00184 00185 sys_var_bool_ptr sys_automatic_sp_privileges("automatic_sp_privileges", 00186 &sp_automatic_privileges); 00187 00188 sys_var_const_str sys_basedir("basedir", mysql_home); 00189 sys_var_long_ptr sys_binlog_cache_size("binlog_cache_size", 00190 &binlog_cache_size); 00191 sys_var_thd_binlog_format sys_binlog_format("binlog_format", 00192 &SV::binlog_format); 00193 sys_var_thd_ulong sys_bulk_insert_buff_size("bulk_insert_buffer_size", 00194 &SV::bulk_insert_buff_size); 00195 sys_var_character_set_server sys_character_set_server("character_set_server"); 00196 sys_var_const_str sys_charset_system("character_set_system", 00197 (char *)my_charset_utf8_general_ci.name); 00198 sys_var_character_set_database sys_character_set_database("character_set_database"); 00199 sys_var_character_set_client sys_character_set_client("character_set_client"); 00200 sys_var_character_set_connection sys_character_set_connection("character_set_connection"); 00201 sys_var_character_set_results sys_character_set_results("character_set_results"); 00202 sys_var_character_set_filesystem sys_character_set_filesystem("character_set_filesystem"); 00203 sys_var_thd_ulong sys_completion_type("completion_type", 00204 &SV::completion_type, 00205 check_completion_type, 00206 fix_completion_type); 00207 sys_var_collation_connection sys_collation_connection("collation_connection"); 00208 sys_var_collation_database sys_collation_database("collation_database"); 00209 sys_var_collation_server sys_collation_server("collation_server"); 00210 sys_var_long_ptr sys_concurrent_insert("concurrent_insert", 00211 &myisam_concurrent_insert); 00212 sys_var_long_ptr sys_connect_timeout("connect_timeout", 00213 &connect_timeout); 00214 sys_var_const_str sys_datadir("datadir", mysql_real_data_home); 00215 #ifndef DBUG_OFF 00216 sys_var_thd_dbug sys_dbug("debug"); 00217 #endif 00218 sys_var_enum sys_delay_key_write("delay_key_write", 00219 &delay_key_write_options, 00220 &delay_key_write_typelib, 00221 fix_delay_key_write); 00222 sys_var_long_ptr sys_delayed_insert_limit("delayed_insert_limit", 00223 &delayed_insert_limit); 00224 sys_var_long_ptr sys_delayed_insert_timeout("delayed_insert_timeout", 00225 &delayed_insert_timeout); 00226 sys_var_long_ptr sys_delayed_queue_size("delayed_queue_size", 00227 &delayed_queue_size); 00228 00229 sys_var_event_scheduler sys_event_scheduler("event_scheduler"); 00230 sys_var_long_ptr sys_expire_logs_days("expire_logs_days", 00231 &expire_logs_days); 00232 sys_var_bool_ptr sys_flush("flush", &myisam_flush); 00233 sys_var_long_ptr sys_flush_time("flush_time", &flush_time); 00234 sys_var_str sys_ft_boolean_syntax("ft_boolean_syntax", 00235 sys_check_ftb_syntax, 00236 sys_update_ftb_syntax, 00237 sys_default_ftb_syntax, 00238 ft_boolean_syntax); 00239 sys_var_str sys_init_connect("init_connect", 0, 00240 sys_update_init_connect, 00241 sys_default_init_connect,0); 00242 sys_var_str sys_init_slave("init_slave", 0, 00243 sys_update_init_slave, 00244 sys_default_init_slave,0); 00245 sys_var_thd_ulong sys_interactive_timeout("interactive_timeout", 00246 &SV::net_interactive_timeout); 00247 sys_var_thd_ulong sys_join_buffer_size("join_buffer_size", 00248 &SV::join_buff_size); 00249 sys_var_key_buffer_size sys_key_buffer_size("key_buffer_size"); 00250 sys_var_key_cache_long sys_key_cache_block_size("key_cache_block_size", 00251 offsetof(KEY_CACHE, 00252 param_block_size)); 00253 sys_var_key_cache_long sys_key_cache_division_limit("key_cache_division_limit", 00254 offsetof(KEY_CACHE, 00255 param_division_limit)); 00256 sys_var_key_cache_long sys_key_cache_age_threshold("key_cache_age_threshold", 00257 offsetof(KEY_CACHE, 00258 param_age_threshold)); 00259 sys_var_bool_ptr sys_local_infile("local_infile", 00260 &opt_local_infile); 00261 sys_var_trust_routine_creators 00262 sys_trust_routine_creators("log_bin_trust_routine_creators", 00263 &trust_function_creators); 00264 sys_var_bool_ptr 00265 sys_trust_function_creators("log_bin_trust_function_creators", 00266 &trust_function_creators); 00267 sys_var_bool_ptr 00268 sys_log_queries_not_using_indexes("log_queries_not_using_indexes", 00269 &opt_log_queries_not_using_indexes); 00270 sys_var_thd_ulong sys_log_warnings("log_warnings", &SV::log_warnings); 00271 sys_var_thd_ulong sys_long_query_time("long_query_time", 00272 &SV::long_query_time); 00273 sys_var_thd_bool sys_low_priority_updates("low_priority_updates", 00274 &SV::low_priority_updates, 00275 fix_low_priority_updates); 00276 #ifndef TO_BE_DELETED /* Alias for the low_priority_updates */ 00277 sys_var_thd_bool sys_sql_low_priority_updates("sql_low_priority_updates", 00278 &SV::low_priority_updates, 00279 fix_low_priority_updates); 00280 #endif 00281 sys_var_thd_ulong sys_max_allowed_packet("max_allowed_packet", 00282 &SV::max_allowed_packet); 00283 sys_var_long_ptr sys_max_binlog_cache_size("max_binlog_cache_size", 00284 &max_binlog_cache_size); 00285 sys_var_long_ptr sys_max_binlog_size("max_binlog_size", 00286 &max_binlog_size, 00287 fix_max_binlog_size); 00288 sys_var_long_ptr sys_max_connections("max_connections", 00289 &max_connections, 00290 fix_max_connections); 00291 sys_var_long_ptr sys_max_connect_errors("max_connect_errors", 00292 &max_connect_errors); 00293 sys_var_thd_ulong sys_max_insert_delayed_threads("max_insert_delayed_threads", 00294 &SV::max_insert_delayed_threads, 00295 check_max_delayed_threads, 00296 fix_max_connections); 00297 sys_var_thd_ulong sys_max_delayed_threads("max_delayed_threads", 00298 &SV::max_insert_delayed_threads, 00299 check_max_delayed_threads, 00300 fix_max_connections); 00301 sys_var_thd_ulong sys_max_error_count("max_error_count", 00302 &SV::max_error_count); 00303 sys_var_thd_ulong sys_max_heap_table_size("max_heap_table_size", 00304 &SV::max_heap_table_size); 00305 sys_var_thd_ulong sys_pseudo_thread_id("pseudo_thread_id", 00306 &SV::pseudo_thread_id, 00307 check_pseudo_thread_id, 0); 00308 sys_var_thd_ha_rows sys_max_join_size("max_join_size", 00309 &SV::max_join_size, 00310 fix_max_join_size); 00311 sys_var_thd_ulong sys_max_seeks_for_key("max_seeks_for_key", 00312 &SV::max_seeks_for_key); 00313 sys_var_thd_ulong sys_max_length_for_sort_data("max_length_for_sort_data", 00314 &SV::max_length_for_sort_data); 00315 #ifndef TO_BE_DELETED /* Alias for max_join_size */ 00316 sys_var_thd_ha_rows sys_sql_max_join_size("sql_max_join_size", 00317 &SV::max_join_size, 00318 fix_max_join_size); 00319 #endif 00320 static sys_var_long_ptr_global 00321 sys_max_prepared_stmt_count("max_prepared_stmt_count", 00322 &max_prepared_stmt_count, 00323 &LOCK_prepared_stmt_count); 00324 sys_var_long_ptr sys_max_relay_log_size("max_relay_log_size", 00325 &max_relay_log_size, 00326 fix_max_relay_log_size); 00327 sys_var_thd_ulong sys_max_sort_length("max_sort_length", 00328 &SV::max_sort_length); 00329 sys_var_thd_ulong sys_max_sp_recursion_depth("max_sp_recursion_depth", 00330 &SV::max_sp_recursion_depth); 00331 sys_var_max_user_conn sys_max_user_connections("max_user_connections"); 00332 sys_var_thd_ulong sys_max_tmp_tables("max_tmp_tables", 00333 &SV::max_tmp_tables); 00334 sys_var_long_ptr sys_max_write_lock_count("max_write_lock_count", 00335 &max_write_lock_count); 00336 sys_var_thd_ulong sys_multi_range_count("multi_range_count", 00337 &SV::multi_range_count); 00338 sys_var_long_ptr sys_myisam_data_pointer_size("myisam_data_pointer_size", 00339 &myisam_data_pointer_size); 00340 sys_var_thd_ulonglong sys_myisam_max_sort_file_size("myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1); 00341 sys_var_thd_ulong sys_myisam_repair_threads("myisam_repair_threads", &SV::myisam_repair_threads); 00342 sys_var_thd_ulong sys_myisam_sort_buffer_size("myisam_sort_buffer_size", &SV::myisam_sort_buff_size); 00343 sys_var_bool_ptr sys_myisam_use_mmap("myisam_use_mmap", 00344 &opt_myisam_use_mmap); 00345 00346 sys_var_thd_enum sys_myisam_stats_method("myisam_stats_method", 00347 &SV::myisam_stats_method, 00348 &myisam_stats_method_typelib, 00349 NULL); 00350 00351 sys_var_thd_ulong sys_net_buffer_length("net_buffer_length", 00352 &SV::net_buffer_length); 00353 sys_var_thd_ulong sys_net_read_timeout("net_read_timeout", 00354 &SV::net_read_timeout, 00355 0, fix_net_read_timeout); 00356 sys_var_thd_ulong sys_net_write_timeout("net_write_timeout", 00357 &SV::net_write_timeout, 00358 0, fix_net_write_timeout); 00359 sys_var_thd_ulong sys_net_retry_count("net_retry_count", 00360 &SV::net_retry_count, 00361 0, fix_net_retry_count); 00362 sys_var_thd_bool sys_new_mode("new", &SV::new_mode); 00363 sys_var_thd_bool sys_old_alter_table("old_alter_table", 00364 &SV::old_alter_table); 00365 sys_var_thd_bool sys_old_passwords("old_passwords", &SV::old_passwords); 00366 sys_var_thd_ulong sys_optimizer_prune_level("optimizer_prune_level", 00367 &SV::optimizer_prune_level); 00368 sys_var_thd_ulong sys_optimizer_search_depth("optimizer_search_depth", 00369 &SV::optimizer_search_depth); 00370 sys_var_thd_ulong sys_preload_buff_size("preload_buffer_size", 00371 &SV::preload_buff_size); 00372 sys_var_thd_ulong sys_read_buff_size("read_buffer_size", 00373 &SV::read_buff_size); 00374 sys_var_bool_ptr sys_readonly("read_only", &opt_readonly); 00375 sys_var_thd_ulong sys_read_rnd_buff_size("read_rnd_buffer_size", 00376 &SV::read_rnd_buff_size); 00377 sys_var_thd_ulong sys_div_precincrement("div_precision_increment", 00378 &SV::div_precincrement); 00379 #ifdef HAVE_REPLICATION 00380 sys_var_bool_ptr sys_relay_log_purge("relay_log_purge", 00381 &relay_log_purge); 00382 #endif 00383 sys_var_long_ptr sys_rpl_recovery_rank("rpl_recovery_rank", 00384 &rpl_recovery_rank); 00385 sys_var_long_ptr sys_query_cache_size("query_cache_size", 00386 &query_cache_size, 00387 fix_query_cache_size); 00388 00389 sys_var_thd_ulong sys_range_alloc_block_size("range_alloc_block_size", 00390 &SV::range_alloc_block_size); 00391 sys_var_thd_ulong sys_query_alloc_block_size("query_alloc_block_size", 00392 &SV::query_alloc_block_size, 00393 0, fix_thd_mem_root); 00394 sys_var_thd_ulong sys_query_prealloc_size("query_prealloc_size", 00395 &SV::query_prealloc_size, 00396 0, fix_thd_mem_root); 00397 sys_var_readonly sys_tmpdir("tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir); 00398 sys_var_thd_ulong sys_trans_alloc_block_size("transaction_alloc_block_size", 00399 &SV::trans_alloc_block_size, 00400 0, fix_trans_mem_root); 00401 sys_var_thd_ulong sys_trans_prealloc_size("transaction_prealloc_size", 00402 &SV::trans_prealloc_size, 00403 0, fix_trans_mem_root); 00404 00405 #ifdef HAVE_QUERY_CACHE 00406 sys_var_long_ptr sys_query_cache_limit("query_cache_limit", 00407 &query_cache.query_cache_limit); 00408 sys_var_long_ptr sys_query_cache_min_res_unit("query_cache_min_res_unit", 00409 &query_cache_min_res_unit, 00410 fix_query_cache_min_res_unit); 00411 sys_var_thd_enum sys_query_cache_type("query_cache_type", 00412 &SV::query_cache_type, 00413 &query_cache_type_typelib); 00414 sys_var_thd_bool 00415 sys_query_cache_wlock_invalidate("query_cache_wlock_invalidate", 00416 &SV::query_cache_wlock_invalidate); 00417 #endif /* HAVE_QUERY_CACHE */ 00418 sys_var_bool_ptr sys_secure_auth("secure_auth", &opt_secure_auth); 00419 sys_var_long_ptr sys_server_id("server_id", &server_id, fix_server_id); 00420 sys_var_bool_ptr sys_slave_compressed_protocol("slave_compressed_protocol", 00421 &opt_slave_compressed_protocol); 00422 #ifdef HAVE_REPLICATION 00423 sys_var_long_ptr sys_slave_net_timeout("slave_net_timeout", 00424 &slave_net_timeout); 00425 sys_var_long_ptr sys_slave_trans_retries("slave_transaction_retries", 00426 &slave_trans_retries); 00427 #endif 00428 sys_var_long_ptr sys_slow_launch_time("slow_launch_time", 00429 &slow_launch_time); 00430 sys_var_thd_ulong sys_sort_buffer("sort_buffer_size", 00431 &SV::sortbuff_size); 00432 sys_var_thd_sql_mode sys_sql_mode("sql_mode", 00433 &SV::sql_mode); 00434 #ifdef HAVE_OPENSSL 00435 extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher, 00436 *opt_ssl_key; 00437 sys_var_const_str_ptr sys_ssl_ca("ssl_ca", &opt_ssl_ca); 00438 sys_var_const_str_ptr sys_ssl_capath("ssl_capath", &opt_ssl_capath); 00439 sys_var_const_str_ptr sys_ssl_cert("ssl_cert", &opt_ssl_cert); 00440 sys_var_const_str_ptr sys_ssl_cipher("ssl_cipher", &opt_ssl_cipher); 00441 sys_var_const_str_ptr sys_ssl_key("ssl_key", &opt_ssl_key); 00442 #else 00443 sys_var_const_str sys_ssl_ca("ssl_ca", NULL); 00444 sys_var_const_str sys_ssl_capath("ssl_capath", NULL); 00445 sys_var_const_str sys_ssl_cert("ssl_cert", NULL); 00446 sys_var_const_str sys_ssl_cipher("ssl_cipher", NULL); 00447 sys_var_const_str sys_ssl_key("ssl_key", NULL); 00448 #endif 00449 sys_var_thd_enum 00450 sys_updatable_views_with_limit("updatable_views_with_limit", 00451 &SV::updatable_views_with_limit, 00452 &updatable_views_with_limit_typelib); 00453 00454 sys_var_thd_table_type sys_table_type("table_type", 00455 &SV::table_type); 00456 sys_var_thd_storage_engine sys_storage_engine("storage_engine", 00457 &SV::table_type); 00458 #ifdef HAVE_REPLICATION 00459 sys_var_sync_binlog_period sys_sync_binlog_period("sync_binlog", &sync_binlog_period); 00460 #endif 00461 sys_var_bool_ptr sys_sync_frm("sync_frm", &opt_sync_frm); 00462 sys_var_const_str sys_system_time_zone("system_time_zone", 00463 system_time_zone); 00464 sys_var_long_ptr sys_table_def_size("table_definition_cache", 00465 &table_def_size); 00466 sys_var_long_ptr sys_table_cache_size("table_open_cache", 00467 &table_cache_size); 00468 sys_var_long_ptr sys_table_lock_wait_timeout("table_lock_wait_timeout", 00469 &table_lock_wait_timeout); 00470 sys_var_long_ptr sys_thread_cache_size("thread_cache_size", 00471 &thread_cache_size); 00472 sys_var_thd_enum sys_tx_isolation("tx_isolation", 00473 &SV::tx_isolation, 00474 &tx_isolation_typelib, 00475 fix_tx_isolation, 00476 check_tx_isolation); 00477 sys_var_thd_ulong sys_tmp_table_size("tmp_table_size", 00478 &SV::tmp_table_size); 00479 sys_var_bool_ptr sys_timed_mutexes("timed_mutexes", 00480 &timed_mutexes); 00481 sys_var_const_str sys_version("version", server_version); 00482 sys_var_const_str sys_version_comment("version_comment", 00483 MYSQL_COMPILATION_COMMENT); 00484 sys_var_const_str sys_version_compile_machine("version_compile_machine", 00485 MACHINE_TYPE); 00486 sys_var_const_str sys_version_compile_os("version_compile_os", 00487 SYSTEM_TYPE); 00488 sys_var_thd_ulong sys_net_wait_timeout("wait_timeout", 00489 &SV::net_wait_timeout); 00490 #ifdef WITH_INNOBASE_STORAGE_ENGINE 00491 sys_var_long_ptr sys_innodb_fast_shutdown("innodb_fast_shutdown", 00492 &innobase_fast_shutdown); 00493 sys_var_long_ptr sys_innodb_max_dirty_pages_pct("innodb_max_dirty_pages_pct", 00494 &srv_max_buf_pool_modified_pct); 00495 sys_var_long_ptr sys_innodb_max_purge_lag("innodb_max_purge_lag", 00496 &srv_max_purge_lag); 00497 sys_var_thd_bool sys_innodb_table_locks("innodb_table_locks", 00498 &SV::innodb_table_locks); 00499 sys_var_thd_bool sys_innodb_support_xa("innodb_support_xa", 00500 &SV::innodb_support_xa); 00501 sys_var_long_ptr sys_innodb_autoextend_increment("innodb_autoextend_increment", 00502 &srv_auto_extend_increment); 00503 sys_var_long_ptr sys_innodb_sync_spin_loops("innodb_sync_spin_loops", 00504 &srv_n_spin_wait_rounds); 00505 sys_var_long_ptr sys_innodb_concurrency_tickets("innodb_concurrency_tickets", 00506 &srv_n_free_tickets_to_enter); 00507 sys_var_long_ptr sys_innodb_thread_sleep_delay("innodb_thread_sleep_delay", 00508 &srv_thread_sleep_delay); 00509 sys_var_long_ptr sys_innodb_thread_concurrency("innodb_thread_concurrency", 00510 &srv_thread_concurrency); 00511 sys_var_long_ptr sys_innodb_commit_concurrency("innodb_commit_concurrency", 00512 &srv_commit_concurrency); 00513 sys_var_long_ptr sys_innodb_flush_log_at_trx_commit( 00514 "innodb_flush_log_at_trx_commit", 00515 &srv_flush_log_at_trx_commit); 00516 #endif 00517 /* Condition pushdown to storage engine */ 00518 sys_var_thd_bool 00519 sys_engine_condition_pushdown("engine_condition_pushdown", 00520 &SV::engine_condition_pushdown); 00521 00522 /* ndb thread specific variable settings */ 00523 sys_var_thd_ulong 00524 sys_ndb_autoincrement_prefetch_sz("ndb_autoincrement_prefetch_sz", 00525 &SV::ndb_autoincrement_prefetch_sz); 00526 sys_var_thd_bool 00527 sys_ndb_force_send("ndb_force_send", &SV::ndb_force_send); 00528 #ifdef HAVE_NDB_BINLOG 00529 sys_var_long_ptr 00530 sys_ndb_report_thresh_binlog_epoch_slip("ndb_report_thresh_binlog_epoch_slip", 00531 &ndb_report_thresh_binlog_epoch_slip); 00532 sys_var_long_ptr 00533 sys_ndb_report_thresh_binlog_mem_usage("ndb_report_thresh_binlog_mem_usage", 00534 &ndb_report_thresh_binlog_mem_usage); 00535 #endif 00536 sys_var_thd_bool 00537 sys_ndb_use_exact_count("ndb_use_exact_count", &SV::ndb_use_exact_count); 00538 sys_var_thd_bool 00539 sys_ndb_use_transactions("ndb_use_transactions", &SV::ndb_use_transactions); 00540 sys_var_long_ptr 00541 sys_ndb_cache_check_time("ndb_cache_check_time", &ndb_cache_check_time); 00542 sys_var_thd_bool 00543 sys_ndb_index_stat_enable("ndb_index_stat_enable", 00544 &SV::ndb_index_stat_enable); 00545 sys_var_thd_ulong 00546 sys_ndb_index_stat_cache_entries("ndb_index_stat_cache_entries", 00547 &SV::ndb_index_stat_cache_entries); 00548 sys_var_thd_ulong 00549 sys_ndb_index_stat_update_freq("ndb_index_stat_update_freq", 00550 &SV::ndb_index_stat_update_freq); 00551 sys_var_long_ptr 00552 sys_ndb_extra_logging("ndb_extra_logging", &ndb_extra_logging); 00553 sys_var_thd_bool 00554 sys_ndb_use_copying_alter_table("ndb_use_copying_alter_table", &SV::ndb_use_copying_alter_table); 00555 00556 /* Time/date/datetime formats */ 00557 00558 sys_var_thd_date_time_format sys_time_format("time_format", 00559 &SV::time_format, 00560 MYSQL_TIMESTAMP_TIME); 00561 sys_var_thd_date_time_format sys_date_format("date_format", 00562 &SV::date_format, 00563 MYSQL_TIMESTAMP_DATE); 00564 sys_var_thd_date_time_format sys_datetime_format("datetime_format", 00565 &SV::datetime_format, 00566 MYSQL_TIMESTAMP_DATETIME); 00567 00568 /* Variables that are bits in THD */ 00569 00570 sys_var_thd_bit sys_autocommit("autocommit", 0, 00571 set_option_autocommit, 00572 OPTION_NOT_AUTOCOMMIT, 00573 1); 00574 static sys_var_thd_bit sys_big_tables("big_tables", 0, 00575 set_option_bit, 00576 OPTION_BIG_TABLES); 00577 #ifndef TO_BE_DELETED /* Alias for big_tables */ 00578 static sys_var_thd_bit sys_sql_big_tables("sql_big_tables", 0, 00579 set_option_bit, 00580 OPTION_BIG_TABLES); 00581 #endif 00582 static sys_var_thd_bit sys_big_selects("sql_big_selects", 0, 00583 set_option_bit, 00584 OPTION_BIG_SELECTS); 00585 static sys_var_thd_bit sys_log_off("sql_log_off", 00586 check_log_update, 00587 set_option_bit, 00588 OPTION_LOG_OFF); 00589 static sys_var_thd_bit sys_log_update("sql_log_update", 00590 check_log_update, 00591 set_log_update, 00592 OPTION_BIN_LOG); 00593 static sys_var_thd_bit sys_log_binlog("sql_log_bin", 00594 check_log_update, 00595 set_option_bit, 00596 OPTION_BIN_LOG); 00597 static sys_var_thd_bit sys_sql_warnings("sql_warnings", 0, 00598 set_option_bit, 00599 OPTION_WARNINGS); 00600 static sys_var_thd_bit sys_sql_notes("sql_notes", 0, 00601 set_option_bit, 00602 OPTION_SQL_NOTES); 00603 static sys_var_thd_bit sys_auto_is_null("sql_auto_is_null", 0, 00604 set_option_bit, 00605 OPTION_AUTO_IS_NULL); 00606 static sys_var_thd_bit sys_safe_updates("sql_safe_updates", 0, 00607 set_option_bit, 00608 OPTION_SAFE_UPDATES); 00609 static sys_var_thd_bit sys_buffer_results("sql_buffer_result", 0, 00610 set_option_bit, 00611 OPTION_BUFFER_RESULT); 00612 static sys_var_thd_bit sys_quote_show_create("sql_quote_show_create", 0, 00613 set_option_bit, 00614 OPTION_QUOTE_SHOW_CREATE); 00615 static sys_var_thd_bit sys_foreign_key_checks("foreign_key_checks", 0, 00616 set_option_bit, 00617 OPTION_NO_FOREIGN_KEY_CHECKS, 00618 1); 00619 static sys_var_thd_bit sys_unique_checks("unique_checks", 0, 00620 set_option_bit, 00621 OPTION_RELAXED_UNIQUE_CHECKS, 00622 1); 00623 00624 /* Local state variables */ 00625 00626 static sys_var_thd_ha_rows sys_select_limit("sql_select_limit", 00627 &SV::select_limit); 00628 static sys_var_timestamp sys_timestamp("timestamp"); 00629 static sys_var_last_insert_id sys_last_insert_id("last_insert_id"); 00630 static sys_var_last_insert_id sys_identity("identity"); 00631 00632 static sys_var_thd_lc_time_names sys_lc_time_names("lc_time_names"); 00633 00634 static sys_var_insert_id sys_insert_id("insert_id"); 00635 static sys_var_readonly sys_error_count("error_count", 00636 OPT_SESSION, 00637 SHOW_LONG, 00638 get_error_count); 00639 static sys_var_readonly sys_warning_count("warning_count", 00640 OPT_SESSION, 00641 SHOW_LONG, 00642 get_warning_count); 00643 static sys_var_readonly sys_prepared_stmt_count("prepared_stmt_count", 00644 OPT_GLOBAL, SHOW_LONG, 00645 get_prepared_stmt_count); 00646 00647 /* alias for last_insert_id() to be compatible with Sybase */ 00648 #ifdef HAVE_REPLICATION 00649 static sys_var_slave_skip_counter sys_slave_skip_counter("sql_slave_skip_counter"); 00650 #endif 00651 static sys_var_rand_seed1 sys_rand_seed1("rand_seed1"); 00652 static sys_var_rand_seed2 sys_rand_seed2("rand_seed2"); 00653 00654 static sys_var_thd_ulong sys_default_week_format("default_week_format", 00655 &SV::default_week_format); 00656 00657 sys_var_thd_ulong sys_group_concat_max_len("group_concat_max_len", 00658 &SV::group_concat_max_len); 00659 00660 sys_var_thd_time_zone sys_time_zone("time_zone"); 00661 00662 /* Read only variables */ 00663 00664 sys_var_have_variable sys_have_archive_db("have_archive", &have_archive_db); 00665 sys_var_have_variable sys_have_blackhole_db("have_blackhole_engine", 00666 &have_blackhole_db); 00667 sys_var_have_variable sys_have_compress("have_compress", &have_compress); 00668 sys_var_have_variable sys_have_crypt("have_crypt", &have_crypt); 00669 sys_var_have_variable sys_have_csv_db("have_csv", &have_csv_db); 00670 sys_var_have_variable sys_have_dlopen("have_dynamic_loading", &have_dlopen); 00671 sys_var_have_variable sys_have_example_db("have_example_engine", 00672 &have_example_db); 00673 sys_var_have_variable sys_have_federated_db("have_federated_engine", 00674 &have_federated_db); 00675 sys_var_have_variable sys_have_geometry("have_geometry", &have_geometry); 00676 sys_var_have_variable sys_have_innodb("have_innodb", &have_innodb); 00677 sys_var_have_variable sys_have_merge_db("have_merge", &have_merge_db); 00678 sys_var_have_variable sys_have_ndbcluster("have_ndbcluster", &have_ndbcluster); 00679 sys_var_have_variable sys_have_openssl("have_openssl", &have_openssl); 00680 sys_var_have_variable sys_have_partition_db("have_partitioning", 00681 &have_partition_db); 00682 sys_var_have_variable sys_have_query_cache("have_query_cache", 00683 &have_query_cache); 00684 sys_var_have_variable sys_have_rtree_keys("have_rtree_keys", &have_rtree_keys); 00685 sys_var_have_variable sys_have_symlink("have_symlink", &have_symlink); 00686 sys_var_have_variable sys_have_row_based_replication("have_row_based_replication",&have_row_based_replication); 00687 /* Global read-only variable describing server license */ 00688 sys_var_const_str sys_license("license", STRINGIFY_ARG(LICENSE)); 00689 00690 /* Global variables which enable|disable logging */ 00691 sys_var_log_state sys_var_general_log("general_log", &opt_log, 00692 QUERY_LOG_GENERAL); 00693 sys_var_log_state sys_var_slow_query_log("slow_query_log", &opt_slow_log, 00694 QUERY_LOG_SLOW); 00695 sys_var_str sys_var_general_log_path("general_log_file", sys_check_log_path, 00696 sys_update_general_log_path, 00697 sys_default_general_log_path, 00698 opt_logname); 00699 sys_var_str sys_var_slow_log_path("slow_query_log_file", sys_check_log_path, 00700 sys_update_slow_log_path, 00701 sys_default_slow_log_path, 00702 opt_slow_logname); 00703 sys_var_log_output sys_var_log_output_state("log_output", &log_output_options, 00704 &log_output_typelib, 0); 00705 00706 #ifdef HAVE_REPLICATION 00707 static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff) 00708 { 00709 var->type=SHOW_CHAR; 00710 var->value= buff; 00711 if (!use_slave_mask || bitmap_is_clear_all(&slave_error_mask)) 00712 { 00713 var->value= const_cast<char *>("OFF"); 00714 } 00715 else if (bitmap_is_set_all(&slave_error_mask)) 00716 { 00717 var->value= const_cast<char *>("ALL"); 00718 } 00719 else 00720 { 00721 /* 10 is enough assuming errors are max 4 digits */ 00722 int i; 00723 var->value= buff; 00724 for (i= 1; 00725 i < MAX_SLAVE_ERROR && 00726 (buff - var->value) < SHOW_VAR_FUNC_BUFF_SIZE; 00727 i++) 00728 { 00729 if (bitmap_is_set(&slave_error_mask, i)) 00730 { 00731 buff= int10_to_str(i, buff, 10); 00732 *buff++= ','; 00733 } 00734 } 00735 if (var->value != buff) 00736 buff--; // Remove last ',' 00737 if (i < MAX_SLAVE_ERROR) 00738 buff= strmov(buff, "..."); // Couldn't show all errors 00739 *buff=0; 00740 } 00741 return 0; 00742 } 00743 #endif /* HAVE_REPLICATION */ 00744 00745 /* 00746 Variables shown by SHOW variables in alphabetical order 00747 */ 00748 00749 SHOW_VAR init_vars[]= { 00750 {"auto_increment_increment", (char*) &sys_auto_increment_increment, SHOW_SYS}, 00751 {"auto_increment_offset", (char*) &sys_auto_increment_offset, SHOW_SYS}, 00752 {sys_automatic_sp_privileges.name,(char*) &sys_automatic_sp_privileges, SHOW_SYS}, 00753 {"back_log", (char*) &back_log, SHOW_LONG}, 00754 {sys_basedir.name, (char*) &sys_basedir, SHOW_SYS}, 00755 {sys_binlog_cache_size.name,(char*) &sys_binlog_cache_size, SHOW_SYS}, 00756 {sys_binlog_format.name, (char*) &sys_binlog_format, SHOW_SYS}, 00757 {sys_bulk_insert_buff_size.name,(char*) &sys_bulk_insert_buff_size,SHOW_SYS}, 00758 {sys_character_set_client.name,(char*) &sys_character_set_client, SHOW_SYS}, 00759 {sys_character_set_connection.name,(char*) &sys_character_set_connection,SHOW_SYS}, 00760 {sys_character_set_database.name, (char*) &sys_character_set_database,SHOW_SYS}, 00761 {sys_character_set_filesystem.name,(char*) &sys_character_set_filesystem, SHOW_SYS}, 00762 {sys_character_set_results.name,(char*) &sys_character_set_results, SHOW_SYS}, 00763 {sys_character_set_server.name, (char*) &sys_character_set_server,SHOW_SYS}, 00764 {sys_charset_system.name, (char*) &sys_charset_system, SHOW_SYS}, 00765 {"character_sets_dir", mysql_charsets_dir, SHOW_CHAR}, 00766 {sys_collation_connection.name,(char*) &sys_collation_connection, SHOW_SYS}, 00767 {sys_collation_database.name,(char*) &sys_collation_database, SHOW_SYS}, 00768 {sys_collation_server.name,(char*) &sys_collation_server, SHOW_SYS}, 00769 {sys_completion_type.name, (char*) &sys_completion_type, SHOW_SYS}, 00770 {sys_concurrent_insert.name,(char*) &sys_concurrent_insert, SHOW_SYS}, 00771 {sys_connect_timeout.name, (char*) &sys_connect_timeout, SHOW_SYS}, 00772 {sys_datadir.name, (char*) &sys_datadir, SHOW_SYS}, 00773 {sys_date_format.name, (char*) &sys_date_format, SHOW_SYS}, 00774 {sys_datetime_format.name, (char*) &sys_datetime_format, SHOW_SYS}, 00775 #ifndef DBUG_OFF 00776 {sys_dbug.name, (char*) &sys_dbug, SHOW_SYS}, 00777 #endif 00778 {sys_default_week_format.name, (char*) &sys_default_week_format, SHOW_SYS}, 00779 {sys_delay_key_write.name, (char*) &sys_delay_key_write, SHOW_SYS}, 00780 {sys_delayed_insert_limit.name, (char*) &sys_delayed_insert_limit,SHOW_SYS}, 00781 {sys_delayed_insert_timeout.name, (char*) &sys_delayed_insert_timeout, SHOW_SYS}, 00782 {sys_delayed_queue_size.name,(char*) &sys_delayed_queue_size, SHOW_SYS}, 00783 {sys_div_precincrement.name,(char*) &sys_div_precincrement,SHOW_SYS}, 00784 {sys_engine_condition_pushdown.name, 00785 (char*) &sys_engine_condition_pushdown, SHOW_SYS}, 00786 {sys_event_scheduler.name, (char*) &sys_event_scheduler, SHOW_SYS}, 00787 {sys_expire_logs_days.name, (char*) &sys_expire_logs_days, SHOW_SYS}, 00788 {sys_flush.name, (char*) &sys_flush, SHOW_SYS}, 00789 {sys_flush_time.name, (char*) &sys_flush_time, SHOW_SYS}, 00790 {sys_ft_boolean_syntax.name,(char*) &ft_boolean_syntax, SHOW_CHAR}, 00791 {"ft_max_word_len", (char*) &ft_max_word_len, SHOW_LONG}, 00792 {"ft_min_word_len", (char*) &ft_min_word_len, SHOW_LONG}, 00793 {"ft_query_expansion_limit",(char*) &ft_query_expansion_limit, SHOW_LONG}, 00794 {"ft_stopword_file", (char*) &ft_stopword_file, SHOW_CHAR_PTR}, 00795 {sys_var_general_log.name, (char*) &opt_log, SHOW_MY_BOOL}, 00796 {sys_var_general_log_path.name, (char*) &sys_var_general_log_path, SHOW_SYS}, 00797 {sys_group_concat_max_len.name, (char*) &sys_group_concat_max_len, SHOW_SYS}, 00798 {sys_have_archive_db.name, (char*) &have_archive_db, SHOW_HAVE}, 00799 {sys_have_blackhole_db.name,(char*) &have_blackhole_db, SHOW_HAVE}, 00800 {sys_have_compress.name, (char*) &have_compress, SHOW_HAVE}, 00801 {sys_have_crypt.name, (char*) &have_crypt, SHOW_HAVE}, 00802 {sys_have_csv_db.name, (char*) &have_csv_db, SHOW_HAVE}, 00803 {sys_have_dlopen.name, (char*) &have_dlopen, SHOW_HAVE}, 00804 {sys_have_example_db.name, (char*) &have_example_db, SHOW_HAVE}, 00805 {sys_have_federated_db.name,(char*) &have_federated_db, SHOW_HAVE}, 00806 {sys_have_geometry.name, (char*) &have_geometry, SHOW_HAVE}, 00807 {sys_have_innodb.name, (char*) &have_innodb, SHOW_HAVE}, 00808 {sys_have_merge_db.name, (char*) &have_merge_db, SHOW_HAVE}, 00809 {sys_have_ndbcluster.name, (char*) &have_ndbcluster, SHOW_HAVE}, 00810 {sys_have_openssl.name, (char*) &have_openssl, SHOW_HAVE}, 00811 {sys_have_partition_db.name,(char*) &have_partition_db, SHOW_HAVE}, 00812 {sys_have_query_cache.name, (char*) &have_query_cache, SHOW_HAVE}, 00813 {sys_have_row_based_replication.name, (char*) &have_row_based_replication, SHOW_HAVE}, 00814 {sys_have_rtree_keys.name, (char*) &have_rtree_keys, SHOW_HAVE}, 00815 {sys_have_symlink.name, (char*) &have_symlink, SHOW_HAVE}, 00816 {"init_connect", (char*) &sys_init_connect, SHOW_SYS}, 00817 {"init_file", (char*) &opt_init_file, SHOW_CHAR_PTR}, 00818 {"init_slave", (char*) &sys_init_slave, SHOW_SYS}, 00819 #ifdef WITH_INNOBASE_STORAGE_ENGINE 00820 {"innodb_additional_mem_pool_size", (char*) &innobase_additional_mem_pool_size, SHOW_LONG }, 00821 {sys_innodb_autoextend_increment.name, (char*) &sys_innodb_autoextend_increment, SHOW_SYS}, 00822 {"innodb_buffer_pool_awe_mem_mb", (char*) &innobase_buffer_pool_awe_mem_mb, SHOW_LONG }, 00823 {"innodb_buffer_pool_size", (char*) &innobase_buffer_pool_size, SHOW_LONGLONG }, 00824 {"innodb_checksums", (char*) &innobase_use_checksums, SHOW_MY_BOOL}, 00825 {sys_innodb_commit_concurrency.name, (char*) &sys_innodb_commit_concurrency, SHOW_SYS}, 00826 {sys_innodb_concurrency_tickets.name, (char*) &sys_innodb_concurrency_tickets, SHOW_SYS}, 00827 {"innodb_data_file_path", (char*) &innobase_data_file_path, SHOW_CHAR_PTR}, 00828 {"innodb_data_home_dir", (char*) &innobase_data_home_dir, SHOW_CHAR_PTR}, 00829 {"innodb_doublewrite", (char*) &innobase_use_doublewrite, SHOW_MY_BOOL}, 00830 {sys_innodb_fast_shutdown.name,(char*) &sys_innodb_fast_shutdown, SHOW_SYS}, 00831 {"innodb_file_io_threads", (char*) &innobase_file_io_threads, SHOW_LONG }, 00832 {"innodb_file_per_table", (char*) &innobase_file_per_table, SHOW_MY_BOOL}, 00833 {"innodb_flush_method", (char*) &innobase_unix_file_flush_method, SHOW_CHAR_PTR}, 00834 {"innodb_force_recovery", (char*) &innobase_force_recovery, SHOW_LONG }, 00835 {"innodb_lock_wait_timeout", (char*) &innobase_lock_wait_timeout, SHOW_LONG }, 00836 {"innodb_locks_unsafe_for_binlog", (char*) &innobase_locks_unsafe_for_binlog, SHOW_MY_BOOL}, 00837 {"innodb_log_arch_dir", (char*) &innobase_log_arch_dir, SHOW_CHAR_PTR}, 00838 {"innodb_log_archive", (char*) &innobase_log_archive, SHOW_MY_BOOL}, 00839 {"innodb_log_buffer_size", (char*) &innobase_log_buffer_size, SHOW_LONG }, 00840 {"innodb_log_file_size", (char*) &innobase_log_file_size, SHOW_LONGLONG}, 00841 {"innodb_log_files_in_group", (char*) &innobase_log_files_in_group, SHOW_LONG}, 00842 {"innodb_log_group_home_dir", (char*) &innobase_log_group_home_dir, SHOW_CHAR_PTR}, 00843 {sys_innodb_max_dirty_pages_pct.name, (char*) &sys_innodb_max_dirty_pages_pct, SHOW_SYS}, 00844 {sys_innodb_max_purge_lag.name, (char*) &sys_innodb_max_purge_lag, SHOW_SYS}, 00845 {"innodb_mirrored_log_groups", (char*) &innobase_mirrored_log_groups, SHOW_LONG}, 00846 {"innodb_open_files", (char*) &innobase_open_files, SHOW_LONG }, 00847 {sys_innodb_support_xa.name, (char*) &sys_innodb_support_xa, SHOW_SYS}, 00848 {sys_innodb_sync_spin_loops.name, (char*) &sys_innodb_sync_spin_loops, SHOW_SYS}, 00849 {sys_innodb_table_locks.name, (char*) &sys_innodb_table_locks, SHOW_SYS}, 00850 {sys_innodb_thread_concurrency.name, (char*) &sys_innodb_thread_concurrency, SHOW_SYS}, 00851 {sys_innodb_thread_sleep_delay.name, (char*) &sys_innodb_thread_sleep_delay, SHOW_SYS}, 00852 {sys_innodb_flush_log_at_trx_commit.name, (char*) &sys_innodb_flush_log_at_trx_commit, SHOW_SYS}, 00853 #endif 00854 {sys_interactive_timeout.name,(char*) &sys_interactive_timeout, SHOW_SYS}, 00855 {sys_join_buffer_size.name, (char*) &sys_join_buffer_size, SHOW_SYS}, 00856 {sys_key_buffer_size.name, (char*) &sys_key_buffer_size, SHOW_SYS}, 00857 {sys_key_cache_age_threshold.name, (char*) &sys_key_cache_age_threshold, 00858 SHOW_SYS}, 00859 {sys_key_cache_block_size.name, (char*) &sys_key_cache_block_size, 00860 SHOW_SYS}, 00861 {sys_key_cache_division_limit.name, (char*) &sys_key_cache_division_limit, 00862 SHOW_SYS}, 00863 {"language", language, SHOW_CHAR}, 00864 {"large_files_support", (char*) &opt_large_files, SHOW_BOOL}, 00865 {"large_page_size", (char*) &opt_large_page_size, SHOW_INT}, 00866 {"large_pages", (char*) &opt_large_pages, SHOW_MY_BOOL}, 00867 {sys_lc_time_names.name, (char*) &sys_lc_time_names, SHOW_SYS}, 00868 {sys_license.name, (char*) &sys_license, SHOW_SYS}, 00869 {sys_local_infile.name, (char*) &sys_local_infile, SHOW_SYS}, 00870 #ifdef HAVE_MLOCKALL 00871 {"locked_in_memory", (char*) &locked_in_memory, SHOW_BOOL}, 00872 #endif 00873 {"log", (char*) &opt_log, SHOW_BOOL}, 00874 {"log_bin", (char*) &opt_bin_log, SHOW_BOOL}, 00875 {sys_trust_function_creators.name,(char*) &sys_trust_function_creators, SHOW_SYS}, 00876 {"log_error", (char*) log_error_file, SHOW_CHAR}, 00877 {sys_var_log_output_state.name, (char*) &sys_var_log_output_state, SHOW_SYS}, 00878 {sys_log_queries_not_using_indexes.name, 00879 (char*) &sys_log_queries_not_using_indexes, SHOW_SYS}, 00880 #ifdef HAVE_REPLICATION 00881 {"log_slave_updates", (char*) &opt_log_slave_updates, SHOW_MY_BOOL}, 00882 #endif 00883 {"log_slow_queries", (char*) &opt_slow_log, SHOW_BOOL}, 00884 {sys_log_warnings.name, (char*) &sys_log_warnings, SHOW_SYS}, 00885 {sys_long_query_time.name, (char*) &sys_long_query_time, SHOW_SYS}, 00886 {sys_low_priority_updates.name, (char*) &sys_low_priority_updates, SHOW_SYS}, 00887 {"lower_case_file_system", (char*) &lower_case_file_system, SHOW_MY_BOOL}, 00888 {"lower_case_table_names", (char*) &lower_case_table_names, SHOW_INT}, 00889 {sys_max_allowed_packet.name,(char*) &sys_max_allowed_packet, SHOW_SYS}, 00890 {sys_max_binlog_cache_size.name,(char*) &sys_max_binlog_cache_size, SHOW_SYS}, 00891 {sys_max_binlog_size.name, (char*) &sys_max_binlog_size, SHOW_SYS}, 00892 {sys_max_connect_errors.name, (char*) &sys_max_connect_errors, SHOW_SYS}, 00893 {sys_max_connections.name, (char*) &sys_max_connections, SHOW_SYS}, 00894 {sys_max_delayed_threads.name,(char*) &sys_max_delayed_threads, SHOW_SYS}, 00895 {sys_max_error_count.name, (char*) &sys_max_error_count, SHOW_SYS}, 00896 {sys_max_heap_table_size.name,(char*) &sys_max_heap_table_size, SHOW_SYS}, 00897 {sys_max_insert_delayed_threads.name, 00898 (char*) &sys_max_insert_delayed_threads, SHOW_SYS}, 00899 {sys_max_join_size.name, (char*) &sys_max_join_size, SHOW_SYS}, 00900 {sys_max_length_for_sort_data.name, (char*) &sys_max_length_for_sort_data, 00901 SHOW_SYS}, 00902 {sys_max_prepared_stmt_count.name, (char*) &sys_max_prepared_stmt_count, 00903 SHOW_SYS}, 00904 {sys_max_relay_log_size.name, (char*) &sys_max_relay_log_size, SHOW_SYS}, 00905 {sys_max_seeks_for_key.name, (char*) &sys_max_seeks_for_key, SHOW_SYS}, 00906 {sys_max_sort_length.name, (char*) &sys_max_sort_length, SHOW_SYS}, 00907 {sys_max_sp_recursion_depth.name, 00908 (char*) &sys_max_sp_recursion_depth, SHOW_SYS}, 00909 {sys_max_tmp_tables.name, (char*) &sys_max_tmp_tables, SHOW_SYS}, 00910 {sys_max_user_connections.name,(char*) &sys_max_user_connections, SHOW_SYS}, 00911 {sys_max_write_lock_count.name, (char*) &sys_max_write_lock_count,SHOW_SYS}, 00912 {sys_multi_range_count.name, (char*) &sys_multi_range_count, SHOW_SYS}, 00913 {sys_myisam_data_pointer_size.name, (char*) &sys_myisam_data_pointer_size, SHOW_SYS}, 00914 {sys_myisam_max_sort_file_size.name, (char*) &sys_myisam_max_sort_file_size, 00915 SHOW_SYS}, 00916 {"myisam_recover_options", (char*) &myisam_recover_options_str, SHOW_CHAR_PTR}, 00917 {sys_myisam_repair_threads.name, (char*) &sys_myisam_repair_threads, 00918 SHOW_SYS}, 00919 {sys_myisam_sort_buffer_size.name, (char*) &sys_myisam_sort_buffer_size, SHOW_SYS}, 00920 00921 {sys_myisam_stats_method.name, (char*) &sys_myisam_stats_method, SHOW_SYS}, 00922 {sys_myisam_use_mmap.name, (char*) &sys_myisam_use_mmap, SHOW_SYS}, 00923 00924 #ifdef __NT__ 00925 {"named_pipe", (char*) &opt_enable_named_pipe, SHOW_MY_BOOL}, 00926 #endif 00927 {sys_ndb_autoincrement_prefetch_sz.name, 00928 (char*) &sys_ndb_autoincrement_prefetch_sz, SHOW_SYS}, 00929 {sys_ndb_cache_check_time.name,(char*) &sys_ndb_cache_check_time, SHOW_SYS}, 00930 {sys_ndb_extra_logging.name,(char*) &sys_ndb_extra_logging, SHOW_SYS}, 00931 {sys_ndb_force_send.name, (char*) &sys_ndb_force_send, SHOW_SYS}, 00932 {sys_ndb_index_stat_cache_entries.name, (char*) &sys_ndb_index_stat_cache_entries, SHOW_SYS}, 00933 {sys_ndb_index_stat_enable.name, (char*) &sys_ndb_index_stat_enable, SHOW_SYS}, 00934 {sys_ndb_index_stat_update_freq.name, (char*) &sys_ndb_index_stat_update_freq, SHOW_SYS}, 00935 #ifdef HAVE_NDB_BINLOG 00936 {sys_ndb_report_thresh_binlog_epoch_slip.name, 00937 (char*) &sys_ndb_report_thresh_binlog_epoch_slip, SHOW_SYS}, 00938 {sys_ndb_report_thresh_binlog_mem_usage.name, 00939 (char*) &sys_ndb_report_thresh_binlog_mem_usage, SHOW_SYS}, 00940 #endif 00941 {sys_ndb_use_copying_alter_table.name, 00942 (char*) &sys_ndb_use_copying_alter_table, SHOW_SYS}, 00943 {sys_ndb_use_exact_count.name,(char*) &sys_ndb_use_exact_count, SHOW_SYS}, 00944 {sys_ndb_use_transactions.name,(char*) &sys_ndb_use_transactions, SHOW_SYS}, 00945 {sys_net_buffer_length.name,(char*) &sys_net_buffer_length, SHOW_SYS}, 00946 {sys_net_read_timeout.name, (char*) &sys_net_read_timeout, SHOW_SYS}, 00947 {sys_net_retry_count.name, (char*) &sys_net_retry_count, SHOW_SYS}, 00948 {sys_net_write_timeout.name,(char*) &sys_net_write_timeout, SHOW_SYS}, 00949 {sys_new_mode.name, (char*) &sys_new_mode, SHOW_SYS}, 00950 {sys_old_alter_table.name, (char*) &sys_old_alter_table, SHOW_SYS}, 00951 {sys_old_passwords.name, (char*) &sys_old_passwords, SHOW_SYS}, 00952 {"open_files_limit", (char*) &open_files_limit, SHOW_LONG}, 00953 {sys_optimizer_prune_level.name, (char*) &sys_optimizer_prune_level, 00954 SHOW_SYS}, 00955 {sys_optimizer_search_depth.name,(char*) &sys_optimizer_search_depth, 00956 SHOW_SYS}, 00957 {"pid_file", (char*) pidfile_name, SHOW_CHAR}, 00958 {"plugin_dir", (char*) opt_plugin_dir, SHOW_CHAR}, 00959 {"port", (char*) &mysqld_port, SHOW_INT}, 00960 {sys_preload_buff_size.name, (char*) &sys_preload_buff_size, SHOW_SYS}, 00961 {sys_prepared_stmt_count.name, (char*) &sys_prepared_stmt_count, SHOW_SYS}, 00962 {"protocol_version", (char*) &protocol_version, SHOW_INT}, 00963 {sys_query_alloc_block_size.name, (char*) &sys_query_alloc_block_size, 00964 SHOW_SYS}, 00965 #ifdef HAVE_QUERY_CACHE 00966 {sys_query_cache_limit.name,(char*) &sys_query_cache_limit, SHOW_SYS}, 00967 {sys_query_cache_min_res_unit.name, (char*) &sys_query_cache_min_res_unit, 00968 SHOW_SYS}, 00969 {sys_query_cache_size.name, (char*) &sys_query_cache_size, SHOW_SYS}, 00970 {sys_query_cache_type.name, (char*) &sys_query_cache_type, SHOW_SYS}, 00971 {sys_query_cache_wlock_invalidate.name, 00972 (char *) &sys_query_cache_wlock_invalidate, SHOW_SYS}, 00973 #endif /* HAVE_QUERY_CACHE */ 00974 {sys_query_prealloc_size.name, (char*) &sys_query_prealloc_size, SHOW_SYS}, 00975 {sys_range_alloc_block_size.name, (char*) &sys_range_alloc_block_size, 00976 SHOW_SYS}, 00977 {sys_read_buff_size.name, (char*) &sys_read_buff_size, SHOW_SYS}, 00978 {sys_readonly.name, (char*) &sys_readonly, SHOW_SYS}, 00979 {sys_read_rnd_buff_size.name,(char*) &sys_read_rnd_buff_size, SHOW_SYS}, 00980 #ifdef HAVE_REPLICATION 00981 {sys_relay_log_purge.name, (char*) &sys_relay_log_purge, SHOW_SYS}, 00982 {"relay_log_space_limit", (char*) &relay_log_space_limit, SHOW_LONGLONG}, 00983 #endif 00984 {sys_rpl_recovery_rank.name,(char*) &sys_rpl_recovery_rank, SHOW_SYS}, 00985 {"secure_auth", (char*) &sys_secure_auth, SHOW_SYS}, 00986 #ifdef HAVE_SMEM 00987 {"shared_memory", (char*) &opt_enable_shared_memory, SHOW_MY_BOOL}, 00988 {"shared_memory_base_name", (char*) &shared_memory_base_name, SHOW_CHAR_PTR}, 00989 #endif 00990 {sys_server_id.name, (char*) &sys_server_id, SHOW_SYS}, 00991 {"skip_external_locking", (char*) &my_disable_locking, SHOW_MY_BOOL}, 00992 {"skip_networking", (char*) &opt_disable_networking, SHOW_BOOL}, 00993 {"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL}, 00994 #ifdef HAVE_REPLICATION 00995 {sys_slave_compressed_protocol.name, 00996 (char*) &sys_slave_compressed_protocol, SHOW_SYS}, 00997 {"slave_load_tmpdir", (char*) &slave_load_tmpdir, SHOW_CHAR_PTR}, 00998 {sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout, SHOW_SYS}, 00999 {"slave_skip_errors", (char*) &show_slave_skip_errors, SHOW_FUNC}, 01000 {sys_slave_trans_retries.name,(char*) &sys_slave_trans_retries, SHOW_SYS}, 01001 #endif 01002 {sys_slow_launch_time.name, (char*) &sys_slow_launch_time, SHOW_SYS}, 01003 {sys_var_slow_query_log.name, (char*) &opt_slow_log, SHOW_MY_BOOL}, 01004 {sys_var_slow_log_path.name, (char*) &sys_var_slow_log_path, SHOW_SYS}, 01005 #ifdef HAVE_SYS_UN_H 01006 {"socket", (char*) &mysqld_unix_port, SHOW_CHAR_PTR}, 01007 #endif 01008 {sys_sort_buffer.name, (char*) &sys_sort_buffer, SHOW_SYS}, 01009 {sys_big_selects.name, (char*) &sys_big_selects, SHOW_SYS}, 01010 {sys_sql_mode.name, (char*) &sys_sql_mode, SHOW_SYS}, 01011 {"sql_notes", (char*) &sys_sql_notes, SHOW_SYS}, 01012 {"sql_warnings", (char*) &sys_sql_warnings, SHOW_SYS}, 01013 {sys_ssl_ca.name, (char*) &sys_ssl_ca, SHOW_SYS}, 01014 {sys_ssl_capath.name, (char*) &sys_ssl_capath, SHOW_SYS}, 01015 {sys_ssl_cert.name, (char*) &sys_ssl_cert, SHOW_SYS}, 01016 {sys_ssl_cipher.name, (char*) &sys_ssl_cipher, SHOW_SYS}, 01017 {sys_ssl_key.name, (char*) &sys_ssl_key, SHOW_SYS}, 01018 {sys_storage_engine.name, (char*) &sys_storage_engine, SHOW_SYS}, 01019 #ifdef HAVE_REPLICATION 01020 {sys_sync_binlog_period.name,(char*) &sys_sync_binlog_period, SHOW_SYS}, 01021 #endif 01022 {sys_sync_frm.name, (char*) &sys_sync_frm, SHOW_SYS}, 01023 #ifdef HAVE_TZNAME 01024 {"system_time_zone", system_time_zone, SHOW_CHAR}, 01025 #endif 01026 {"table_definition_cache", (char*) &table_def_size, SHOW_LONG}, 01027 {"table_lock_wait_timeout", (char*) &table_lock_wait_timeout, SHOW_LONG }, 01028 {"table_open_cache", (char*) &table_cache_size, SHOW_LONG}, 01029 {sys_table_type.name, (char*) &sys_table_type, SHOW_SYS}, 01030 {sys_thread_cache_size.name,(char*) &sys_thread_cache_size, SHOW_SYS}, 01031 #ifdef HAVE_THR_SETCONCURRENCY 01032 {"thread_concurrency", (char*) &concurrency, SHOW_LONG}, 01033 #endif 01034 {"thread_stack", (char*) &thread_stack, SHOW_LONG}, 01035 {sys_time_format.name, (char*) &sys_time_format, SHOW_SYS}, 01036 {"time_zone", (char*) &sys_time_zone, SHOW_SYS}, 01037 {sys_timed_mutexes.name, (char*) &sys_timed_mutexes, SHOW_SYS}, 01038 {sys_tmp_table_size.name, (char*) &sys_tmp_table_size, SHOW_SYS}, 01039 {sys_tmpdir.name, (char*) &sys_tmpdir, SHOW_SYS}, 01040 {sys_trans_alloc_block_size.name, (char*) &sys_trans_alloc_block_size, 01041 SHOW_SYS}, 01042 {sys_trans_prealloc_size.name, (char*) &sys_trans_prealloc_size, SHOW_SYS}, 01043 {sys_tx_isolation.name, (char*) &sys_tx_isolation, SHOW_SYS}, 01044 {sys_updatable_views_with_limit.name, 01045 (char*) &sys_updatable_views_with_limit,SHOW_SYS}, 01046 {sys_version.name, (char*) &sys_version, SHOW_SYS}, 01047 {sys_version_comment.name, (char*) &sys_version_comment, SHOW_SYS}, 01048 {sys_version_compile_machine.name, (char*) &sys_version_compile_machine, 01049 SHOW_SYS}, 01050 {sys_version_compile_os.name, (char*) &sys_version_compile_os, SHOW_SYS}, 01051 {sys_net_wait_timeout.name, (char*) &sys_net_wait_timeout, SHOW_SYS}, 01052 {NullS, NullS, SHOW_LONG} 01053 }; 01054 01055 01056 bool sys_var::check(THD *thd, set_var *var) 01057 { 01058 var->save_result.ulonglong_value= var->value->val_int(); 01059 return 0; 01060 } 01061 01062 bool sys_var_str::check(THD *thd, set_var *var) 01063 { 01064 int res; 01065 if (!check_func) 01066 return 0; 01067 01068 if ((res=(*check_func)(thd, var)) < 0) 01069 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), 01070 name, var->value->str_value.ptr()); 01071 return res; 01072 } 01073 01074 /* 01075 Functions to check and update variables 01076 */ 01077 01078 01079 /* 01080 Update variables 'init_connect, init_slave'. 01081 01082 In case of 'DEFAULT' value 01083 (for example: 'set GLOBAL init_connect=DEFAULT') 01084 'var' parameter is NULL pointer. 01085 */ 01086 01087 bool update_sys_var_str(sys_var_str *var_str, rw_lock_t *var_mutex, 01088 set_var *var) 01089 { 01090 char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0); 01091 uint new_length= (var ? var->value->str_value.length() : 0); 01092 if (!old_value) 01093 old_value= (char*) ""; 01094 if (!(res= my_strndup(old_value, new_length, MYF(0)))) 01095 return 1; 01096 /* 01097 Replace the old value in such a way that the any thread using 01098 the value will work. 01099 */ 01100 rw_wrlock(var_mutex); 01101 old_value= var_str->value; 01102 var_str->value= res; 01103 var_str->value_length= new_length; 01104 rw_unlock(var_mutex); 01105 my_free(old_value, MYF(MY_ALLOW_ZERO_PTR)); 01106 return 0; 01107 } 01108 01109 01110 static bool sys_update_init_connect(THD *thd, set_var *var) 01111 { 01112 return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var); 01113 } 01114 01115 01116 static void sys_default_init_connect(THD* thd, enum_var_type type) 01117 { 01118 update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0); 01119 } 01120 01121 01122 static bool sys_update_init_slave(THD *thd, set_var *var) 01123 { 01124 return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var); 01125 } 01126 01127 01128 static void sys_default_init_slave(THD* thd, enum_var_type type) 01129 { 01130 update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0); 01131 } 01132 01133 static int sys_check_ftb_syntax(THD *thd, set_var *var) 01134 { 01135 if (thd->security_ctx->master_access & SUPER_ACL) 01136 return (ft_boolean_check_syntax_string((byte*) 01137 var->value->str_value.c_ptr()) ? 01138 -1 : 0); 01139 else 01140 { 01141 my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER"); 01142 return 1; 01143 } 01144 } 01145 01146 static bool sys_update_ftb_syntax(THD *thd, set_var * var) 01147 { 01148 strmake(ft_boolean_syntax, var->value->str_value.c_ptr(), 01149 sizeof(ft_boolean_syntax)-1); 01150 return 0; 01151 } 01152 01153 static void sys_default_ftb_syntax(THD *thd, enum_var_type type) 01154 { 01155 strmake(ft_boolean_syntax, def_ft_boolean_syntax, 01156 sizeof(ft_boolean_syntax)-1); 01157 } 01158 01159 01160 /* 01161 If one sets the LOW_PRIORIY UPDATES flag, we also must change the 01162 used lock type 01163 */ 01164 01165 static void fix_low_priority_updates(THD *thd, enum_var_type type) 01166 { 01167 if (type != OPT_GLOBAL) 01168 thd->update_lock_default= (thd->variables.low_priority_updates ? 01169 TL_WRITE_LOW_PRIORITY : TL_WRITE); 01170 } 01171 01172 01173 static void 01174 fix_myisam_max_sort_file_size(THD *thd, enum_var_type type) 01175 { 01176 myisam_max_temp_length= 01177 (my_off_t) global_system_variables.myisam_max_sort_file_size; 01178 } 01179 01180 /* 01181 Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR 01182 */ 01183 01184 static void fix_max_join_size(THD *thd, enum_var_type type) 01185 { 01186 if (type != OPT_GLOBAL) 01187 { 01188 if (thd->variables.max_join_size == HA_POS_ERROR) 01189 thd->options|= OPTION_BIG_SELECTS; 01190 else 01191 thd->options&= ~OPTION_BIG_SELECTS; 01192 } 01193 } 01194 01195 01196 /* 01197 Can't change the 'next' tx_isolation while we are already in 01198 a transaction 01199 */ 01200 static int check_tx_isolation(THD *thd, set_var *var) 01201 { 01202 if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS)) 01203 { 01204 my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0)); 01205 return 1; 01206 } 01207 return 0; 01208 } 01209 01210 /* 01211 If one doesn't use the SESSION modifier, the isolation level 01212 is only active for the next command 01213 */ 01214 static void fix_tx_isolation(THD *thd, enum_var_type type) 01215 { 01216 if (type == OPT_SESSION) 01217 thd->session_tx_isolation= ((enum_tx_isolation) 01218 thd->variables.tx_isolation); 01219 } 01220 01221 static void fix_completion_type(THD *thd __attribute__(unused), 01222 enum_var_type type __attribute__(unused)) {} 01223 01224 static int check_completion_type(THD *thd, set_var *var) 01225 { 01226 longlong val= var->value->val_int(); 01227 if (val < 0 || val > 2) 01228 { 01229 char buf[64]; 01230 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf)); 01231 return 1; 01232 } 01233 return 0; 01234 } 01235 01236 01237 /* 01238 If we are changing the thread variable, we have to copy it to NET too 01239 */ 01240 01241 #ifdef HAVE_REPLICATION 01242 static void fix_net_read_timeout(THD *thd, enum_var_type type) 01243 { 01244 if (type != OPT_GLOBAL) 01245 thd->net.read_timeout=thd->variables.net_read_timeout; 01246 } 01247 01248 01249 static void fix_net_write_timeout(THD *thd, enum_var_type type) 01250 { 01251 if (type != OPT_GLOBAL) 01252 thd->net.write_timeout=thd->variables.net_write_timeout; 01253 } 01254 01255 static void fix_net_retry_count(THD *thd, enum_var_type type) 01256 { 01257 if (type != OPT_GLOBAL) 01258 thd->net.retry_count=thd->variables.net_retry_count; 01259 } 01260 #else /* HAVE_REPLICATION */ 01261 static void fix_net_read_timeout(THD *thd __attribute__(unused), 01262 enum_var_type type __attribute__(unused)) 01263 {} 01264 static void fix_net_write_timeout(THD *thd __attribute__(unused), 01265 enum_var_type type __attribute__(unused)) 01266 {} 01267 static void fix_net_retry_count(THD *thd __attribute__(unused), 01268 enum_var_type type __attribute__(unused)) 01269 {} 01270 #endif /* HAVE_REPLICATION */ 01271 01272 01273 static void fix_query_cache_size(THD *thd, enum_var_type type) 01274 { 01275 #ifdef HAVE_QUERY_CACHE 01276 ulong requested= query_cache_size; 01277 query_cache.resize(query_cache_size); 01278 if (requested != query_cache_size) 01279 push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, 01280 ER_WARN_QC_RESIZE, ER(ER_WARN_QC_RESIZE), 01281 requested, query_cache_size); 01282 #endif 01283 } 01284 01285 01286 #ifdef HAVE_QUERY_CACHE 01287 static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type) 01288 { 01289 query_cache_min_res_unit= 01290 query_cache.set_min_res_unit(query_cache_min_res_unit); 01291 } 01292 #endif 01293 01294 01295 extern void fix_delay_key_write(THD *thd, enum_var_type type) 01296 { 01297 switch ((enum_delay_key_write) delay_key_write_options) { 01298 case DELAY_KEY_WRITE_NONE: 01299 myisam_delay_key_write=0; 01300 break; 01301 case DELAY_KEY_WRITE_ON: 01302 myisam_delay_key_write=1; 01303 break; 01304 case DELAY_KEY_WRITE_ALL: 01305 myisam_delay_key_write=1; 01306 ha_open_options|= HA_OPEN_DELAY_KEY_WRITE; 01307 break; 01308 } 01309 } 01310 01311 01312 bool sys_var_thd_binlog_format::is_readonly() const 01313 { 01314 /* 01315 Under certain circumstances, the variable is read-only (unchangeable): 01316 */ 01317 THD *thd= current_thd; 01318 /* 01319 If RBR and open temporary tables, their CREATE TABLE may not be in the 01320 binlog, so we can't toggle to SBR in this connection. 01321 The test below will also prevent SET GLOBAL, well it was not easy to test 01322 if global or not here. 01323 And this test will also prevent switching from RBR to RBR (a no-op which 01324 should not happen too often). 01325 01326 If we don't have row-based replication compiled in, the variable 01327 is always read-only. 01328 */ 01329 #ifndef HAVE_ROW_BASED_REPLICATION 01330 my_error(ER_RBR_NOT_AVAILABLE, MYF(0)); 01331 return 1; 01332 #else 01333 if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) && 01334 thd->temporary_tables) 01335 { 01336 my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0)); 01337 return 1; 01338 } 01339 /* 01340 if in a stored function/trigger, it's too late to change mode 01341 */ 01342 if (thd->in_sub_stmt) 01343 { 01344 my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0)); 01345 return 1; 01346 } 01347 #ifdef HAVE_NDB_BINLOG 01348 /* 01349 Cluster does not support changing the binlog format on the fly yet. 01350 */ 01351 if (opt_bin_log && (have_ndbcluster == SHOW_OPTION_YES)) 01352 { 01353 my_error(ER_NDB_CANT_SWITCH_BINLOG_FORMAT, MYF(0)); 01354 return 1; 01355 } 01356 #endif /* HAVE_NDB_BINLOG */ 01357 #endif /* HAVE_ROW_BASED_REPLICATION */ 01358 return sys_var_thd_enum::is_readonly(); 01359 } 01360 01361 01362 void fix_binlog_format_after_update(THD *thd, enum_var_type type) 01363 { 01364 #ifdef HAVE_ROW_BASED_REPLICATION 01365 thd->reset_current_stmt_binlog_row_based(); 01366 #endif /*HAVE_ROW_BASED_REPLICATION*/ 01367 } 01368 01369 01370 static void fix_max_binlog_size(THD *thd, enum_var_type type) 01371 { 01372 DBUG_ENTER("fix_max_binlog_size"); 01373 DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu", 01374 max_binlog_size, max_relay_log_size)); 01375 mysql_bin_log.set_max_size(max_binlog_size); 01376 #ifdef HAVE_REPLICATION 01377 if (!max_relay_log_size) 01378 active_mi->rli.relay_log.set_max_size(max_binlog_size); 01379 #endif 01380 DBUG_VOID_RETURN; 01381 } 01382 01383 static void fix_max_relay_log_size(THD *thd, enum_var_type type) 01384 { 01385 DBUG_ENTER("fix_max_relay_log_size"); 01386 DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu", 01387 max_binlog_size, max_relay_log_size)); 01388 #ifdef HAVE_REPLICATION 01389 active_mi->rli.relay_log.set_max_size(max_relay_log_size ? 01390 max_relay_log_size: max_binlog_size); 01391 #endif 01392 DBUG_VOID_RETURN; 01393 } 01394 01395 01396 static int check_max_delayed_threads(THD *thd, set_var *var) 01397 { 01398 longlong val= var->value->val_int(); 01399 if (var->type != OPT_GLOBAL && val != 0 && 01400 val != (longlong) global_system_variables.max_insert_delayed_threads) 01401 { 01402 char buf[64]; 01403 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf)); 01404 return 1; 01405 } 01406 return 0; 01407 } 01408 01409 static void fix_max_connections(THD *thd, enum_var_type type) 01410 { 01411 #ifndef EMBEDDED_LIBRARY 01412 resize_thr_alarm(max_connections + 01413 global_system_variables.max_insert_delayed_threads + 10); 01414 #endif 01415 } 01416 01417 01418 static void fix_thd_mem_root(THD *thd, enum_var_type type) 01419 { 01420 if (type != OPT_GLOBAL) 01421 reset_root_defaults(thd->mem_root, 01422 thd->variables.query_alloc_block_size, 01423 thd->variables.query_prealloc_size); 01424 } 01425 01426 01427 static void fix_trans_mem_root(THD *thd, enum_var_type type) 01428 { 01429 #ifdef USING_TRANSACTIONS 01430 if (type != OPT_GLOBAL) 01431 reset_root_defaults(&thd->transaction.mem_root, 01432 thd->variables.trans_alloc_block_size, 01433 thd->variables.trans_prealloc_size); 01434 #endif 01435 } 01436 01437 01438 static void fix_server_id(THD *thd, enum_var_type type) 01439 { 01440 server_id_supplied = 1; 01441 } 01442 01443 01444 sys_var_long_ptr:: 01445 sys_var_long_ptr(const char *name_arg, ulong *value_ptr, 01446 sys_after_update_func after_update_arg) 01447 :sys_var_long_ptr_global(name_arg, value_ptr, 01448 &LOCK_global_system_variables, after_update_arg) 01449 {} 01450 01451 01452 bool sys_var_long_ptr_global::check(THD *thd, set_var *var) 01453 { 01454 longlong v= var->value->val_int(); 01455 var->save_result.ulonglong_value= v < 0 ? 0 : v; 01456 return 0; 01457 } 01458 01459 bool sys_var_long_ptr_global::update(THD *thd, set_var *var) 01460 { 01461 ulonglong tmp= var->save_result.ulonglong_value; 01462 pthread_mutex_lock(guard); 01463 if (option_limits) 01464 *value= (ulong) getopt_ull_limit_value(tmp, option_limits); 01465 else 01466 *value= (ulong) tmp; 01467 pthread_mutex_unlock(guard); 01468 return 0; 01469 } 01470 01471 01472 void sys_var_long_ptr_global::set_default(THD *thd, enum_var_type type) 01473 { 01474 pthread_mutex_lock(guard); 01475 *value= (ulong) option_limits->def_value; 01476 pthread_mutex_unlock(guard); 01477 } 01478 01479 01480 bool sys_var_ulonglong_ptr::update(THD *thd, set_var *var) 01481 { 01482 ulonglong tmp= var->save_result.ulonglong_value; 01483 pthread_mutex_lock(&LOCK_global_system_variables); 01484 if (option_limits) 01485 *value= (ulonglong) getopt_ull_limit_value(tmp, option_limits); 01486 else 01487 *value= (ulonglong) tmp; 01488 pthread_mutex_unlock(&LOCK_global_system_variables); 01489 return 0; 01490 } 01491 01492 01493 void sys_var_ulonglong_ptr::set_default(THD *thd, enum_var_type type) 01494 { 01495 pthread_mutex_lock(&LOCK_global_system_variables); 01496 *value= (ulonglong) option_limits->def_value; 01497 pthread_mutex_unlock(&LOCK_global_system_variables); 01498 } 01499 01500 01501 bool sys_var_bool_ptr::update(THD *thd, set_var *var) 01502 { 01503 *value= (my_bool) var->save_result.ulong_value; 01504 return 0; 01505 } 01506 01507 01508 void sys_var_bool_ptr::set_default(THD *thd, enum_var_type type) 01509 { 01510 *value= (my_bool) option_limits->def_value; 01511 } 01512 01513 01514 bool sys_var_enum::update(THD *thd, set_var *var) 01515 { 01516 *value= (uint) var->save_result.ulong_value; 01517 return 0; 01518 } 01519 01520 01521 byte *sys_var_enum::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) 01522 { 01523 return (byte*) enum_names->type_names[*value]; 01524 } 01525 01526 bool sys_var_thd_ulong::check(THD *thd, set_var *var) 01527 { 01528 return (sys_var_thd::check(thd, var) || 01529 (check_func && (*check_func)(thd, var))); 01530 } 01531 01532 bool sys_var_thd_ulong::update(THD *thd, set_var *var) 01533 { 01534 ulonglong tmp= var->save_result.ulonglong_value; 01535 01536 /* Don't use bigger value than given with --maximum-variable-name=.. */ 01537 if ((ulong) tmp > max_system_variables.*offset) 01538 tmp= max_system_variables.*offset; 01539 01540 #if SIZEOF_LONG == 4 01541 /* Avoid overflows on 32 bit systems */ 01542 if (tmp > (ulonglong) ~(ulong) 0) 01543 tmp= ((ulonglong) ~(ulong) 0); 01544 #endif 01545 01546 if (option_limits) 01547 tmp= (ulong) getopt_ull_limit_value(tmp, option_limits); 01548 if (var->type == OPT_GLOBAL) 01549 global_system_variables.*offset= (ulong) tmp; 01550 else 01551 thd->variables.*offset= (ulong) tmp; 01552 return 0; 01553 } 01554 01555 01556 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type) 01557 { 01558 if (type == OPT_GLOBAL) 01559 { 01560 /* We will not come here if option_limits is not set */ 01561 global_system_variables.*offset= (ulong) option_limits->def_value; 01562 } 01563 else 01564 thd->variables.*offset= global_system_variables.*offset; 01565 } 01566 01567 01568 byte *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type, 01569 LEX_STRING *base) 01570 { 01571 if (type == OPT_GLOBAL) 01572 return (byte*) &(global_system_variables.*offset); 01573 return (byte*) &(thd->variables.*offset); 01574 } 01575 01576 01577 bool sys_var_thd_ha_rows::update(THD *thd, set_var *var) 01578 { 01579 ulonglong tmp= var->save_result.ulonglong_value; 01580 01581 /* Don't use bigger value than given with --maximum-variable-name=.. */ 01582 if ((ha_rows) tmp > max_system_variables.*offset) 01583 tmp= max_system_variables.*offset; 01584 01585 if (option_limits) 01586 tmp= (ha_rows) getopt_ull_limit_value(tmp, option_limits); 01587 if (var->type == OPT_GLOBAL) 01588 { 01589 /* Lock is needed to make things safe on 32 bit systems */ 01590 pthread_mutex_lock(&LOCK_global_system_variables); 01591 global_system_variables.*offset= (ha_rows) tmp; 01592 pthread_mutex_unlock(&LOCK_global_system_variables); 01593 } 01594 else 01595 thd->variables.*offset= (ha_rows) tmp; 01596 return 0; 01597 } 01598 01599 01600 void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type) 01601 { 01602 if (type == OPT_GLOBAL) 01603 { 01604 /* We will not come here if option_limits is not set */ 01605 pthread_mutex_lock(&LOCK_global_system_variables); 01606 global_system_variables.*offset= (ha_rows) option_limits->def_value; 01607 pthread_mutex_unlock(&LOCK_global_system_variables); 01608 } 01609 else 01610 thd->variables.*offset= global_system_variables.*offset; 01611 } 01612 01613 01614 byte *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type, 01615 LEX_STRING *base) 01616 { 01617 if (type == OPT_GLOBAL) 01618 return (byte*) &(global_system_variables.*offset); 01619 return (byte*) &(thd->variables.*offset); 01620 } 01621 01622 bool sys_var_thd_ulonglong::update(THD *thd, set_var *var) 01623 { 01624 ulonglong tmp= var->save_result.ulonglong_value; 01625 01626 if (tmp > max_system_variables.*offset) 01627 tmp= max_system_variables.*offset; 01628 01629 if (option_limits) 01630 tmp= getopt_ull_limit_value(tmp, option_limits); 01631 if (var->type == OPT_GLOBAL) 01632 { 01633 /* Lock is needed to make things safe on 32 bit systems */ 01634 pthread_mutex_lock(&LOCK_global_system_variables); 01635 global_system_variables.*offset= (ulonglong) tmp; 01636 pthread_mutex_unlock(&LOCK_global_system_variables); 01637 } 01638 else 01639 thd->variables.*offset= (ulonglong) tmp; 01640 return 0; 01641 } 01642 01643 01644 void sys_var_thd_ulonglong::set_default(THD *thd, enum_var_type type) 01645 { 01646 if (type == OPT_GLOBAL) 01647 { 01648 pthread_mutex_lock(&LOCK_global_system_variables); 01649 global_system_variables.*offset= (ulonglong) option_limits->def_value; 01650 pthread_mutex_unlock(&LOCK_global_system_variables); 01651 } 01652 else 01653 thd->variables.*offset= global_system_variables.*offset; 01654 } 01655 01656 01657 byte *sys_var_thd_ulonglong::value_ptr(THD *thd, enum_var_type type, 01658 LEX_STRING *base) 01659 { 01660 if (type == OPT_GLOBAL) 01661 return (byte*) &(global_system_variables.*offset); 01662 return (byte*) &(thd->variables.*offset); 01663 } 01664 01665 01666 bool sys_var_thd_bool::update(THD *thd, set_var *var) 01667 { 01668 if (var->type == OPT_GLOBAL) 01669 global_system_variables.*offset= (my_bool) var->save_result.ulong_value; 01670 else 01671 thd->variables.*offset= (my_bool) var->save_result.ulong_value; 01672 return 0; 01673 } 01674 01675 01676 void sys_var_thd_bool::set_default(THD *thd, enum_var_type type) 01677 { 01678 if (type == OPT_GLOBAL) 01679 global_system_variables.*offset= (my_bool) option_limits->def_value; 01680 else 01681 thd->variables.*offset= global_system_variables.*offset; 01682 } 01683 01684 01685 byte *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type, 01686 LEX_STRING *base) 01687 { 01688 if (type == OPT_GLOBAL) 01689 return (byte*) &(global_system_variables.*offset); 01690 return (byte*) &(thd->variables.*offset); 01691 } 01692 01693 01694 bool sys_var::check_enum(THD *thd, set_var *var, TYPELIB *enum_names) 01695 { 01696 char buff[STRING_BUFFER_USUAL_SIZE]; 01697 const char *value; 01698 String str(buff, sizeof(buff), system_charset_info), *res; 01699 01700 if (var->value->result_type() == STRING_RESULT) 01701 { 01702 if (!(res=var->value->val_str(&str)) || 01703 ((long) (var->save_result.ulong_value= 01704 (ulong) find_type(enum_names, res->ptr(), 01705 res->length(),1)-1)) < 0) 01706 { 01707 value= res ? res->c_ptr() : "NULL"; 01708 goto err; 01709 } 01710 } 01711 else 01712 { 01713 ulonglong tmp=var->value->val_int(); 01714 if (tmp >= enum_names->count) 01715 { 01716 llstr(tmp,buff); 01717 value=buff; // Wrong value is here 01718 goto err; 01719 } 01720 var->save_result.ulong_value= (ulong) tmp; // Save for update 01721 } 01722 return 0; 01723 01724 err: 01725 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, value); 01726 return 1; 01727 } 01728 01729 01730 bool sys_var::check_set(THD *thd, set_var *var, TYPELIB *enum_names) 01731 { 01732 bool not_used; 01733 char buff[STRING_BUFFER_USUAL_SIZE], *error= 0; 01734 uint error_len= 0; 01735 String str(buff, sizeof(buff), system_charset_info), *res; 01736 01737 if (var->value->result_type() == STRING_RESULT) 01738 { 01739 if (!(res= var->value->val_str(&str))) 01740 { 01741 strmov(buff, "NULL"); 01742 goto err; 01743 } 01744 var->save_result.ulong_value= ((ulong) 01745 find_set(enum_names, res->c_ptr(), 01746 res->length(), 01747 NULL, 01748 &error, &error_len, 01749 ¬_used)); 01750 if (error_len) 01751 { 01752 strmake(buff, error, min(sizeof(buff), error_len)); 01753 goto err; 01754 } 01755 } 01756 else 01757 { 01758 ulonglong tmp= var->value->val_int(); 01759 /* 01760 For when the enum is made to contain 64 elements, as 1ULL<<64 is 01761 undefined, we guard with a "count<64" test. 01762 */ 01763 if (unlikely((tmp >= ((ULL(1)) << enum_names->count)) && 01764 (enum_names->count < 64))) 01765 { 01766 llstr(tmp, buff); 01767 goto err; 01768 } 01769 var->save_result.ulong_value= (ulong) tmp; // Save for update 01770 } 01771 return 0; 01772 01773 err: 01774 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buff); 01775 return 1; 01776 } 01777 01778 01779 /* 01780 Return an Item for a variable. Used with @@[global.]variable_name 01781 If type is not given, return local value if exists, else global 01782 */ 01783 01784 Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) 01785 { 01786 if (check_type(var_type)) 01787 { 01788 if (var_type != OPT_DEFAULT) 01789 { 01790 my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), 01791 name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); 01792 return 0; 01793 } 01794 /* As there was no local variable, return the global value */ 01795 var_type= OPT_GLOBAL; 01796 } 01797 switch (type()) { 01798 case SHOW_INT: 01799 { 01800 uint value; 01801 pthread_mutex_lock(&LOCK_global_system_variables); 01802 value= *(uint*) value_ptr(thd, var_type, base); 01803 pthread_mutex_unlock(&LOCK_global_system_variables); 01804 return new Item_uint((ulonglong) value); 01805 } 01806 case SHOW_LONG: 01807 { 01808 ulong value; 01809 pthread_mutex_lock(&LOCK_global_system_variables); 01810 value= *(ulong*) value_ptr(thd, var_type, base); 01811 pthread_mutex_unlock(&LOCK_global_system_variables); 01812 return new Item_uint((ulonglong) value); 01813 } 01814 case SHOW_LONGLONG: 01815 { 01816 longlong value; 01817 pthread_mutex_lock(&LOCK_global_system_variables); 01818 value= *(longlong*) value_ptr(thd, var_type, base); 01819 pthread_mutex_unlock(&LOCK_global_system_variables); 01820 return new Item_int(value); 01821 } 01822 case SHOW_HA_ROWS: 01823 { 01824 ha_rows value; 01825 pthread_mutex_lock(&LOCK_global_system_variables); 01826 value= *(ha_rows*) value_ptr(thd, var_type, base); 01827 pthread_mutex_unlock(&LOCK_global_system_variables); 01828 return new Item_int((longlong) value); 01829 } 01830 case SHOW_MY_BOOL: 01831 return new Item_int((int32) *(my_bool*) value_ptr(thd, var_type, base),1); 01832 case SHOW_CHAR: 01833 { 01834 Item *tmp; 01835 pthread_mutex_lock(&LOCK_global_system_variables); 01836 char *str= (char*) value_ptr(thd, var_type, base); 01837 if (str) 01838 tmp= new Item_string(str, strlen(str), 01839 system_charset_info, DERIVATION_SYSCONST); 01840 else 01841 { 01842 tmp= new Item_null(); 01843 tmp->collation.set(system_charset_info, DERIVATION_SYSCONST); 01844 } 01845 pthread_mutex_unlock(&LOCK_global_system_variables); 01846 return tmp; 01847 } 01848 default: 01849 my_error(ER_VAR_CANT_BE_READ, MYF(0), name); 01850 } 01851 return 0; 01852 } 01853 01854 01855 bool sys_var_thd_enum::update(THD *thd, set_var *var) 01856 { 01857 if (var->type == OPT_GLOBAL) 01858 global_system_variables.*offset= var->save_result.ulong_value; 01859 else 01860 thd->variables.*offset= var->save_result.ulong_value; 01861 return 0; 01862 } 01863 01864 01865 void sys_var_thd_enum::set_default(THD *thd, enum_var_type type) 01866 { 01867 if (type == OPT_GLOBAL) 01868 global_system_variables.*offset= (ulong) option_limits->def_value; 01869 else 01870 thd->variables.*offset= global_system_variables.*offset; 01871 } 01872 01873 01874 byte *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type, 01875 LEX_STRING *base) 01876 { 01877 ulong tmp= ((type == OPT_GLOBAL) ? 01878 global_system_variables.*offset : 01879 thd->variables.*offset); 01880 return (byte*) enum_names->type_names[tmp]; 01881 } 01882 01883 bool sys_var_thd_bit::check(THD *thd, set_var *var) 01884 { 01885 return (check_enum(thd, var, &bool_typelib) || 01886 (check_func && (*check_func)(thd, var))); 01887 } 01888 01889 bool sys_var_thd_bit::update(THD *thd, set_var *var) 01890 { 01891 int res= (*update_func)(thd, var); 01892 return res; 01893 } 01894 01895 01896 byte *sys_var_thd_bit::value_ptr(THD *thd, enum_var_type type, 01897 LEX_STRING *base) 01898 { 01899 /* 01900 If reverse is 0 (default) return 1 if bit is set. 01901 If reverse is 1, return 0 if bit is set 01902 */ 01903 thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ? 01904 !reverse : reverse); 01905 return (byte*) &thd->sys_var_tmp.my_bool_value; 01906 } 01907 01908 01909 /* Update a date_time format variable based on given value */ 01910 01911 void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type, 01912 DATE_TIME_FORMAT *new_value) 01913 { 01914 DATE_TIME_FORMAT *old; 01915 DBUG_ENTER("sys_var_date_time_format::update2"); 01916 DBUG_DUMP("positions",(char*) new_value->positions, 01917 sizeof(new_value->positions)); 01918 01919 if (type == OPT_GLOBAL) 01920 { 01921 pthread_mutex_lock(&LOCK_global_system_variables); 01922 old= (global_system_variables.*offset); 01923 (global_system_variables.*offset)= new_value; 01924 pthread_mutex_unlock(&LOCK_global_system_variables); 01925 } 01926 else 01927 { 01928 old= (thd->variables.*offset); 01929 (thd->variables.*offset)= new_value; 01930 } 01931 my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR)); 01932 DBUG_VOID_RETURN; 01933 } 01934 01935 01936 bool sys_var_thd_date_time_format::update(THD *thd, set_var *var) 01937 { 01938 DATE_TIME_FORMAT *new_value; 01939 /* We must make a copy of the last value to get it into normal memory */ 01940 new_value= date_time_format_copy((THD*) 0, 01941 var->save_result.date_time_format); 01942 if (!new_value) 01943 return 1; // Out of memory 01944 update2(thd, var->type, new_value); // Can't fail 01945 return 0; 01946 } 01947 01948 01949 bool sys_var_thd_date_time_format::check(THD *thd, set_var *var) 01950 { 01951 char buff[STRING_BUFFER_USUAL_SIZE]; 01952 String str(buff,sizeof(buff), system_charset_info), *res; 01953 DATE_TIME_FORMAT *format; 01954 01955 if (!(res=var->value->val_str(&str))) 01956 res= &my_empty_string; 01957 01958 if (!(format= date_time_format_make(date_time_type, 01959 res->ptr(), res->length()))) 01960 { 01961 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr()); 01962 return 1; 01963 } 01964 01965 /* 01966 We must copy result to thread space to not get a memory leak if 01967 update is aborted 01968 */ 01969 var->save_result.date_time_format= date_time_format_copy(thd, format); 01970 my_free((char*) format, MYF(0)); 01971 return var->save_result.date_time_format == 0; 01972 } 01973 01974 01975 void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type) 01976 { 01977 DATE_TIME_FORMAT *res= 0; 01978 01979 if (type == OPT_GLOBAL) 01980 { 01981 const char *format; 01982 if ((format= opt_date_time_formats[date_time_type])) 01983 res= date_time_format_make(date_time_type, format, strlen(format)); 01984 } 01985 else 01986 { 01987 /* Make copy with malloc */ 01988 res= date_time_format_copy((THD *) 0, global_system_variables.*offset); 01989 } 01990 01991 if (res) // Should always be true 01992 update2(thd, type, res); 01993 } 01994 01995 01996 byte *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type, 01997 LEX_STRING *base) 01998 { 01999 if (type == OPT_GLOBAL) 02000 { 02001 char *res; 02002 /* 02003 We do a copy here just to be sure things will work even if someone 02004 is modifying the original string while the copy is accessed 02005 (Can't happen now in SQL SHOW, but this is a good safety for the future) 02006 */ 02007 res= thd->strmake((global_system_variables.*offset)->format.str, 02008 (global_system_variables.*offset)->format.length); 02009 return (byte*) res; 02010 } 02011 return (byte*) (thd->variables.*offset)->format.str; 02012 } 02013 02014 02015 typedef struct old_names_map_st 02016 { 02017 const char *old_name; 02018 const char *new_name; 02019 } my_old_conv; 02020 02021 static my_old_conv old_conv[]= 02022 { 02023 { "cp1251_koi8" , "cp1251" }, 02024 { "cp1250_latin2" , "cp1250" }, 02025 { "kam_latin2" , "keybcs2" }, 02026 { "mac_latin2" , "MacRoman" }, 02027 { "macce_latin2" , "MacCE" }, 02028 { "pc2_latin2" , "pclatin2" }, 02029 { "vga_latin2" , "pclatin1" }, 02030 { "koi8_cp1251" , "koi8r" }, 02031 { "win1251ukr_koi8_ukr" , "win1251ukr" }, 02032 { "koi8_ukr_win1251ukr" , "koi8u" }, 02033 { NULL , NULL } 02034 }; 02035 02036 CHARSET_INFO *get_old_charset_by_name(const char *name) 02037 { 02038 my_old_conv *conv; 02039 02040 for (conv= old_conv; conv->old_name; conv++) 02041 { 02042 if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name)) 02043 return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0)); 02044 } 02045 return NULL; 02046 } 02047 02048 02049 bool sys_var_collation::check(THD *thd, set_var *var) 02050 { 02051 CHARSET_INFO *tmp; 02052 LINT_INIT(tmp); 02053 02054 if (var->value->result_type() == STRING_RESULT) 02055 { 02056 char buff[STRING_BUFFER_USUAL_SIZE]; 02057 String str(buff,sizeof(buff), system_charset_info), *res; 02058 if (!(res=var->value->val_str(&str))) 02059 { 02060 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); 02061 return 1; 02062 } 02063 if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0)))) 02064 { 02065 my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr()); 02066 return 1; 02067 } 02068 } 02069 else // INT_RESULT 02070 { 02071 if (!(tmp=get_charset((int) var->value->val_int(),MYF(0)))) 02072 { 02073 char buf[20]; 02074 int10_to_str((int) var->value->val_int(), buf, -10); 02075 my_error(ER_UNKNOWN_COLLATION, MYF(0), buf); 02076 return 1; 02077 } 02078 } 02079 var->save_result.charset= tmp; // Save for update 02080 return 0; 02081 } 02082 02083 02084 bool sys_var_character_set::check(THD *thd, set_var *var) 02085 { 02086 CHARSET_INFO *tmp; 02087 LINT_INIT(tmp); 02088 02089 if (var->value->result_type() == STRING_RESULT) 02090 { 02091 char buff[STRING_BUFFER_USUAL_SIZE]; 02092 String str(buff,sizeof(buff), system_charset_info), *res; 02093 if (!(res=var->value->val_str(&str))) 02094 { 02095 if (!nullable) 02096 { 02097 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL"); 02098 return 1; 02099 } 02100 tmp= NULL; 02101 } 02102 else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) && 02103 !(tmp=get_old_charset_by_name(res->c_ptr()))) 02104 { 02105 my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr()); 02106 return 1; 02107 } 02108 } 02109 else // INT_RESULT 02110 { 02111 if (!(tmp=get_charset((int) var->value->val_int(),MYF(0)))) 02112 { 02113 char buf[20]; 02114 int10_to_str((int) var->value->val_int(), buf, -10); 02115 my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf); 02116 return 1; 02117 } 02118 } 02119 var->save_result.charset= tmp; // Save for update 02120 return 0; 02121 } 02122 02123 02124 bool sys_var_character_set::update(THD *thd, set_var *var) 02125 { 02126 ci_ptr(thd,var->type)[0]= var->save_result.charset; 02127 thd->update_charset(); 02128 return 0; 02129 } 02130 02131 02132 byte *sys_var_character_set::value_ptr(THD *thd, enum_var_type type, 02133 LEX_STRING *base) 02134 { 02135 CHARSET_INFO *cs= ci_ptr(thd,type)[0]; 02136 return cs ? (byte*) cs->csname : (byte*) NULL; 02137 } 02138 02139 02140 CHARSET_INFO ** sys_var_character_set_connection::ci_ptr(THD *thd, 02141 enum_var_type type) 02142 { 02143 if (type == OPT_GLOBAL) 02144 return &global_system_variables.collation_connection; 02145 else 02146 return &thd->variables.collation_connection; 02147 } 02148 02149 02150 void sys_var_character_set_connection::set_default(THD *thd, 02151 enum_var_type type) 02152 { 02153 if (type == OPT_GLOBAL) 02154 global_system_variables.collation_connection= default_charset_info; 02155 else 02156 { 02157 thd->variables.collation_connection= global_system_variables.collation_connection; 02158 thd->update_charset(); 02159 } 02160 } 02161 02162 02163 CHARSET_INFO ** sys_var_character_set_client::ci_ptr(THD *thd, 02164 enum_var_type type) 02165 { 02166 if (type == OPT_GLOBAL) 02167 return &global_system_variables.character_set_client; 02168 else 02169 return &thd->variables.character_set_client; 02170 } 02171 02172 02173 void sys_var_character_set_client::set_default(THD *thd, enum_var_type type) 02174 { 02175 if (type == OPT_GLOBAL) 02176 global_system_variables.character_set_client= default_charset_info; 02177 else 02178 { 02179 thd->variables.character_set_client= (global_system_variables. 02180 character_set_client); 02181 thd->update_charset(); 02182 } 02183 } 02184 02185 02186 CHARSET_INFO ** 02187 sys_var_character_set_filesystem::ci_ptr(THD *thd, enum_var_type type) 02188 { 02189 if (type == OPT_GLOBAL) 02190 return &global_system_variables.character_set_filesystem; 02191 else 02192 return &thd->variables.character_set_filesystem; 02193 } 02194 02195 02196 extern CHARSET_INFO *character_set_filesystem; 02197 02198 void 02199 sys_var_character_set_filesystem::set_default(THD *thd, enum_var_type type) 02200 { 02201 if (type == OPT_GLOBAL) 02202 global_system_variables.character_set_filesystem= character_set_filesystem; 02203 else 02204 { 02205 thd->variables.character_set_filesystem= (global_system_variables. 02206 character_set_filesystem); 02207 thd->update_charset(); 02208 } 02209 } 02210 02211 02212 CHARSET_INFO ** 02213 sys_var_character_set_results::ci_ptr(THD *thd, enum_var_type type) 02214 { 02215 if (type == OPT_GLOBAL) 02216 return &global_system_variables.character_set_results; 02217 else 02218 return &thd->variables.character_set_results; 02219 } 02220 02221 02222 void sys_var_character_set_results::set_default(THD *thd, enum_var_type type) 02223 { 02224 if (type == OPT_GLOBAL) 02225 global_system_variables.character_set_results= default_charset_info; 02226 else 02227 { 02228 thd->variables.character_set_results= (global_system_variables. 02229 character_set_results); 02230 thd->update_charset(); 02231 } 02232 } 02233 02234 02235 CHARSET_INFO ** 02236 sys_var_character_set_server::ci_ptr(THD *thd, enum_var_type type) 02237 { 02238 if (type == OPT_GLOBAL) 02239 return &global_system_variables.collation_server; 02240 else 02241 return &thd->variables.collation_server; 02242 } 02243 02244 02245 void sys_var_character_set_server::set_default(THD *thd, enum_var_type type) 02246 { 02247 if (type == OPT_GLOBAL) 02248 global_system_variables.collation_server= default_charset_info; 02249 else 02250 { 02251 thd->variables.collation_server= global_system_variables.collation_server; 02252 thd->update_charset(); 02253 } 02254 } 02255 02256 CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd, 02257 enum_var_type type) 02258 { 02259 if (type == OPT_GLOBAL) 02260 return &global_system_variables.collation_database; 02261 else 02262 return &thd->variables.collation_database; 02263 } 02264 02265 02266 void sys_var_character_set_database::set_default(THD *thd, enum_var_type type) 02267 { 02268 if (type == OPT_GLOBAL) 02269 global_system_variables.collation_database= default_charset_info; 02270 else 02271 { 02272 thd->variables.collation_database= thd->db_charset; 02273 thd->update_charset(); 02274 } 02275 } 02276 02277 02278 bool sys_var_collation_connection::update(THD *thd, set_var *var) 02279 { 02280 if (var->type == OPT_GLOBAL) 02281 global_system_variables.collation_connection= var->save_result.charset; 02282 else 02283 { 02284 thd->variables.collation_connection= var->save_result.charset; 02285 thd->update_charset(); 02286 } 02287 return 0; 02288 } 02289 02290 02291 byte *sys_var_collation_connection::value_ptr(THD *thd, enum_var_type type, 02292 LEX_STRING *base) 02293 { 02294 CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? 02295 global_system_variables.collation_connection : 02296 thd->variables.collation_connection); 02297 return cs ? (byte*) cs->name : (byte*) "NULL"; 02298 } 02299 02300 02301 void sys_var_collation_connection::set_default(THD *thd, enum_var_type type) 02302 { 02303 if (type == OPT_GLOBAL) 02304 global_system_variables.collation_connection= default_charset_info; 02305 else 02306 { 02307 thd->variables.collation_connection= (global_system_variables. 02308 collation_connection); 02309 thd->update_charset(); 02310 } 02311 } 02312 02313 bool sys_var_collation_database::update(THD *thd, set_var *var) 02314 { 02315 if (var->type == OPT_GLOBAL) 02316 global_system_variables.collation_database= var->save_result.charset; 02317 else 02318 { 02319 thd->variables.collation_database= var->save_result.charset; 02320 thd->update_charset(); 02321 } 02322 return 0; 02323 } 02324 02325 02326 byte *sys_var_collation_database::value_ptr(THD *thd, enum_var_type type, 02327 LEX_STRING *base) 02328 { 02329 CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? 02330 global_system_variables.collation_database : 02331 thd->variables.collation_database); 02332 return cs ? (byte*) cs->name : (byte*) "NULL"; 02333 } 02334 02335 02336 void sys_var_collation_database::set_default(THD *thd, enum_var_type type) 02337 { 02338 if (type == OPT_GLOBAL) 02339 global_system_variables.collation_database= default_charset_info; 02340 else 02341 { 02342 thd->variables.collation_database= (global_system_variables. 02343 collation_database); 02344 thd->update_charset(); 02345 } 02346 } 02347 02348 02349 bool sys_var_collation_server::update(THD *thd, set_var *var) 02350 { 02351 if (var->type == OPT_GLOBAL) 02352 global_system_variables.collation_server= var->save_result.charset; 02353 else 02354 { 02355 thd->variables.collation_server= var->save_result.charset; 02356 thd->update_charset(); 02357 } 02358 return 0; 02359 } 02360 02361 02362 byte *sys_var_collation_server::value_ptr(THD *thd, enum_var_type type, 02363 LEX_STRING *base) 02364 { 02365 CHARSET_INFO *cs= ((type == OPT_GLOBAL) ? 02366 global_system_variables.collation_server : 02367 thd->variables.collation_server); 02368 return cs ? (byte*) cs->name : (byte*) "NULL"; 02369 } 02370 02371 02372 void sys_var_collation_server::set_default(THD *thd, enum_var_type type) 02373 { 02374 if (type == OPT_GLOBAL) 02375 global_system_variables.collation_server= default_charset_info; 02376 else 02377 { 02378 thd->variables.collation_server= (global_system_variables. 02379 collation_server); 02380 thd->update_charset(); 02381 } 02382 } 02383 02384 02385 LEX_STRING default_key_cache_base= {(char *) "default", 7 }; 02386 02387 static KEY_CACHE zero_key_cache; 02388 02389 KEY_CACHE *get_key_cache(LEX_STRING *cache_name) 02390 { 02391 safe_mutex_assert_owner(&LOCK_global_system_variables); 02392 if (!cache_name || ! cache_name->length) 02393 cache_name= &default_key_cache_base; 02394 return ((KEY_CACHE*) find_named(&key_caches, 02395 cache_name->str, cache_name->length, 0)); 02396 } 02397 02398 02399 byte *sys_var_key_cache_param::value_ptr(THD *thd, enum_var_type type, 02400 LEX_STRING *base) 02401 { 02402 KEY_CACHE *key_cache= get_key_cache(base); 02403 if (!key_cache) 02404 key_cache= &zero_key_cache; 02405 return (byte*) key_cache + offset ; 02406 } 02407 02408 02409 bool sys_var_key_buffer_size::update(THD *thd, set_var *var) 02410 { 02411 ulonglong tmp= var->save_result.ulonglong_value; 02412 LEX_STRING *base_name= &var->base; 02413 KEY_CACHE *key_cache; 02414 bool error= 0; 02415 02416 /* If no basename, assume it's for the key cache named 'default' */ 02417 if (!base_name->length) 02418 base_name= &default_key_cache_base; 02419 02420 pthread_mutex_lock(&LOCK_global_system_variables); 02421 key_cache= get_key_cache(base_name); 02422 02423 if (!key_cache) 02424 { 02425 /* Key cache didn't exists */ 02426 if (!tmp) // Tried to delete cache 02427 goto end; // Ok, nothing to do 02428 if (!(key_cache= create_key_cache(base_name->str, base_name->length))) 02429 { 02430 error= 1; 02431 goto end; 02432 } 02433 } 02434 02435 /* 02436 Abort if some other thread is changing the key cache 02437 TODO: This should be changed so that we wait until the previous 02438 assignment is done and then do the new assign 02439 */ 02440 if (key_cache->in_init) 02441 goto end; 02442 02443 if (!tmp) // Zero size means delete 02444 { 02445 if (key_cache == dflt_key_cache) 02446 { 02447 push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, 02448 ER_WARN_CANT_DROP_DEFAULT_KEYCACHE, 02449 ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE)); 02450 goto end; // Ignore default key cache 02451 } 02452 02453 if (key_cache->key_cache_inited) // If initied 02454 { 02455 /* 02456 Move tables using this key cache to the default key cache 02457 and clear the old key cache. 02458 */ 02459 NAMED_LIST *list; 02460 key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str, 02461 base_name->length, &list); 02462 key_cache->in_init= 1; 02463 pthread_mutex_unlock(&LOCK_global_system_variables); 02464 error= reassign_keycache_tables(thd, key_cache, dflt_key_cache); 02465 pthread_mutex_lock(&LOCK_global_system_variables); 02466 key_cache->in_init= 0; 02467 } 02468 /* 02469 We don't delete the key cache as some running threads my still be 02470 in the key cache code with a pointer to the deleted (empty) key cache 02471 */ 02472 goto end; 02473 } 02474 02475 key_cache->param_buff_size= 02476 (ulonglong) getopt_ull_limit_value(tmp, option_limits); 02477 02478 /* If key cache didn't existed initialize it, else resize it */ 02479 key_cache->in_init= 1; 02480 pthread_mutex_unlock(&LOCK_global_system_variables); 02481 02482 if (!key_cache->key_cache_inited) 02483 error= (bool) (ha_init_key_cache("", key_cache)); 02484 else 02485 error= (bool)(ha_resize_key_cache(key_cache)); 02486 02487 pthread_mutex_lock(&LOCK_global_system_variables); 02488 key_cache->in_init= 0; 02489 02490 end: 02491 pthread_mutex_unlock(&LOCK_global_system_variables); 02492 return error; 02493 } 02494 02495 02496 bool sys_var_key_cache_long::update(THD *thd, set_var *var) 02497 { 02498 ulong tmp= (ulong) var->value->val_int(); 02499 LEX_STRING *base_name= &var->base; 02500 bool error= 0; 02501 02502 if (!base_name->length) 02503 base_name= &default_key_cache_base; 02504 02505 pthread_mutex_lock(&LOCK_global_system_variables); 02506 KEY_CACHE *key_cache= get_key_cache(base_name); 02507 02508 if (!key_cache && !(key_cache= create_key_cache(base_name->str, 02509 base_name->length))) 02510 { 02511 error= 1; 02512 goto end; 02513 } 02514 02515 /* 02516 Abort if some other thread is changing the key cache 02517 TODO: This should be changed so that we wait until the previous 02518 assignment is done and then do the new assign 02519 */ 02520 if (key_cache->in_init) 02521 goto end; 02522 02523 *((ulong*) (((char*) key_cache) + offset))= 02524 (ulong) getopt_ull_limit_value(tmp, option_limits); 02525 02526 /* 02527 Don't create a new key cache if it didn't exist 02528 (key_caches are created only when the user sets block_size) 02529 */ 02530 key_cache->in_init= 1; 02531 02532 pthread_mutex_unlock(&LOCK_global_system_variables); 02533 02534 error= (bool) (ha_resize_key_cache(key_cache)); 02535 02536 pthread_mutex_lock(&LOCK_global_system_variables); 02537 key_cache->in_init= 0; 02538 02539 end: 02540 pthread_mutex_unlock(&LOCK_global_system_variables); 02541 return error; 02542 } 02543 02544 02545 bool sys_var_log_state::update(THD *thd, set_var *var) 02546 { 02547 bool res= 0; 02548 pthread_mutex_lock(&LOCK_global_system_variables); 02549 if (!var->save_result.ulong_value) 02550 logger.deactivate_log_handler(thd, log_type); 02551 else 02552 { 02553 if ((res= logger.activate_log_handler(thd, log_type))) 02554 { 02555 my_error(ER_CANT_ACTIVATE_LOG, MYF(0), 02556 log_type == QUERY_LOG_GENERAL ? "general" : 02557 "slow query"); 02558 goto err; 02559 } 02560 } 02561 err: 02562 pthread_mutex_unlock(&LOCK_global_system_variables); 02563 return res; 02564 } 02565 02566 void sys_var_log_state::set_default(THD *thd, enum_var_type type) 02567 { 02568 pthread_mutex_lock(&LOCK_global_system_variables); 02569 logger.deactivate_log_handler(thd, log_type); 02570 pthread_mutex_unlock(&LOCK_global_system_variables); 02571 } 02572 02573 02574 static int sys_check_log_path(THD *thd, set_var *var) 02575 { 02576 char path[FN_REFLEN]; 02577 MY_STAT f_stat; 02578 const char *var_path= var->value->str_value.ptr(); 02579 bzero(&f_stat, sizeof(MY_STAT)); 02580 02581 (void) unpack_filename(path, var_path); 02582 if (my_stat(path, &f_stat, MYF(0))) 02583 { 02584 /* Check if argument is a file and we have 'write' permission */ 02585 if (!MY_S_ISREG(f_stat.st_mode) || 02586 !(f_stat.st_mode & MY_S_IWRITE)) 02587 return -1; 02588 } 02589 else 02590 { 02591 /* 02592 Check if directory exists and 02593 we have permission to create file & write to file 02594 */ 02595 (void) dirname_part(path, var_path); 02596 if (my_access(path, (F_OK|W_OK))) 02597 return -1; 02598 } 02599 return 0; 02600 } 02601 02602 02603 bool update_sys_var_str_path(THD *thd, sys_var_str *var_str, 02604 set_var *var, const char *log_ext, 02605 bool log_state, uint log_type) 02606 { 02607 MYSQL_QUERY_LOG *file_log; 02608 char buff[FN_REFLEN]; 02609 char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0); 02610 bool result= 0; 02611 uint str_length= (var ? var->value->str_value.length() : 0); 02612 02613 switch (log_type) { 02614 case QUERY_LOG_SLOW: 02615 file_log= logger.get_slow_log_file_handler(); 02616 break; 02617 case QUERY_LOG_GENERAL: 02618 file_log= logger.get_log_file_handler(); 02619 break; 02620 default: 02621 DBUG_ASSERT(0); 02622 } 02623 02624 if (!old_value) 02625 { 02626 old_value= make_default_log_name(buff, log_ext); 02627 str_length= strlen(old_value); 02628 } 02629 if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME)))) 02630 { 02631 result= 1; 02632 goto err; 02633 } 02634 02635 pthread_mutex_lock(&LOCK_global_system_variables); 02636 logger.lock(); 02637 02638 if (file_log && log_state) 02639 file_log->close(0); 02640 old_value= var_str->value; 02641 var_str->value= res; 02642 var_str->value_length= str_length; 02643 my_free(old_value, MYF(MY_ALLOW_ZERO_PTR)); 02644 if (file_log && log_state) 02645 { 02646 switch (log_type) { 02647 case QUERY_LOG_SLOW: 02648 file_log->open_slow_log(sys_var_general_log_path.value); 02649 break; 02650 case QUERY_LOG_GENERAL: 02651 file_log->open_query_log(sys_var_general_log_path.value); 02652 break; 02653 default: 02654 DBUG_ASSERT(0); 02655 } 02656 } 02657 02658 logger.unlock(); 02659 pthread_mutex_unlock(&LOCK_global_system_variables); 02660 02661 err: 02662 return result; 02663 } 02664 02665 02666 static bool sys_update_general_log_path(THD *thd, set_var * var) 02667 { 02668 return update_sys_var_str_path(thd, &sys_var_general_log_path, 02669 var, ".log", opt_log, QUERY_LOG_GENERAL); 02670 } 02671 02672 02673 static void sys_default_general_log_path(THD *thd, enum_var_type type) 02674 { 02675 (void) update_sys_var_str_path(thd, &sys_var_general_log_path, 02676 0, ".log", opt_log, QUERY_LOG_GENERAL); 02677 } 02678 02679 02680 static bool sys_update_slow_log_path(THD *thd, set_var * var) 02681 { 02682 return update_sys_var_str_path(thd, &sys_var_slow_log_path, 02683 var, "-slow.log", opt_slow_log, 02684 QUERY_LOG_SLOW); 02685 } 02686 02687 02688 static void sys_default_slow_log_path(THD *thd, enum_var_type type) 02689 { 02690 (void) update_sys_var_str_path(thd, &sys_var_slow_log_path, 02691 0, "-slow.log", opt_slow_log, 02692 QUERY_LOG_SLOW); 02693 } 02694 02695 02696 bool sys_var_log_output::update(THD *thd, set_var *var) 02697 { 02698 pthread_mutex_lock(&LOCK_global_system_variables); 02699 logger.lock(); 02700 logger.init_slow_log(var->save_result.ulong_value); 02701 logger.init_general_log(var->save_result.ulong_value); 02702 *value= var->save_result.ulong_value; 02703 logger.unlock(); 02704 pthread_mutex_unlock(&LOCK_global_system_variables); 02705 return 0; 02706 } 02707 02708 02709 void sys_var_log_output::set_default(THD *thd, enum_var_type type) 02710 { 02711 pthread_mutex_lock(&LOCK_global_system_variables); 02712 logger.lock(); 02713 logger.init_slow_log(LOG_TABLE); 02714 logger.init_general_log(LOG_TABLE); 02715 *value= LOG_TABLE; 02716 logger.unlock(); 02717 pthread_mutex_unlock(&LOCK_global_system_variables); 02718 } 02719 02720 02721 byte *sys_var_log_output::value_ptr(THD *thd, enum_var_type type, 02722 LEX_STRING *base) 02723 { 02724 char buff[256]; 02725 String tmp(buff, sizeof(buff), &my_charset_latin1); 02726 ulong length; 02727 ulong val= *value; 02728 02729 tmp.length(0); 02730 for (uint i= 0; val; val>>= 1, i++) 02731 { 02732 if (val & 1) 02733 { 02734 tmp.append(log_output_typelib.type_names[i], 02735 log_output_typelib.type_lengths[i]); 02736 tmp.append(','); 02737 } 02738 } 02739 02740 if ((length= tmp.length())) 02741 length--; 02742 return (byte*) thd->strmake(tmp.ptr(), length); 02743 } 02744 02745 02746 /***************************************************************************** 02747 Functions to handle SET NAMES and SET CHARACTER SET 02748 *****************************************************************************/ 02749 02750 int set_var_collation_client::check(THD *thd) 02751 { 02752 return 0; 02753 } 02754 02755 int set_var_collation_client::update(THD *thd) 02756 { 02757 thd->variables.character_set_client= character_set_client; 02758 thd->variables.character_set_results= character_set_results; 02759 thd->variables.collation_connection= collation_connection; 02760 thd->update_charset(); 02761 thd->protocol_simple.init(thd); 02762 thd->protocol_prep.init(thd); 02763 return 0; 02764 } 02765 02766 /****************************************************************************/ 02767 02768 bool sys_var_timestamp::update(THD *thd, set_var *var) 02769 { 02770 thd->set_time((time_t) var->save_result.ulonglong_value); 02771 return 0; 02772 } 02773 02774 02775 void sys_var_timestamp::set_default(THD *thd, enum_var_type type) 02776 { 02777 thd->user_time=0; 02778 } 02779 02780 02781 byte *sys_var_timestamp::value_ptr(THD *thd, enum_var_type type, 02782 LEX_STRING *base) 02783 { 02784 thd->sys_var_tmp.long_value= (long) thd->start_time; 02785 return (byte*) &thd->sys_var_tmp.long_value; 02786 } 02787 02788 02789 bool sys_var_last_insert_id::update(THD *thd, set_var *var) 02790 { 02791 thd->first_successful_insert_id_in_prev_stmt= 02792 var->save_result.ulonglong_value; 02793 return 0; 02794 } 02795 02796 02797 byte *sys_var_last_insert_id::value_ptr(THD *thd, enum_var_type type, 02798 LEX_STRING *base) 02799 { 02800 /* 02801 this tmp var makes it robust againt change of type of 02802 read_first_successful_insert_id_in_prev_stmt(). 02803 */ 02804 thd->sys_var_tmp.ulonglong_value= 02805 thd->read_first_successful_insert_id_in_prev_stmt(); 02806 return (byte*) &thd->sys_var_tmp.ulonglong_value; 02807 } 02808 02809 02810 bool sys_var_insert_id::update(THD *thd, set_var *var) 02811 { 02812 thd->force_one_auto_inc_interval(var->save_result.ulonglong_value); 02813 return 0; 02814 } 02815 02816 02817 byte *sys_var_insert_id::value_ptr(THD *thd, enum_var_type type, 02818 LEX_STRING *base) 02819 { 02820 thd->sys_var_tmp.ulonglong_value= 02821 thd->auto_inc_intervals_forced.minimum(); 02822 return (byte*) &thd->sys_var_tmp.ulonglong_value; 02823 } 02824 02825 02826 #ifdef HAVE_REPLICATION 02827 bool sys_var_slave_skip_counter::check(THD *thd, set_var *var) 02828 { 02829 int result= 0; 02830 pthread_mutex_lock(&LOCK_active_mi); 02831 pthread_mutex_lock(&active_mi->rli.run_lock); 02832 if (active_mi->rli.slave_running) 02833 { 02834 my_message(ER_SLAVE_MUST_STOP, ER(ER_SLAVE_MUST_STOP), MYF(0)); 02835 result=1; 02836 } 02837 pthread_mutex_unlock(&active_mi->rli.run_lock); 02838 pthread_mutex_unlock(&LOCK_active_mi); 02839 var->save_result.ulong_value= (ulong) var->value->val_int(); 02840 return result; 02841 } 02842 02843 02844 bool sys_var_slave_skip_counter::update(THD *thd, set_var *var) 02845 { 02846 pthread_mutex_lock(&LOCK_active_mi); 02847 pthread_mutex_lock(&active_mi->rli.run_lock); 02848 /* 02849 The following test should normally never be true as we test this 02850 in the check function; To be safe against multiple 02851 SQL_SLAVE_SKIP_COUNTER request, we do the check anyway 02852 */ 02853 if (!active_mi->rli.slave_running) 02854 { 02855 pthread_mutex_lock(&active_mi->rli.data_lock); 02856 active_mi->rli.slave_skip_counter= var->save_result.ulong_value; 02857 pthread_mutex_unlock(&active_mi->rli.data_lock); 02858 } 02859 pthread_mutex_unlock(&active_mi->rli.run_lock); 02860 pthread_mutex_unlock(&LOCK_active_mi); 02861 return 0; 02862 } 02863 02864 02865 bool sys_var_sync_binlog_period::update(THD *thd, set_var *var) 02866 { 02867 sync_binlog_period= (ulong) var->save_result.ulonglong_value; 02868 return 0; 02869 } 02870 #endif /* HAVE_REPLICATION */ 02871 02872 bool sys_var_rand_seed1::update(THD *thd, set_var *var) 02873 { 02874 thd->rand.seed1= (ulong) var->save_result.ulonglong_value; 02875 return 0; 02876 } 02877 02878 bool sys_var_rand_seed2::update(THD *thd, set_var *var) 02879 { 02880 thd->rand.seed2= (ulong) var->save_result.ulonglong_value; 02881 return 0; 02882 } 02883 02884 02885 bool sys_var_thd_time_zone::check(THD *thd, set_var *var) 02886 { 02887 char buff[MAX_TIME_ZONE_NAME_LENGTH]; 02888 String str(buff, sizeof(buff), &my_charset_latin1); 02889 String *res= var->value->val_str(&str); 02890 02891 if (!(var->save_result.time_zone= 02892 my_tz_find(res, thd->lex->time_zone_tables_used))) 02893 { 02894 my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL"); 02895 return 1; 02896 } 02897 return 0; 02898 } 02899 02900 02901 bool sys_var_thd_time_zone::update(THD *thd, set_var *var) 02902 { 02903 /* We are using Time_zone object found during check() phase. */ 02904 if (var->type == OPT_GLOBAL) 02905 { 02906 pthread_mutex_lock(&LOCK_global_system_variables); 02907 global_system_variables.time_zone= var->save_result.time_zone; 02908 pthread_mutex_unlock(&LOCK_global_system_variables); 02909 } 02910 else 02911 thd->variables.time_zone= var->save_result.time_zone; 02912 return 0; 02913 } 02914 02915 02916 byte *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type, 02917 LEX_STRING *base) 02918 { 02919 /* 02920 We can use ptr() instead of c_ptr() here because String contaning 02921 time zone name is guaranteed to be zero ended. 02922 */ 02923 if (type == OPT_GLOBAL) 02924 return (byte *)(global_system_variables.time_zone->get_name()->ptr()); 02925 else 02926 { 02927 /* 02928 This is an ugly fix for replication: we don't replicate properly queries 02929 invoking system variables' values to update tables; but 02930 CONVERT_TZ(,,@@session.time_zone) is so popular that we make it 02931 replicable (i.e. we tell the binlog code to store the session 02932 timezone). If it's the global value which was used we can't replicate 02933 (binlog code stores session value only). 02934 */ 02935 thd->time_zone_used= 1; 02936 return (byte *)(thd->variables.time_zone->get_name()->ptr()); 02937 } 02938 } 02939 02940 02941 void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type) 02942 { 02943 pthread_mutex_lock(&LOCK_global_system_variables); 02944 if (type == OPT_GLOBAL) 02945 { 02946 if (default_tz_name) 02947 { 02948 String str(default_tz_name, &my_charset_latin1); 02949 /* 02950 We are guaranteed to find this time zone since its existence 02951 is checked during start-up. 02952 */ 02953 global_system_variables.time_zone= 02954 my_tz_find(&str, thd->lex->time_zone_tables_used); 02955 } 02956 else 02957 global_system_variables.time_zone= my_tz_SYSTEM; 02958 } 02959 else 02960 thd->variables.time_zone= global_system_variables.time_zone; 02961 pthread_mutex_unlock(&LOCK_global_system_variables); 02962 } 02963 02964 02965 bool sys_var_max_user_conn::check(THD *thd, set_var *var) 02966 { 02967 if (var->type == OPT_GLOBAL) 02968 return sys_var_thd::check(thd, var); 02969 else 02970 { 02971 /* 02972 Per-session values of max_user_connections can't be set directly. 02973 May be we should have a separate error message for this? 02974 */ 02975 my_error(ER_GLOBAL_VARIABLE, MYF(0), name); 02976 return TRUE; 02977 } 02978 } 02979 02980 bool sys_var_max_user_conn::update(THD *thd, set_var *var) 02981 { 02982 DBUG_ASSERT(var->type == OPT_GLOBAL); 02983 pthread_mutex_lock(&LOCK_global_system_variables); 02984 max_user_connections= (uint)var->save_result.ulonglong_value; 02985 pthread_mutex_unlock(&LOCK_global_system_variables); 02986 return 0; 02987 } 02988 02989 02990 void sys_var_max_user_conn::set_default(THD *thd, enum_var_type type) 02991 { 02992 DBUG_ASSERT(type == OPT_GLOBAL); 02993 pthread_mutex_lock(&LOCK_global_system_variables); 02994 max_user_connections= (ulong) option_limits->def_value; 02995 pthread_mutex_unlock(&LOCK_global_system_variables); 02996 } 02997 02998 02999 byte *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type, 03000 LEX_STRING *base) 03001 { 03002 if (type != OPT_GLOBAL && 03003 thd->user_connect && thd->user_connect->user_resources.user_conn) 03004 return (byte*) &(thd->user_connect->user_resources.user_conn); 03005 return (byte*) &(max_user_connections); 03006 } 03007 03008 bool sys_var_thd_lc_time_names::check(THD *thd, set_var *var) 03009 { 03010 char *locale_str =var->value->str_value.c_ptr(); 03011 MY_LOCALE *locale_match= my_locale_by_name(locale_str); 03012 03013 if (locale_match == NULL) 03014 { 03015 my_printf_error(ER_UNKNOWN_ERROR, 03016 "Unknown locale: '%s'", MYF(0), locale_str); 03017 return 1; 03018 } 03019 var->save_result.locale_value= locale_match; 03020 return 0; 03021 } 03022 03023 03024 bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var) 03025 { 03026 thd->variables.lc_time_names= var->save_result.locale_value; 03027 return 0; 03028 } 03029 03030 03031 byte *sys_var_thd_lc_time_names::value_ptr(THD *thd, enum_var_type type, 03032 LEX_STRING *base) 03033 { 03034 return (byte *)(thd->variables.lc_time_names->name); 03035 } 03036 03037 03038 void sys_var_thd_lc_time_names::set_default(THD *thd, enum_var_type type) 03039 { 03040 thd->variables.lc_time_names = &my_locale_en_US; 03041 } 03042 03043 /* 03044 Functions to update thd->options bits 03045 */ 03046 03047 static bool set_option_bit(THD *thd, set_var *var) 03048 { 03049 sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var); 03050 if ((var->save_result.ulong_value != 0) == sys_var->reverse) 03051 thd->options&= ~sys_var->bit_flag; 03052 else 03053 thd->options|= sys_var->bit_flag; 03054 return 0; 03055 } 03056 03057 03058 static bool set_option_autocommit(THD *thd, set_var *var) 03059 { 03060 /* The test is negative as the flag we use is NOT autocommit */ 03061 03062 ulong org_options=thd->options; 03063 03064 if (var->save_result.ulong_value != 0) 03065 thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag; 03066 else 03067 thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag; 03068 03069 if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT) 03070 { 03071 if ((org_options & OPTION_NOT_AUTOCOMMIT)) 03072 { 03073 /* We changed to auto_commit mode */ 03074 thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE | 03075 OPTION_KEEP_LOG); 03076 thd->server_status|= SERVER_STATUS_AUTOCOMMIT; 03077 if (ha_commit(thd)) 03078 return 1; 03079 } 03080 else 03081 { 03082 thd->options&= ~(ulong) (OPTION_STATUS_NO_TRANS_UPDATE); 03083 thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT; 03084 } 03085 } 03086 return 0; 03087 } 03088 03089 static int check_log_update(THD *thd, set_var *var) 03090 { 03091 #ifndef NO_EMBEDDED_ACCESS_CHECKS 03092 if (!(thd->security_ctx->master_access & SUPER_ACL)) 03093 { 03094 my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER"); 03095 return 1; 03096 } 03097 #endif 03098 return 0; 03099 } 03100 03101 static bool set_log_update(THD *thd, set_var *var) 03102 { 03103 /* 03104 The update log is not supported anymore since 5.0. 03105 See sql/mysqld.cc/, comments in function init_server_components() for an 03106 explaination of the different warnings we send below 03107 */ 03108 03109 if (opt_sql_bin_update) 03110 { 03111 push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, 03112 ER_UPDATE_LOG_DEPRECATED_TRANSLATED, 03113 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED)); 03114 } 03115 else 03116 push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, 03117 ER_UPDATE_LOG_DEPRECATED_IGNORED, 03118 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED)); 03119 set_option_bit(thd, var); 03120 return 0; 03121 } 03122 03123 03124 static int check_pseudo_thread_id(THD *thd, set_var *var) 03125 { 03126 var->save_result.ulonglong_value= var->value->val_int(); 03127 #ifndef NO_EMBEDDED_ACCESS_CHECKS 03128 if (thd->security_ctx->master_access & SUPER_ACL) 03129 return 0; 03130 else 03131 { 03132 my_error(ER_SPECIFIC_ACCESS_DENIED_ERROR, MYF(0), "SUPER"); 03133 return 1; 03134 } 03135 #else 03136 return 0; 03137 #endif 03138 } 03139 03140 static byte *get_warning_count(THD *thd) 03141 { 03142 thd->sys_var_tmp.long_value= 03143 (thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] + 03144 thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]); 03145 return (byte*) &thd->sys_var_tmp.long_value; 03146 } 03147 03148 static byte *get_error_count(THD *thd) 03149 { 03150 thd->sys_var_tmp.long_value= 03151 thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR]; 03152 return (byte*) &thd->sys_var_tmp.long_value; 03153 } 03154 03155 static byte *get_prepared_stmt_count(THD *thd) 03156 { 03157 pthread_mutex_lock(&LOCK_prepared_stmt_count); 03158 thd->sys_var_tmp.ulong_value= prepared_stmt_count; 03159 pthread_mutex_unlock(&LOCK_prepared_stmt_count); 03160 return (byte*) &thd->sys_var_tmp.ulong_value; 03161 } 03162 03163 03164 /* 03165 Get the tmpdir that was specified or chosen by default 03166 03167 SYNOPSIS 03168 get_tmpdir() 03169 thd thread handle 03170 03171 DESCRIPTION 03172 This is necessary because if the user does not specify a temporary 03173 directory via the command line, one is chosen based on the environment 03174 or system defaults. But we can't just always use mysql_tmpdir, because 03175 that is actually a call to my_tmpdir() which cycles among possible 03176 temporary directories. 03177 03178 RETURN VALUES 03179 ptr pointer to NUL-terminated string 03180 */ 03181 static byte *get_tmpdir(THD *thd) 03182 { 03183 if (opt_mysql_tmpdir) 03184 return (byte *)opt_mysql_tmpdir; 03185 return (byte*)mysql_tmpdir; 03186 } 03187 03188 /**************************************************************************** 03189 Main handling of variables: 03190 - Initialisation 03191 - Searching during parsing 03192 - Update loop 03193 ****************************************************************************/ 03194 03195 /* 03196 Find variable name in option my_getopt structure used for command line args 03197 03198 SYNOPSIS 03199 find_option() 03200 opt option structure array to search in 03201 name variable name 03202 03203 RETURN VALUES 03204 0 Error 03205 ptr pointer to option structure 03206 */ 03207 03208 static struct my_option *find_option(struct my_option *opt, const char *name) 03209 { 03210 uint length=strlen(name); 03211 for (; opt->name; opt++) 03212 { 03213 if (!getopt_compare_strings(opt->name, name, length) && 03214 !opt->name[length]) 03215 { 03216 /* 03217 Only accept the option if one can set values through it. 03218 If not, there is no default value or limits in the option. 03219 */ 03220 return (opt->value) ? opt : 0; 03221 } 03222 } 03223 return 0; 03224 } 03225 03226 03227 /* 03228 Return variable name and length for hashing of variables 03229 */ 03230 03231 static byte *get_sys_var_length(const sys_var *var, uint *length, 03232 my_bool first) 03233 { 03234 *length= var->name_length; 03235 return (byte*) var->name; 03236 } 03237 03238 03239 /* 03240 Initialises sys variables and put them in system_variable_hash 03241 */ 03242 03243 03244 void set_var_init() 03245 { 03246 sys_var *var; 03247 03248 hash_init(&system_variable_hash, system_charset_info, sys_var::sys_vars, 0, 03249 0, (hash_get_key) get_sys_var_length, 0, 0); 03250 for (var= sys_var::first; var; var= var->next) 03251 { 03252 var->name_length= strlen(var->name); 03253 var->option_limits= find_option(my_long_options, var->name); 03254 my_hash_insert(&system_variable_hash, (byte*) var); 03255 } 03256 /* 03257 Special cases 03258 Needed because MySQL can't find the limits for a variable it it has 03259 a different name than the command line option. 03260 As these variables are deprecated, this code will disappear soon... 03261 */ 03262 sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits; 03263 } 03264 03265 03266 void set_var_free() 03267 { 03268 hash_free(&system_variable_hash); 03269 } 03270 03271 03272 /* 03273 Find a user set-table variable 03274 03275 SYNOPSIS 03276 find_sys_var() 03277 str Name of system variable to find 03278 length Length of variable. zero means that we should use strlen() 03279 on the variable 03280 03281 RETURN VALUES 03282 pointer pointer to variable definitions 03283 0 Unknown variable (error message is given) 03284 */ 03285 03286 sys_var *find_sys_var(const char *str, uint length) 03287 { 03288 sys_var *var= (sys_var*) hash_search(&system_variable_hash, 03289 (byte*) str, 03290 length ? length : 03291 strlen(str)); 03292 if (!var) 03293 my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str); 03294 return var; 03295 } 03296 03297 03298 /* 03299 Execute update of all variables 03300 03301 SYNOPSIS 03302 03303 sql_set 03304 THD Thread id 03305 set_var List of variables to update 03306 03307 DESCRIPTION 03308 First run a check of all variables that all updates will go ok. 03309 If yes, then execute all updates, returning an error if any one failed. 03310 03311 This should ensure that in all normal cases none all or variables are 03312 updated 03313 03314 RETURN VALUE 03315 0 ok 03316 1 ERROR, message sent (normally no variables was updated) 03317 -1 ERROR, message not sent 03318 */ 03319 03320 int sql_set_variables(THD *thd, List<set_var_base> *var_list) 03321 { 03322 int error; 03323 List_iterator_fast<set_var_base> it(*var_list); 03324 DBUG_ENTER("sql_set_variables"); 03325 03326 set_var_base *var; 03327 while ((var=it++)) 03328 { 03329 if ((error= var->check(thd))) 03330 goto err; 03331 } 03332 if (!(error= test(thd->net.report_error))) 03333 { 03334 it.rewind(); 03335 while ((var= it++)) 03336 error|= var->update(thd); // Returns 0, -1 or 1 03337 } 03338 03339 err: 03340 free_underlaid_joins(thd, &thd->lex->select_lex); 03341 DBUG_RETURN(error); 03342 } 03343 03344 03345 /* 03346 Say if all variables set by a SET support the ONE_SHOT keyword (currently, 03347 only character set and collation do; later timezones will). 03348 03349 SYNOPSIS 03350 03351 not_all_support_one_shot 03352 set_var List of variables to update 03353 03354 NOTES 03355 It has a "not_" because it makes faster tests (no need to "!") 03356 03357 RETURN VALUE 03358 0 all variables of the list support ONE_SHOT 03359 1 at least one does not support ONE_SHOT 03360 */ 03361 03362 bool not_all_support_one_shot(List<set_var_base> *var_list) 03363 { 03364 List_iterator_fast<set_var_base> it(*var_list); 03365 set_var_base *var; 03366 while ((var= it++)) 03367 { 03368 if (var->no_support_one_shot()) 03369 return 1; 03370 } 03371 return 0; 03372 } 03373 03374 03375 /***************************************************************************** 03376 Functions to handle SET mysql_internal_variable=const_expr 03377 *****************************************************************************/ 03378 03379 int set_var::check(THD *thd) 03380 { 03381 if (var->is_readonly()) 03382 { 03383 my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name, "read only"); 03384 return -1; 03385 } 03386 if (var->check_type(type)) 03387 { 03388 int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; 03389 my_error(err, MYF(0), var->name); 03390 return -1; 03391 } 03392 if ((type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL))) 03393 return 1; 03394 /* value is a NULL pointer if we are using SET ... = DEFAULT */ 03395 if (!value) 03396 { 03397 if (var->check_default(type)) 03398 { 03399 my_error(ER_NO_DEFAULT, MYF(0), var->name); 03400 return -1; 03401 } 03402 return 0; 03403 } 03404 03405 if ((!value->fixed && 03406 value->fix_fields(thd, &value)) || value->check_cols(1)) 03407 return -1; 03408 if (var->check_update_type(value->result_type())) 03409 { 03410 my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name); 03411 return -1; 03412 } 03413 return var->check(thd, this) ? -1 : 0; 03414 } 03415 03416 03417 /* 03418 Check variable, but without assigning value (used by PS) 03419 03420 SYNOPSIS 03421 set_var::light_check() 03422 thd thread handler 03423 03424 RETURN VALUE 03425 0 ok 03426 1 ERROR, message sent (normally no variables was updated) 03427 -1 ERROR, message not sent 03428 */ 03429 int set_var::light_check(THD *thd) 03430 { 03431 if (var->check_type(type)) 03432 { 03433 int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE; 03434 my_error(err, MYF(0), var->name); 03435 return -1; 03436 } 03437 if (type == OPT_GLOBAL && check_global_access(thd, SUPER_ACL)) 03438 return 1; 03439 03440 if (value && ((!value->fixed && value->fix_fields(thd, &value)) || 03441 value->check_cols(1))) 03442 return -1; 03443 return 0; 03444 } 03445 03446 03447 int set_var::update(THD *thd) 03448 { 03449 if (!value) 03450 var->set_default(thd, type); 03451 else if (var->update(thd, this)) 03452 return -1; // should never happen 03453 if (var->after_update) 03454 (*var->after_update)(thd, type); 03455 return 0; 03456 } 03457 03458 03459 /***************************************************************************** 03460 Functions to handle SET @user_variable=const_expr 03461 *****************************************************************************/ 03462 03463 int set_var_user::check(THD *thd) 03464 { 03465 /* 03466 Item_func_set_user_var can't substitute something else on its place => 03467 0 can be passed as last argument (reference on item) 03468 */ 03469 return (user_var_item->fix_fields(thd, (Item**) 0) || 03470 user_var_item->check()) ? -1 : 0; 03471 } 03472 03473 03474 /* 03475 Check variable, but without assigning value (used by PS) 03476 03477 SYNOPSIS 03478 set_var_user::light_check() 03479 thd thread handler 03480 03481 RETURN VALUE 03482 0 ok 03483 1 ERROR, message sent (normally no variables was updated) 03484 -1 ERROR, message not sent 03485 */ 03486 int set_var_user::light_check(THD *thd) 03487 { 03488 /* 03489 Item_func_set_user_var can't substitute something else on its place => 03490 0 can be passed as last argument (reference on item) 03491 */ 03492 return (user_var_item->fix_fields(thd, (Item**) 0)); 03493 } 03494 03495 03496 int set_var_user::update(THD *thd) 03497 { 03498 if (user_var_item->update()) 03499 { 03500 /* Give an error if it's not given already */ 03501 my_message(ER_SET_CONSTANTS_ONLY, ER(ER_SET_CONSTANTS_ONLY), MYF(0)); 03502 return -1; 03503 } 03504 return 0; 03505 } 03506 03507 03508 /***************************************************************************** 03509 Functions to handle SET PASSWORD 03510 *****************************************************************************/ 03511 03512 int set_var_password::check(THD *thd) 03513 { 03514 #ifndef NO_EMBEDDED_ACCESS_CHECKS 03515 if (!user->host.str) 03516 { 03517 if (*thd->security_ctx->priv_host != 0) 03518 { 03519 user->host.str= (char *) thd->security_ctx->priv_host; 03520 user->host.length= strlen(thd->security_ctx->priv_host); 03521 } 03522 else 03523 { 03524 user->host.str= (char *)"%"; 03525 user->host.length= 1; 03526 } 03527 } 03528 /* Returns 1 as the function sends error to client */ 03529 return check_change_password(thd, user->host.str, user->user.str, 03530 password, strlen(password)) ? 1 : 0; 03531 #else 03532 return 0; 03533 #endif 03534 } 03535 03536 int set_var_password::update(THD *thd) 03537 { 03538 #ifndef NO_EMBEDDED_ACCESS_CHECKS 03539 /* Returns 1 as the function sends error to client */ 03540 return change_password(thd, user->host.str, user->user.str, password) ? 03541 1 : 0; 03542 #else 03543 return 0; 03544 #endif 03545 } 03546 03547 /**************************************************************************** 03548 Functions to handle table_type 03549 ****************************************************************************/ 03550 03551 /* Based upon sys_var::check_enum() */ 03552 03553 bool sys_var_thd_storage_engine::check(THD *thd, set_var *var) 03554 { 03555 char buff[STRING_BUFFER_USUAL_SIZE]; 03556 const char *value; 03557 String str(buff, sizeof(buff), &my_charset_latin1), *res; 03558 03559 if (var->value->result_type() == STRING_RESULT) 03560 { 03561 LEX_STRING name; 03562 handlerton *db_type; 03563 if (!(res=var->value->val_str(&str)) || 03564 !(name.str= (char *)res->ptr()) || !(name.length= res->length()) || 03565 !(var->save_result.hton= db_type= ha_resolve_by_name(thd, &name)) || 03566 ha_checktype(thd, ha_legacy_type(db_type), 1, 0) != db_type) 03567 { 03568 value= res ? res->c_ptr() : "NULL"; 03569 goto err; 03570 } 03571 return 0; 03572 } 03573 value= "unknown"; 03574 03575 err: 03576 my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), value); 03577 return 1; 03578 } 03579 03580 03581 byte *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type, 03582 LEX_STRING *base) 03583 { 03584 handlerton *val; 03585 val= (type == OPT_GLOBAL) ? global_system_variables.*offset : 03586 thd->variables.*offset; 03587 return (byte *) hton2plugin[val->slot]->name.str; 03588 } 03589 03590 03591 void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type) 03592 { 03593 if (type == OPT_GLOBAL) 03594 global_system_variables.*offset= &myisam_hton; 03595 else 03596 thd->variables.*offset= global_system_variables.*offset; 03597 } 03598 03599 03600 bool sys_var_thd_storage_engine::update(THD *thd, set_var *var) 03601 { 03602 handlerton **value= &(global_system_variables.*offset); 03603 if (var->type != OPT_GLOBAL) 03604 value= &(thd->variables.*offset); 03605 *value= var->save_result.hton; 03606 return 0; 03607 } 03608 03609 void sys_var_thd_table_type::warn_deprecated(THD *thd) 03610 { 03611 WARN_DEPRECATED(thd, "5.2", "table_type", "'storage_engine'"); 03612 } 03613 03614 void sys_var_thd_table_type::set_default(THD *thd, enum_var_type type) 03615 { 03616 warn_deprecated(thd); 03617 sys_var_thd_storage_engine::set_default(thd, type); 03618 } 03619 03620 bool sys_var_thd_table_type::update(THD *thd, set_var *var) 03621 { 03622 warn_deprecated(thd); 03623 return sys_var_thd_storage_engine::update(thd, var); 03624 } 03625 03626 03627 /**************************************************************************** 03628 Functions to handle sql_mode 03629 ****************************************************************************/ 03630 03631 /* 03632 Make string representation of mode 03633 03634 SYNOPSIS 03635 thd in thread handler 03636 val in sql_mode value 03637 len out pointer on length of string 03638 03639 RETURN 03640 pointer to string with sql_mode representation 03641 */ 03642 03643 byte *sys_var_thd_sql_mode::symbolic_mode_representation(THD *thd, ulong val, 03644 ulong *len) 03645 { 03646 char buff[256]; 03647 String tmp(buff, sizeof(buff), &my_charset_latin1); 03648 ulong length; 03649 03650 tmp.length(0); 03651 for (uint i= 0; val; val>>= 1, i++) 03652 { 03653 if (val & 1) 03654 { 03655 tmp.append(sql_mode_typelib.type_names[i], 03656 sql_mode_typelib.type_lengths[i]); 03657 tmp.append(','); 03658 } 03659 } 03660 03661 if ((length= tmp.length())) 03662 length--; 03663 *len= length; 03664 return (byte*) thd->strmake(tmp.ptr(), length); 03665 } 03666 03667 03668 byte *sys_var_thd_sql_mode::value_ptr(THD *thd, enum_var_type type, 03669 LEX_STRING *base) 03670 { 03671 ulong val= ((type == OPT_GLOBAL) ? global_system_variables.*offset : 03672 thd->variables.*offset); 03673 ulong length_unused; 03674 return symbolic_mode_representation(thd, val, &length_unused); 03675 } 03676 03677 03678 void sys_var_thd_sql_mode::set_default(THD *thd, enum_var_type type) 03679 { 03680 if (type == OPT_GLOBAL) 03681 global_system_variables.*offset= 0; 03682 else 03683 thd->variables.*offset= global_system_variables.*offset; 03684 } 03685 03686 03687 void fix_sql_mode_var(THD *thd, enum_var_type type) 03688 { 03689 if (type == OPT_GLOBAL) 03690 global_system_variables.sql_mode= 03691 fix_sql_mode(global_system_variables.sql_mode); 03692 else 03693 { 03694 thd->variables.sql_mode= fix_sql_mode(thd->variables.sql_mode); 03695 /* 03696 Update thd->server_status 03697 */ 03698 if (thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) 03699 thd->server_status|= SERVER_STATUS_NO_BACKSLASH_ESCAPES; 03700 else 03701 thd->server_status&= ~SERVER_STATUS_NO_BACKSLASH_ESCAPES; 03702 } 03703 } 03704 03705 /* Map database specific bits to function bits */ 03706 03707 ulong fix_sql_mode(ulong sql_mode) 03708 { 03709 /* 03710 Note that we dont set 03711 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | MODE_NO_FIELD_OPTIONS 03712 to allow one to get full use of MySQL in this mode. 03713 */ 03714 03715 if (sql_mode & MODE_ANSI) 03716 { 03717 sql_mode|= (MODE_REAL_AS_FLOAT | MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES | 03718 MODE_IGNORE_SPACE); 03719 /* 03720 MODE_ONLY_FULL_GROUP_BY removed from ANSI mode because it is currently 03721 overly restrictive (see BUG#8510). 03722 */ 03723 } 03724 if (sql_mode & MODE_ORACLE) 03725 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES | 03726 MODE_IGNORE_SPACE | 03727 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | 03728 MODE_NO_FIELD_OPTIONS | MODE_NO_AUTO_CREATE_USER); 03729 if (sql_mode & MODE_MSSQL) 03730 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES | 03731 MODE_IGNORE_SPACE | 03732 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | 03733 MODE_NO_FIELD_OPTIONS); 03734 if (sql_mode & MODE_POSTGRESQL) 03735 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES | 03736 MODE_IGNORE_SPACE | 03737 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | 03738 MODE_NO_FIELD_OPTIONS); 03739 if (sql_mode & MODE_DB2) 03740 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES | 03741 MODE_IGNORE_SPACE | 03742 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | 03743 MODE_NO_FIELD_OPTIONS); 03744 if (sql_mode & MODE_MAXDB) 03745 sql_mode|= (MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES | 03746 MODE_IGNORE_SPACE | 03747 MODE_NO_KEY_OPTIONS | MODE_NO_TABLE_OPTIONS | 03748 MODE_NO_FIELD_OPTIONS | MODE_NO_AUTO_CREATE_USER); 03749 if (sql_mode & MODE_MYSQL40) 03750 sql_mode|= MODE_HIGH_NOT_PRECEDENCE; 03751 if (sql_mode & MODE_MYSQL323) 03752 sql_mode|= MODE_HIGH_NOT_PRECEDENCE; 03753 if (sql_mode & MODE_TRADITIONAL) 03754 sql_mode|= (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES | 03755 MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE | 03756 MODE_ERROR_FOR_DIVISION_BY_ZERO | MODE_NO_AUTO_CREATE_USER); 03757 return sql_mode; 03758 } 03759 03760 03761 /**************************************************************************** 03762 Named list handling 03763 ****************************************************************************/ 03764 03765 gptr find_named(I_List<NAMED_LIST> *list, const char *name, uint length, 03766 NAMED_LIST **found) 03767 { 03768 I_List_iterator<NAMED_LIST> it(*list); 03769 NAMED_LIST *element; 03770 while ((element= it++)) 03771 { 03772 if (element->cmp(name, length)) 03773 { 03774 if (found) 03775 *found= element; 03776 return element->data; 03777 } 03778 } 03779 return 0; 03780 } 03781 03782 03783 void delete_elements(I_List<NAMED_LIST> *list, 03784 void (*free_element)(const char *name, gptr)) 03785 { 03786 NAMED_LIST *element; 03787 DBUG_ENTER("delete_elements"); 03788 while ((element= list->get())) 03789 { 03790 (*free_element)(element->name, element->data); 03791 delete element; 03792 } 03793 DBUG_VOID_RETURN; 03794 } 03795 03796 03797 /* Key cache functions */ 03798 03799 static KEY_CACHE *create_key_cache(const char *name, uint length) 03800 { 03801 KEY_CACHE *key_cache; 03802 DBUG_ENTER("create_key_cache"); 03803 DBUG_PRINT("enter",("name: %.*s", length, name)); 03804 03805 if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE), 03806 MYF(MY_ZEROFILL | MY_WME)))) 03807 { 03808 if (!new NAMED_LIST(&key_caches, name, length, (gptr) key_cache)) 03809 { 03810 my_free((char*) key_cache, MYF(0)); 03811 key_cache= 0; 03812 } 03813 else 03814 { 03815 /* 03816 Set default values for a key cache 03817 The values in dflt_key_cache_var is set by my_getopt() at startup 03818 03819 We don't set 'buff_size' as this is used to enable the key cache 03820 */ 03821 key_cache->param_block_size= dflt_key_cache_var.param_block_size; 03822 key_cache->param_division_limit= dflt_key_cache_var.param_division_limit; 03823 key_cache->param_age_threshold= dflt_key_cache_var.param_age_threshold; 03824 } 03825 } 03826 DBUG_RETURN(key_cache); 03827 } 03828 03829 03830 KEY_CACHE *get_or_create_key_cache(const char *name, uint length) 03831 { 03832 LEX_STRING key_cache_name; 03833 KEY_CACHE *key_cache; 03834 03835 key_cache_name.str= (char *) name; 03836 key_cache_name.length= length; 03837 pthread_mutex_lock(&LOCK_global_system_variables); 03838 if (!(key_cache= get_key_cache(&key_cache_name))) 03839 key_cache= create_key_cache(name, length); 03840 pthread_mutex_unlock(&LOCK_global_system_variables); 03841 return key_cache; 03842 } 03843 03844 03845 void free_key_cache(const char *name, KEY_CACHE *key_cache) 03846 { 03847 ha_end_key_cache(key_cache); 03848 my_free((char*) key_cache, MYF(0)); 03849 } 03850 03851 03852 bool process_key_caches(int (* func) (const char *name, KEY_CACHE *)) 03853 { 03854 I_List_iterator<NAMED_LIST> it(key_caches); 03855 NAMED_LIST *element; 03856 03857 while ((element= it++)) 03858 { 03859 KEY_CACHE *key_cache= (KEY_CACHE *) element->data; 03860 func(element->name, key_cache); 03861 } 03862 return 0; 03863 } 03864 03865 03866 void sys_var_trust_routine_creators::warn_deprecated(THD *thd) 03867 { 03868 WARN_DEPRECATED(thd, "5.2", "log_bin_trust_routine_creators", 03869 "'log_bin_trust_function_creators'"); 03870 } 03871 03872 void sys_var_trust_routine_creators::set_default(THD *thd, enum_var_type type) 03873 { 03874 warn_deprecated(thd); 03875 sys_var_bool_ptr::set_default(thd, type); 03876 } 03877 03878 bool sys_var_trust_routine_creators::update(THD *thd, set_var *var) 03879 { 03880 warn_deprecated(thd); 03881 return sys_var_bool_ptr::update(thd, var); 03882 } 03883 03884 /* even session variable here requires SUPER, because of -#o,file */ 03885 bool sys_var_thd_dbug::check(THD *thd, set_var *var) 03886 { 03887 return check_global_access(thd, SUPER_ACL); 03888 } 03889 03890 bool sys_var_thd_dbug::update(THD *thd, set_var *var) 03891 { 03892 if (var->type == OPT_GLOBAL) 03893 DBUG_SET_INITIAL(var ? var->value->str_value.c_ptr() : ""); 03894 else 03895 { 03896 DBUG_POP(); 03897 DBUG_PUSH(var ? var->value->str_value.c_ptr() : ""); 03898 } 03899 return 0; 03900 } 03901 03902 byte *sys_var_thd_dbug::value_ptr(THD *thd, enum_var_type type, LEX_STRING *b) 03903 { 03904 char buf[256]; 03905 if (type == OPT_GLOBAL) 03906 DBUG_EXPLAIN_INITIAL(buf, sizeof(buf)); 03907 else 03908 DBUG_EXPLAIN(buf, sizeof(buf)); 03909 return (byte*) thd->strdup(buf); 03910 } 03911 03912 03913 /* 03914 The update method of the global variable event_scheduler. 03915 If event_scheduler is switched from 0 to 1 then the scheduler main 03916 thread is resumed and if from 1 to 0 the scheduler thread is suspended 03917 03918 SYNOPSIS 03919 sys_var_event_scheduler::update() 03920 thd Thread context (unused) 03921 var The new value 03922 03923 Returns 03924 FALSE OK 03925 TRUE Error 03926 */ 03927 03928 bool 03929 sys_var_event_scheduler::update(THD *thd, set_var *var) 03930 { 03931 enum Event_scheduler::enum_error_code res; 03932 Event_scheduler *scheduler= Event_scheduler::get_instance(); 03933 /* here start the thread if not running. */ 03934 DBUG_ENTER("sys_var_event_scheduler::update"); 03935 03936 DBUG_PRINT("new_value", ("%lu", (bool)var->save_result.ulong_value)); 03937 if (!scheduler->initialized()) 03938 { 03939 my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--event-scheduler=0"); 03940 DBUG_RETURN(true); 03941 } 03942 03943 if (var->save_result.ulonglong_value < 1 || 03944 var->save_result.ulonglong_value > 2) 03945 { 03946 char buf[64]; 03947 my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "event_scheduler", 03948 llstr(var->save_result.ulonglong_value, buf)); 03949 DBUG_RETURN(true); 03950 } 03951 if ((res= scheduler->suspend_or_resume(var->save_result.ulonglong_value == 1? 03952 Event_scheduler::RESUME : 03953 Event_scheduler::SUSPEND))) 03954 my_error(ER_EVENT_SET_VAR_ERROR, MYF(0), (uint) res); 03955 DBUG_RETURN((bool) res); 03956 } 03957 03958 03959 byte *sys_var_event_scheduler::value_ptr(THD *thd, enum_var_type type, 03960 LEX_STRING *base) 03961 { 03962 Event_scheduler *scheduler= Event_scheduler::get_instance(); 03963 03964 if (!scheduler->initialized()) 03965 thd->sys_var_tmp.long_value= 0; 03966 else if (scheduler->get_state() == Event_scheduler::RUNNING) 03967 thd->sys_var_tmp.long_value= 1; 03968 else 03969 thd->sys_var_tmp.long_value= 2; 03970 03971 return (byte*) &thd->sys_var_tmp; 03972 } 03973 03974 03975 /**************************************************************************** 03976 Used templates 03977 ****************************************************************************/ 03978 03979 #ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION 03980 template class List<set_var_base>; 03981 template class List_iterator_fast<set_var_base>; 03982 template class I_List_iterator<NAMED_LIST>; 03983 #endif
1.4.7

