16 #ifndef MYSQLD_INCLUDED
17 #define MYSQLD_INCLUDED
19 #include "my_global.h"
20 #include "sql_bitmap.h"
22 #include "mysql_com.h"
23 #include "my_atomic.h"
43 #ifndef CHARSET_INFO_DEFINED
54 #define TEST_PRINT_CACHED_TABLES 1
55 #define TEST_NO_KEY_GROUP 2
56 #define TEST_MIT_THREAD 4
57 #define TEST_BLOCKING 8
58 #define TEST_KEEP_TMP_TABLES 16
59 #define TEST_READCHECK 64
60 #define TEST_NO_EXTRA 128
61 #define TEST_CORE_ON_SIGNAL 256
62 #define TEST_NO_STACKTRACE 512
63 #define TEST_SIGINT 1024
64 #define TEST_SYNCHRONIZATION 2048
67 void kill_mysql(
void);
68 void close_connection(THD *thd, uint sql_errno= 0);
69 void handle_connection_in_main_thread(THD *thd);
70 void create_thread_to_handle_connection(THD *thd);
71 void destroy_thd(THD *thd);
72 bool one_thread_per_connection_end(THD *thd,
bool block_pthread);
73 void kill_blocked_pthreads();
74 void refresh_status(THD *thd);
75 bool is_secure_file_path(
char *path);
76 void dec_connection_count();
79 void set_remaining_args(
int argc,
char **argv);
80 int init_common_variables();
81 void my_init_signals();
82 bool gtid_server_init();
83 void gtid_server_cleanup();
85 extern "C" MYSQL_PLUGIN_IMPORT
CHARSET_INFO *system_charset_info;
86 extern MYSQL_PLUGIN_IMPORT
CHARSET_INFO *files_charset_info ;
87 extern MYSQL_PLUGIN_IMPORT
CHARSET_INFO *national_charset_info;
88 extern MYSQL_PLUGIN_IMPORT
CHARSET_INFO *table_alias_charset;
98 extern bool opt_large_files, server_id_supplied;
99 extern bool opt_update_log, opt_bin_log, opt_error_log;
100 extern my_bool opt_log, opt_slow_log, opt_log_raw;
101 extern my_bool opt_backup_history_log;
102 extern my_bool opt_backup_progress_log;
103 extern ulonglong log_output_options;
104 extern ulong log_backup_output_options;
105 extern my_bool opt_log_queries_not_using_indexes;
106 extern ulong opt_log_throttle_queries_not_using_indexes;
107 extern bool opt_disable_networking, opt_skip_show_db;
108 extern bool opt_skip_name_resolve;
109 extern bool opt_ignore_builtin_innodb;
110 extern my_bool opt_character_set_client_handshake;
111 extern bool volatile abort_loop;
112 extern bool in_bootstrap;
113 extern my_bool opt_bootstrap;
114 extern uint connection_count;
115 extern my_bool opt_safe_user_create;
116 extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
117 extern my_bool opt_slave_compressed_protocol, use_temp_pool;
118 extern ulong slave_exec_mode_options;
119 extern ulonglong slave_type_conversions_options;
120 extern my_bool read_only, opt_readonly;
121 extern my_bool lower_case_file_system;
122 extern ulonglong slave_rows_search_algorithms_options;
124 extern uint slave_rows_last_search_algorithm_used;
126 #ifndef EMBEDDED_LIBRARY
127 extern "C" int check_enough_stack_size(
int);
129 extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
130 extern my_bool opt_secure_auth;
131 extern char* opt_secure_file_priv;
132 extern char* opt_secure_backup_file_priv;
133 extern size_t opt_secure_backup_file_priv_len;
134 extern my_bool opt_log_slow_admin_statements, opt_log_slow_slave_statements;
135 extern my_bool sp_automatic_privileges, opt_noacl;
136 extern my_bool opt_old_style_user_limits, trust_function_creators;
137 extern uint opt_crash_binlog_innodb;
138 extern char *shared_memory_base_name, *mysqld_unix_port;
139 extern my_bool opt_enable_shared_memory;
140 extern char *default_tz_name;
142 extern char *default_storage_engine;
143 extern char *default_tmp_storage_engine;
144 extern bool opt_endinfo, using_udf_functions;
145 extern my_bool locked_in_memory;
146 extern bool opt_using_transactions;
147 extern ulong max_long_data_size;
148 extern ulong current_pid;
149 extern ulong expire_logs_days;
150 extern my_bool relay_log_recovery;
151 extern uint sync_binlog_period, sync_relaylog_period,
152 sync_relayloginfo_period, sync_masterinfo_period,
153 opt_mts_checkpoint_period, opt_mts_checkpoint_group;
154 extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
155 extern ulong tc_log_page_waits;
156 extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;
157 extern my_bool relay_log_recovery;
158 extern uint test_flags,select_errors,ha_open_options;
159 extern uint protocol_version, mysqld_port, dropping_tables;
160 extern ulong delay_key_write_options;
161 extern char *opt_logname, *opt_slow_logname, *opt_bin_logname,
163 extern char *opt_backup_history_logname, *opt_backup_progress_logname,
164 *opt_backup_settings_name;
165 extern const char *log_output_str;
166 extern const char *log_backup_output_str;
167 extern char *mysql_home_ptr, *pidfile_name_ptr;
168 extern char *my_bind_addr_str;
169 extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
170 extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
171 extern char default_logfile_name[FN_REFLEN];
172 extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
174 #define UUID_LENGTH (8+1+4+1+4+1+4+1+12)
175 extern char server_uuid[UUID_LENGTH+1];
176 extern const char *server_uuid_ptr;
177 extern const double log_10[309];
178 extern ulonglong keybuff_size;
179 extern ulonglong thd_startup_options;
180 extern ulong thread_id;
181 extern ulong binlog_cache_use, binlog_cache_disk_use;
182 extern ulong binlog_stmt_cache_use, binlog_stmt_cache_disk_use;
183 extern ulong aborted_threads,aborted_connects;
184 extern ulong delayed_insert_timeout;
185 extern ulong delayed_insert_limit, delayed_queue_size;
186 extern ulong delayed_insert_threads, delayed_insert_writes;
187 extern ulong delayed_rows_in_use,delayed_insert_errors;
188 extern int32 slave_open_temp_tables;
189 extern ulong query_cache_size, query_cache_min_res_unit;
190 extern ulong slow_launch_threads, slow_launch_time;
191 extern ulong table_cache_size, table_def_size;
192 extern ulong table_cache_size_per_instance, table_cache_instances;
193 extern MYSQL_PLUGIN_IMPORT ulong max_connections;
194 extern ulong max_connect_errors, connect_timeout;
195 extern my_bool opt_slave_allow_batching;
196 extern my_bool allow_slave_start;
198 extern ulong slave_trans_retries;
199 extern uint slave_net_timeout;
200 extern ulong opt_mts_slave_parallel_workers;
201 extern ulonglong opt_mts_pending_jobs_size_max;
202 extern uint max_user_connections;
203 extern ulong rpl_stop_slave_timeout;
204 extern my_bool log_bin_use_v1_row_events;
205 extern ulong what_to_log,flush_time;
206 extern ulong max_prepared_stmt_count, prepared_stmt_count;
207 extern ulong open_files_limit;
208 extern ulong binlog_cache_size, binlog_stmt_cache_size;
209 extern ulonglong max_binlog_cache_size, max_binlog_stmt_cache_size;
210 extern int32 opt_binlog_max_flush_queue_time;
211 extern ulong max_binlog_size, max_relay_log_size;
212 extern ulong slave_max_allowed_packet;
213 extern ulong opt_binlog_rows_event_max_size;
214 extern ulong binlog_checksum_options;
215 extern const char *binlog_checksum_type_names[];
216 extern my_bool opt_master_verify_checksum;
217 extern my_bool opt_slave_sql_verify_checksum;
218 extern my_bool enforce_gtid_consistency;
224 GTID_MODE_UPGRADE_STEP_1= 1,
226 GTID_MODE_UPGRADE_STEP_2= 2,
230 extern ulong gtid_mode;
231 extern const char *gtid_mode_names[];
232 extern TYPELIB gtid_mode_typelib;
234 extern ulong max_blocked_pthreads;
235 extern ulong stored_program_cache_size;
236 extern ulong back_log;
237 extern char language[FN_REFLEN];
238 extern "C" MYSQL_PLUGIN_IMPORT ulong server_id;
239 extern ulong concurrency;
240 extern time_t server_start_time, flush_status_time;
241 extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
242 extern int mysql_unpacked_real_data_home_len;
243 extern MYSQL_PLUGIN_IMPORT
MY_TMPDIR mysql_tmpdir_list;
244 extern const char *first_keyword, *delayed_user, *binary_keyword;
245 extern MYSQL_PLUGIN_IMPORT
const char *my_localhost;
246 extern MYSQL_PLUGIN_IMPORT
const char **errmesg;
247 extern const char *myisam_recover_options_str;
248 extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
253 extern const char *opt_date_time_formats[];
257 extern uint opt_server_id_bits;
258 extern ulong opt_server_id_mask;
259 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
261 extern int(*ndb_wait_setup_func)(ulong);
262 extern ulong opt_ndb_wait_setup;
264 extern const char *load_default_groups[];
265 extern struct my_option my_long_options[];
266 extern struct my_option my_long_early_options[];
267 int handle_early_options();
268 void adjust_related_options(ulong *requested_open_files);
269 extern int mysqld_server_started;
270 extern "C" MYSQL_PLUGIN_IMPORT
int orig_argc;
271 extern "C" MYSQL_PLUGIN_IMPORT
char **orig_argv;
272 extern pthread_attr_t connection_attrib;
274 extern my_bool old_mode;
275 extern LEX_STRING opt_init_connect, opt_init_slave;
276 extern int bootstrap_error;
277 extern char err_shared_dir[];
278 extern TYPELIB thread_handling_typelib;
280 extern ulong connection_errors_select;
281 extern ulong connection_errors_accept;
282 extern ulong connection_errors_tcpwrap;
283 extern ulong connection_errors_internal;
284 extern ulong connection_errors_max_connection;
285 extern ulong connection_errors_peer_addr;
286 extern ulong log_warnings;
287 void init_sql_statement_names();
295 #ifdef HAVE_PSI_INTERFACE
297 extern PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active,
302 extern PSI_mutex_key key_LOCK_des_key_file;
305 extern PSI_mutex_key key_BINLOG_LOCK_commit;
306 extern PSI_mutex_key key_BINLOG_LOCK_commit_queue;
307 extern PSI_mutex_key key_BINLOG_LOCK_done;
308 extern PSI_mutex_key key_BINLOG_LOCK_flush_queue;
309 extern PSI_mutex_key key_BINLOG_LOCK_index;
310 extern PSI_mutex_key key_BINLOG_LOCK_log;
311 extern PSI_mutex_key key_BINLOG_LOCK_sync;
312 extern PSI_mutex_key key_BINLOG_LOCK_sync_queue;
313 extern PSI_mutex_key key_BINLOG_LOCK_xids;
315 key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi,
316 key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create,
317 key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log,
318 key_LOCK_gdl, key_LOCK_global_system_variables,
319 key_LOCK_lock_db, key_LOCK_logger, key_LOCK_manager,
320 key_LOCK_prepared_stmt_count,
321 key_LOCK_sql_slave_skip_counter,
322 key_LOCK_slave_net_timeout,
323 key_LOCK_server_started, key_LOCK_status,
324 key_LOCK_table_share, key_LOCK_thd_data,
325 key_LOCK_user_conn, key_LOCK_uuid_generator, key_LOG_LOCK_log,
326 key_master_info_data_lock, key_master_info_run_lock,
327 key_master_info_sleep_lock,
328 key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock,
329 key_relay_log_info_sleep_lock,
330 key_relay_log_info_log_space_lock, key_relay_log_info_run_lock,
331 key_mutex_slave_parallel_pend_jobs, key_mutex_mts_temp_tables_lock,
332 key_mutex_slave_parallel_worker,
333 key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data,
334 key_LOCK_error_messages, key_LOCK_thread_count,
335 key_LOCK_log_throttle_qni;
336 extern PSI_mutex_key key_RELAYLOG_LOCK_commit;
337 extern PSI_mutex_key key_RELAYLOG_LOCK_commit_queue;
338 extern PSI_mutex_key key_RELAYLOG_LOCK_done;
339 extern PSI_mutex_key key_RELAYLOG_LOCK_flush_queue;
340 extern PSI_mutex_key key_RELAYLOG_LOCK_index;
341 extern PSI_mutex_key key_RELAYLOG_LOCK_log;
342 extern PSI_mutex_key key_RELAYLOG_LOCK_sync;
343 extern PSI_mutex_key key_RELAYLOG_LOCK_sync_queue;
344 extern PSI_mutex_key key_RELAYLOG_LOCK_xids;
345 extern PSI_mutex_key key_LOCK_sql_rand;
346 extern PSI_mutex_key key_gtid_ensure_index_mutex;
347 extern PSI_mutex_key key_LOCK_thread_created;
349 extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,
350 key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave,
351 key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock,
352 key_rwlock_global_sid_lock;
355 extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool;
358 extern PSI_cond_key key_BINLOG_update_cond,
359 key_COND_cache_status_changed, key_COND_manager,
360 key_COND_server_started,
361 key_delayed_insert_cond, key_delayed_insert_cond_client,
362 key_item_func_sleep_cond, key_master_info_data_cond,
363 key_master_info_start_cond, key_master_info_stop_cond,
364 key_master_info_sleep_cond,
365 key_relay_log_info_data_cond, key_relay_log_info_log_space_cond,
366 key_relay_log_info_start_cond, key_relay_log_info_stop_cond,
367 key_relay_log_info_sleep_cond, key_cond_slave_parallel_pend_jobs,
368 key_cond_slave_parallel_worker,
369 key_TABLE_SHARE_cond, key_user_level_lock_cond,
370 key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache;
371 extern PSI_cond_key key_BINLOG_COND_done;
372 extern PSI_cond_key key_RELAYLOG_COND_done;
373 extern PSI_cond_key key_RELAYLOG_update_cond;
374 extern PSI_cond_key key_BINLOG_prep_xids_cond;
375 extern PSI_cond_key key_RELAYLOG_prep_xids_cond;
376 extern PSI_cond_key key_gtid_ensure_index_cond;
378 extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert,
379 key_thread_handle_manager, key_thread_kill_server, key_thread_main,
380 key_thread_one_connection, key_thread_signal_hand;
383 extern PSI_file_key key_file_map;
386 extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest,
387 key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file,
388 key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load,
389 key_file_loadfile, key_file_log_event_data, key_file_log_event_info,
390 key_file_master_info, key_file_misc, key_file_partition,
391 key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog,
392 key_file_trg, key_file_trn, key_file_init;
393 extern PSI_file_key key_file_query_log, key_file_slow_log;
394 extern PSI_file_key key_file_relaylog, key_file_relaylog_index;
395 extern PSI_socket_key key_socket_tcpip, key_socket_unix, key_socket_client_connection;
397 void init_server_psi_keys();
432 extern PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog;
433 extern PSI_stage_info stage_flushing_relay_log_and_master_info_repository;
441 extern PSI_stage_info stage_invalidating_query_cache_entries_table;
442 extern PSI_stage_info stage_invalidating_query_cache_entries_table_list;
445 extern PSI_stage_info stage_making_temp_file_append_before_load_data;
446 extern PSI_stage_info stage_making_temp_file_create_before_load_data;
454 extern PSI_stage_info stage_queueing_master_event_to_the_relay_log;
486 extern PSI_stage_info stage_waiting_for_gtid_to_be_written_to_binary_log;
498 extern PSI_stage_info stage_waiting_for_the_next_event_in_relay_log;
499 extern PSI_stage_info stage_waiting_for_the_slave_thread_to_advance_position;
502 extern PSI_stage_info stage_slave_waiting_worker_to_release_partition;
507 #ifdef HAVE_PSI_STATEMENT_INTERFACE
512 extern PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1];
518 extern PSI_statement_info com_statement_info[(uint) COM_END + 1];
523 extern PSI_statement_info stmt_info_rpl;
525 void init_sql_statement_info();
526 void init_com_statement_info();
530 extern pthread_t signal_thread;
534 extern struct st_VioSSLFd * ssl_acceptor_fd;
540 extern my_bool opt_large_pages;
541 extern uint opt_large_page_size;
542 extern char lc_messages_dir[FN_REFLEN];
543 extern char *lc_messages_dir_ptr, *log_error_file_ptr;
544 extern MYSQL_PLUGIN_IMPORT
char reg_ext[FN_EXTLEN];
545 extern MYSQL_PLUGIN_IMPORT uint reg_ext_length;
546 extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names;
547 extern MYSQL_PLUGIN_IMPORT
bool mysqld_embedded;
548 extern ulong specialflag;
549 extern uint mysql_data_home_len;
550 extern uint mysql_real_data_home_len;
551 extern const char *mysql_real_data_home_ptr;
552 extern ulong thread_handling;
553 extern MYSQL_PLUGIN_IMPORT
char *mysql_data_home;
554 extern "C" MYSQL_PLUGIN_IMPORT
char server_version[SERVER_VERSION_LENGTH];
555 extern MYSQL_PLUGIN_IMPORT
char mysql_real_data_home[];
556 extern char mysql_unpacked_real_data_home[];
558 extern char default_logfile_name[FN_REFLEN];
560 #define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
562 extern MYSQL_PLUGIN_IMPORT
const key_map key_map_empty;
563 extern MYSQL_PLUGIN_IMPORT
key_map key_map_full;
569 LOCK_user_locks, LOCK_status,
570 LOCK_error_log, LOCK_delayed_insert, LOCK_uuid_generator,
571 LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
572 LOCK_slave_list, LOCK_active_mi, LOCK_manager,
573 LOCK_global_system_variables, LOCK_user_conn, LOCK_log_throttle_qni,
574 LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count,
575 LOCK_sql_slave_skip_counter, LOCK_slave_net_timeout;
581 extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
584 extern int32 thread_running;
589 extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher,
590 *opt_ssl_key, *opt_ssl_crl, *opt_ssl_crlpath;
592 extern MYSQL_PLUGIN_IMPORT
pthread_key(THD*, THR_THD);
600 OPT_to_set_the_start_number=256,
605 OPT_BINLOG_IGNORE_DB,
609 OPT_DEBUG_SYNC_TIMEOUT,
610 OPT_DELAY_KEY_WRITE_ALL,
612 OPT_IGNORE_DB_DIRECTORY,
614 OPT_KEY_CACHE_AGE_THRESHOLD,
615 OPT_KEY_CACHE_BLOCK_SIZE,
616 OPT_KEY_CACHE_DIVISION_LIMIT,
617 OPT_LC_MESSAGES_DIRECTORY,
618 OPT_LOWER_CASE_TABLE_NAMES,
619 OPT_MASTER_RETRY_COUNT,
620 OPT_MASTER_VERIFY_CHECKSUM,
623 OPT_REPLICATE_DO_TABLE,
624 OPT_REPLICATE_IGNORE_DB,
625 OPT_REPLICATE_IGNORE_TABLE,
626 OPT_REPLICATE_REWRITE_DB,
627 OPT_REPLICATE_WILD_DO_TABLE,
628 OPT_REPLICATE_WILD_IGNORE_TABLE,
634 OPT_SKIP_STACK_TRACE,
636 OPT_SLAVE_SQL_VERIFY_CHECKSUM,
644 OPT_ENGINE_CONDITION_PUSHDOWN,
646 OPT_MAX_LONG_DATA_SIZE,
654 OPT_THREAD_CACHE_SIZE,
656 OPT_TABLE_DEFINITION_CACHE
668 QT_TO_SYSTEM_CHARSET= (1 << 0),
670 QT_WITHOUT_INTRODUCERS= (1 << 1),
672 QT_SHOW_SELECT_NUMBER= (1 << 2),
674 QT_NO_DEFAULT_DB= (1 << 3),
676 QT_DERIVED_TABLE_ONLY_ALIAS= (1 << 4)
680 typedef int64 query_id_t;
681 extern query_id_t global_query_id;
684 void unireg_end(
void) __attribute__((noreturn));
687 inline __attribute__((warn_unused_result)) query_id_t next_query_id()
690 my_atomic_rwlock_wrlock(&global_query_id_lock);
691 id= my_atomic_add64(&global_query_id, 1);
692 my_atomic_rwlock_wrunlock(&global_query_id_lock);
699 #ifndef EMBEDDED_LIBRARY
700 extern "C" void unireg_abort(
int exit_code) __attribute__((noreturn));
702 extern "C" void unireg_clear(
int exit_code);
703 #define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0)
706 inline void table_case_convert(
char *
name, uint length)
708 if (lower_case_table_names)
709 files_charset_info->cset->casedn(files_charset_info,
710 name, length, name, length);
713 ulong sql_rnd_with_mutex();
715 extern int32 num_thread_running;
720 my_atomic_rwlock_wrlock(&thread_running_lock);
721 num_threads= my_atomic_add32(&num_thread_running, 1);
722 my_atomic_rwlock_wrunlock(&thread_running_lock);
723 return (num_threads+1);
730 my_atomic_rwlock_wrlock(&thread_running_lock);
731 num_threads= my_atomic_add32(&num_thread_running, -1);
732 my_atomic_rwlock_wrunlock(&thread_running_lock);
733 return (num_threads-1);
736 #if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
737 extern "C" THD *_current_thd_noinline();
738 #define _current_thd() _current_thd_noinline()
745 inline THD *_current_thd(
void)
747 return my_pthread_getspecific_ptr(THD*,THR_THD);
750 #define current_thd _current_thd()
752 extern const char *MY_BIND_ALL_ADDRESSES;