MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mysqld.h
1 /* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef MYSQLD_INCLUDED
17 #define MYSQLD_INCLUDED
18 
19 #include "my_global.h" /* MYSQL_PLUGIN_IMPORT, FN_REFLEN, FN_EXTLEN */
20 #include "sql_bitmap.h" /* Bitmap */
21 #include "my_decimal.h" /* my_decimal */
22 #include "mysql_com.h" /* SERVER_VERSION_LENGTH */
23 #include "my_atomic.h" /* my_atomic_rwlock_t */
24 #include "mysql/psi/mysql_file.h" /* MYSQL_FILE */
25 #include "sql_list.h" /* I_List */
26 #include "sql_cmd.h" /* SQLCOM_END */
27 
28 class THD;
29 struct handlerton;
30 class Time_zone;
31 
32 struct scheduler_functions;
33 
35 typedef struct st_mysql_show_var SHOW_VAR;
36 
37 /*
38  This forward declaration is used from C files where the real
39  definition is included before. Since C does not allow repeated
40  typedef declarations, even when identical, the definition may not be
41  repeated.
42 */
43 #ifndef CHARSET_INFO_DEFINED
44 typedef struct charset_info_st CHARSET_INFO;
45 #endif /* CHARSET_INFO_DEFINED */
46 
47 #if MAX_INDEXES <= 64
48 typedef Bitmap<64> key_map; /* Used for finding keys */
49 #else
50 typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
51 #endif
52 
53  /* Bits from testflag */
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
66 /* Function prototypes */
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();
77 
78 // These are needed for unit testing.
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();
84 
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;
89 
93 extern CHARSET_INFO *error_message_charset_info;
94 
95 extern CHARSET_INFO *character_set_filesystem;
96 
97 extern MY_BITMAP temp_pool;
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;
123 #ifndef DBUG_OFF
124 extern uint slave_rows_last_search_algorithm_used;
125 #endif
126 #ifndef EMBEDDED_LIBRARY
127 extern "C" int check_enough_stack_size(int);
128 #endif
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;
141 extern Time_zone *default_tz;
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,
162  *opt_relay_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;
173 /*Move UUID_LENGTH from item_strfunc.h*/
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;
197 extern LEX_CSTRING reason_slave_blocked;
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;
219 enum enum_gtid_mode
220 {
222  GTID_MODE_OFF= 0,
224  GTID_MODE_UPGRADE_STEP_1= 1,
226  GTID_MODE_UPGRADE_STEP_2= 2,
228  GTID_MODE_ON= 3
229 };
230 extern ulong gtid_mode;
231 extern const char *gtid_mode_names[];
232 extern TYPELIB gtid_mode_typelib;
233 
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; /* Error messages */
247 extern const char *myisam_recover_options_str;
248 extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
249 extern SHOW_VAR status_vars[];
250 extern struct system_variables max_system_variables;
251 extern struct system_status_var global_status_var;
252 extern struct rand_struct sql_rand;
253 extern const char *opt_date_time_formats[];
254 extern handlerton *partition_hton;
255 extern handlerton *myisam_hton;
256 extern handlerton *heap_hton;
257 extern uint opt_server_id_bits;
258 extern ulong opt_server_id_mask;
259 #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
260 /* engine specific hook, to be made generic */
261 extern int(*ndb_wait_setup_func)(ulong);
262 extern ulong opt_ndb_wait_setup;
263 #endif
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;
273 extern MYSQL_FILE *bootstrap_file;
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;
279 extern my_decimal decimal_zero;
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();
288 
289 /*
290  THR_MALLOC is a key which will be used to set/get MEM_ROOT** for a thread,
291  using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
292 */
293 extern pthread_key(MEM_ROOT**,THR_MALLOC);
294 
295 #ifdef HAVE_PSI_INTERFACE
296 #ifdef HAVE_MMAP
297 extern PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active,
298  key_LOCK_pool;
299 #endif /* HAVE_MMAP */
300 
301 #ifdef HAVE_OPENSSL
302 extern PSI_mutex_key key_LOCK_des_key_file;
303 #endif
304 
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;
314 extern PSI_mutex_key
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;
348 
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;
353 
354 #ifdef HAVE_MMAP
355 extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool;
356 #endif /* HAVE_MMAP */
357 
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;
377 
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;
381 
382 #ifdef HAVE_MMAP
383 extern PSI_file_key key_file_map;
384 #endif /* HAVE_MMAP */
385 
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;
396 
397 void init_server_psi_keys();
398 #endif /* HAVE_PSI_INTERFACE */
399 
400 /*
401  MAINTAINER: Please keep this list in order, to limit merge collisions.
402  Hint: grep PSI_stage_info | sort -u
403 */
404 extern PSI_stage_info stage_after_create;
405 extern PSI_stage_info stage_allocating_local_table;
406 extern PSI_stage_info stage_alter_inplace_prepare;
407 extern PSI_stage_info stage_alter_inplace;
408 extern PSI_stage_info stage_alter_inplace_commit;
409 extern PSI_stage_info stage_changing_master;
410 extern PSI_stage_info stage_checking_master_version;
411 extern PSI_stage_info stage_checking_permissions;
412 extern PSI_stage_info stage_checking_privileges_on_cached_query;
413 extern PSI_stage_info stage_checking_query_cache_for_query;
414 extern PSI_stage_info stage_cleaning_up;
415 extern PSI_stage_info stage_closing_tables;
416 extern PSI_stage_info stage_connecting_to_master;
417 extern PSI_stage_info stage_converting_heap_to_myisam;
418 extern PSI_stage_info stage_copying_to_group_table;
419 extern PSI_stage_info stage_copying_to_tmp_table;
420 extern PSI_stage_info stage_copy_to_tmp_table;
421 extern PSI_stage_info stage_creating_delayed_handler;
422 extern PSI_stage_info stage_creating_sort_index;
423 extern PSI_stage_info stage_creating_table;
424 extern PSI_stage_info stage_creating_tmp_table;
425 extern PSI_stage_info stage_deleting_from_main_table;
426 extern PSI_stage_info stage_deleting_from_reference_tables;
427 extern PSI_stage_info stage_discard_or_import_tablespace;
428 extern PSI_stage_info stage_end;
429 extern PSI_stage_info stage_executing;
430 extern PSI_stage_info stage_execution_of_init_command;
431 extern PSI_stage_info stage_explaining;
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;
434 extern PSI_stage_info stage_flushing_relay_log_info_file;
435 extern PSI_stage_info stage_freeing_items;
436 extern PSI_stage_info stage_fulltext_initialization;
437 extern PSI_stage_info stage_got_handler_lock;
438 extern PSI_stage_info stage_got_old_table;
439 extern PSI_stage_info stage_init;
440 extern PSI_stage_info stage_insert;
441 extern PSI_stage_info stage_invalidating_query_cache_entries_table;
442 extern PSI_stage_info stage_invalidating_query_cache_entries_table_list;
443 extern PSI_stage_info stage_killing_slave;
444 extern PSI_stage_info stage_logging_slow_query;
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;
447 extern PSI_stage_info stage_manage_keys;
448 extern PSI_stage_info stage_master_has_sent_all_binlog_to_slave;
449 extern PSI_stage_info stage_opening_tables;
450 extern PSI_stage_info stage_optimizing;
451 extern PSI_stage_info stage_preparing;
452 extern PSI_stage_info stage_purging_old_relay_logs;
453 extern PSI_stage_info stage_query_end;
454 extern PSI_stage_info stage_queueing_master_event_to_the_relay_log;
455 extern PSI_stage_info stage_reading_event_from_the_relay_log;
456 extern PSI_stage_info stage_registering_slave_on_master;
457 extern PSI_stage_info stage_removing_duplicates;
458 extern PSI_stage_info stage_removing_tmp_table;
459 extern PSI_stage_info stage_rename;
460 extern PSI_stage_info stage_rename_result_table;
461 extern PSI_stage_info stage_requesting_binlog_dump;
462 extern PSI_stage_info stage_reschedule;
463 extern PSI_stage_info stage_searching_rows_for_update;
464 extern PSI_stage_info stage_sending_binlog_event_to_slave;
465 extern PSI_stage_info stage_sending_cached_result_to_client;
466 extern PSI_stage_info stage_sending_data;
467 extern PSI_stage_info stage_setup;
468 extern PSI_stage_info stage_slave_has_read_all_relay_log;
469 extern PSI_stage_info stage_sorting_for_group;
470 extern PSI_stage_info stage_sorting_for_order;
471 extern PSI_stage_info stage_sorting_result;
472 extern PSI_stage_info stage_sql_thd_waiting_until_delay;
473 extern PSI_stage_info stage_statistics;
474 extern PSI_stage_info stage_storing_result_in_query_cache;
475 extern PSI_stage_info stage_storing_row_into_queue;
476 extern PSI_stage_info stage_system_lock;
477 extern PSI_stage_info stage_update;
478 extern PSI_stage_info stage_updating;
479 extern PSI_stage_info stage_updating_main_table;
480 extern PSI_stage_info stage_updating_reference_tables;
481 extern PSI_stage_info stage_upgrading_lock;
482 extern PSI_stage_info stage_user_lock;
483 extern PSI_stage_info stage_user_sleep;
484 extern PSI_stage_info stage_verifying_table;
485 extern PSI_stage_info stage_waiting_for_delay_list;
486 extern PSI_stage_info stage_waiting_for_gtid_to_be_written_to_binary_log;
487 extern PSI_stage_info stage_waiting_for_handler_insert;
488 extern PSI_stage_info stage_waiting_for_handler_lock;
489 extern PSI_stage_info stage_waiting_for_handler_open;
490 extern PSI_stage_info stage_waiting_for_insert;
491 extern PSI_stage_info stage_waiting_for_master_to_send_event;
492 extern PSI_stage_info stage_waiting_for_master_update;
493 extern PSI_stage_info stage_waiting_for_relay_log_space;
494 extern PSI_stage_info stage_waiting_for_slave_mutex_on_exit;
495 extern PSI_stage_info stage_waiting_for_slave_thread_to_start;
496 extern PSI_stage_info stage_waiting_for_query_cache_lock;
497 extern PSI_stage_info stage_waiting_for_table_flush;
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;
500 extern PSI_stage_info stage_waiting_to_finalize_termination;
501 extern PSI_stage_info stage_waiting_to_get_readlock;
502 extern PSI_stage_info stage_slave_waiting_worker_to_release_partition;
503 extern PSI_stage_info stage_slave_waiting_worker_to_free_events;
504 extern PSI_stage_info stage_slave_waiting_worker_queue;
505 extern PSI_stage_info stage_slave_waiting_event_from_coordinator;
506 extern PSI_stage_info stage_slave_waiting_workers_to_exit;
507 #ifdef HAVE_PSI_STATEMENT_INTERFACE
508 
512 extern PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1];
513 
518 extern PSI_statement_info com_statement_info[(uint) COM_END + 1];
519 
523 extern PSI_statement_info stmt_info_rpl;
524 
525 void init_sql_statement_info();
526 void init_com_statement_info();
527 #endif /* HAVE_PSI_STATEMENT_INTERFACE */
528 
529 #ifndef __WIN__
530 extern pthread_t signal_thread;
531 #endif
532 
533 #ifdef HAVE_OPENSSL
534 extern struct st_VioSSLFd * ssl_acceptor_fd;
535 #endif /* HAVE_OPENSSL */
536 
537 /*
538  The following variables were under INNODB_COMPABILITY_HOOKS
539  */
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[];
557 extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables;
558 extern char default_logfile_name[FN_REFLEN];
559 
560 #define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
561 
562 extern MYSQL_PLUGIN_IMPORT const key_map key_map_empty;
563 extern MYSQL_PLUGIN_IMPORT key_map key_map_full; /* Should be threaded as const */
564 
565 /*
566  Server mutex locks and condition variables.
567  */
568 extern mysql_mutex_t
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;
576 #ifdef HAVE_OPENSSL
577 extern mysql_mutex_t LOCK_des_key_file;
578 #endif
579 extern mysql_mutex_t LOCK_server_started;
580 extern mysql_cond_t COND_server_started;
581 extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
582 extern mysql_rwlock_t LOCK_system_variables_hash;
583 extern mysql_cond_t COND_manager;
584 extern int32 thread_running;
585 extern my_atomic_rwlock_t thread_running_lock;
586 extern my_atomic_rwlock_t slave_open_temp_tables_lock;
587 extern my_atomic_rwlock_t opt_binlog_max_flush_queue_time_lock;
588 
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;
591 
592 extern MYSQL_PLUGIN_IMPORT pthread_key(THD*, THR_THD);
593 
598 enum options_mysqld
599 {
600  OPT_to_set_the_start_number=256,
601  OPT_BIND_ADDRESS,
602  OPT_BINLOG_CHECKSUM,
603  OPT_BINLOG_DO_DB,
604  OPT_BINLOG_FORMAT,
605  OPT_BINLOG_IGNORE_DB,
606  OPT_BIN_LOG,
607  OPT_BOOTSTRAP,
608  OPT_CONSOLE,
609  OPT_DEBUG_SYNC_TIMEOUT,
610  OPT_DELAY_KEY_WRITE_ALL,
611  OPT_ISAM_LOG,
612  OPT_IGNORE_DB_DIRECTORY,
613  OPT_KEY_BUFFER_SIZE,
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,
621  OPT_POOL_OF_THREADS,
622  OPT_REPLICATE_DO_DB,
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,
629  OPT_SERVER_ID,
630  OPT_SKIP_HOST_CACHE,
631  OPT_SKIP_LOCK,
632  OPT_SKIP_NEW,
633  OPT_SKIP_RESOLVE,
634  OPT_SKIP_STACK_TRACE,
635  OPT_SKIP_SYMLINKS,
636  OPT_SLAVE_SQL_VERIFY_CHECKSUM,
637  OPT_SSL_CA,
638  OPT_SSL_CAPATH,
639  OPT_SSL_CERT,
640  OPT_SSL_CIPHER,
641  OPT_SSL_KEY,
642  OPT_UPDATE_LOG,
643  OPT_WANT_CORE,
644  OPT_ENGINE_CONDITION_PUSHDOWN,
645  OPT_LOG_ERROR,
646  OPT_MAX_LONG_DATA_SIZE,
647  OPT_PLUGIN_LOAD,
648  OPT_PLUGIN_LOAD_ADD,
649  OPT_SSL_CRL,
650  OPT_SSL_CRLPATH,
651  OPT_PFS_INSTRUMENT,
652  OPT_DEFAULT_AUTH,
653  OPT_SECURE_AUTH,
654  OPT_THREAD_CACHE_SIZE,
655  OPT_HOST_CACHE_SIZE,
656  OPT_TABLE_DEFINITION_CACHE
657 };
658 
659 
663 enum enum_query_type
664 {
666  QT_ORDINARY= 0,
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)
677 };
678 
679 /* query_id */
680 typedef int64 query_id_t;
681 extern query_id_t global_query_id;
682 extern my_atomic_rwlock_t global_query_id_lock;
683 
684 void unireg_end(void) __attribute__((noreturn));
685 
686 /* increment query_id and return it. */
687 inline __attribute__((warn_unused_result)) query_id_t next_query_id()
688 {
689  query_id_t 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);
693  return (id+1);
694 }
695 
696 /*
697  TODO: Replace this with an inline function.
698  */
699 #ifndef EMBEDDED_LIBRARY
700 extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
701 #else
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)
704 #endif
705 
706 inline void table_case_convert(char * name, uint length)
707 {
708  if (lower_case_table_names)
709  files_charset_info->cset->casedn(files_charset_info,
710  name, length, name, length);
711 }
712 
713 ulong sql_rnd_with_mutex();
714 
715 extern int32 num_thread_running;
716 inline int32
717 inc_thread_running()
718 {
719  int32 num_threads;
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);
724 }
725 
726 inline int32
727 dec_thread_running()
728 {
729  int32 num_threads;
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);
734 }
735 
736 #if defined(MYSQL_DYNAMIC_PLUGIN) && defined(_WIN32)
737 extern "C" THD *_current_thd_noinline();
738 #define _current_thd() _current_thd_noinline()
739 #else
740 /*
741  THR_THD is a key which will be used to set/get THD* for a thread,
742  using my_pthread_setspecific_ptr()/my_thread_getspecific_ptr().
743 */
744 extern pthread_key(THD*, THR_THD);
745 inline THD *_current_thd(void)
746 {
747  return my_pthread_getspecific_ptr(THD*,THR_THD);
748 }
749 #endif
750 #define current_thd _current_thd()
751 
752 extern const char *MY_BIND_ALL_ADDRESSES;
753 
754 #endif /* MYSQLD_INCLUDED */