1/* Copyright (c) 2006, 2016, Oracle and/or its affiliates.
2 Copyright (c) 2010, 2017, MariaDB Corporation.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#ifndef MYSQLD_INCLUDED
18#define MYSQLD_INCLUDED
19
20#include "sql_basic_types.h" /* query_id_t */
21#include "sql_plugin.h"
22#include "sql_bitmap.h" /* Bitmap */
23#include "my_decimal.h" /* my_decimal */
24#include "mysql_com.h" /* SERVER_VERSION_LENGTH */
25#include "my_atomic.h"
26#include "mysql/psi/mysql_file.h" /* MYSQL_FILE */
27#include "sql_list.h" /* I_List */
28#include "sql_cmd.h"
29#include <my_rnd.h>
30#include "my_pthread.h"
31#include "my_rdtsc.h"
32
33class THD;
34class CONNECT;
35struct handlerton;
36class Time_zone;
37
38struct scheduler_functions;
39
40typedef struct st_mysql_show_var SHOW_VAR;
41
42#if MAX_INDEXES <= 64
43typedef Bitmap<64> key_map; /* Used for finding keys */
44#elif MAX_INDEXES > 128
45#error "MAX_INDEXES values greater than 128 is not supported."
46#else
47typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
48#endif
49
50 /* Bits from testflag */
51#define TEST_PRINT_CACHED_TABLES 1U
52#define TEST_NO_KEY_GROUP 2U
53#define TEST_MIT_THREAD 4U
54#define TEST_BLOCKING 8U
55#define TEST_KEEP_TMP_TABLES 16U
56#define TEST_READCHECK 64U /**< Force use of readcheck */
57#define TEST_NO_EXTRA 128U
58#define TEST_CORE_ON_SIGNAL 256U /**< Give core if signal */
59#define TEST_SIGINT 1024U /**< Allow sigint on threads */
60#define TEST_SYNCHRONIZATION 2048U /**< get server to do sleep in
61 some places */
62
63/* Keep things compatible */
64#define OPT_DEFAULT SHOW_OPT_DEFAULT
65#define OPT_SESSION SHOW_OPT_SESSION
66#define OPT_GLOBAL SHOW_OPT_GLOBAL
67
68extern MY_TIMER_INFO sys_timer_info;
69
70/*
71 Values for --slave-parallel-mode
72 Must match order in slave_parallel_mode_typelib in sys_vars.cc.
73*/
74enum enum_slave_parallel_mode {
75 SLAVE_PARALLEL_NONE,
76 SLAVE_PARALLEL_MINIMAL,
77 SLAVE_PARALLEL_CONSERVATIVE,
78 SLAVE_PARALLEL_OPTIMISTIC,
79 SLAVE_PARALLEL_AGGRESSIVE
80};
81
82/* Function prototypes */
83void kill_mysql(THD *thd= 0);
84void close_connection(THD *thd, uint sql_errno= 0);
85void handle_connection_in_main_thread(CONNECT *thd);
86void create_thread_to_handle_connection(CONNECT *connect);
87void signal_thd_deleted();
88void unlink_thd(THD *thd);
89bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
90void flush_thread_cache();
91void refresh_status(THD *thd);
92bool is_secure_file_path(char *path);
93void dec_connection_count(scheduler_functions *scheduler);
94extern void init_net_server_extension(THD *thd);
95
96extern "C" MYSQL_PLUGIN_IMPORT CHARSET_INFO *system_charset_info;
97extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *files_charset_info ;
98extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *national_charset_info;
99extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *table_alias_charset;
100
101/**
102 Character set of the buildin error messages loaded from errmsg.sys.
103*/
104extern CHARSET_INFO *error_message_charset_info;
105
106extern CHARSET_INFO *character_set_filesystem;
107
108extern MY_BITMAP temp_pool;
109extern bool opt_large_files;
110extern bool opt_update_log, opt_bin_log, opt_error_log, opt_bin_log_compress;
111extern uint opt_bin_log_compress_min_len;
112extern my_bool opt_log, opt_bootstrap;
113extern my_bool opt_backup_history_log;
114extern my_bool opt_backup_progress_log;
115extern my_bool opt_support_flashback;
116extern ulonglong log_output_options;
117extern ulong log_backup_output_options;
118extern bool opt_disable_networking, opt_skip_show_db;
119extern bool opt_skip_name_resolve;
120extern bool opt_ignore_builtin_innodb;
121extern my_bool opt_character_set_client_handshake;
122extern my_bool debug_assert_on_not_freed_memory;
123extern bool volatile abort_loop;
124extern bool volatile in_bootstrap;
125extern uint connection_count;
126extern my_bool opt_safe_user_create;
127extern my_bool opt_safe_show_db, opt_local_infile, opt_myisam_use_mmap;
128extern my_bool opt_slave_compressed_protocol, use_temp_pool;
129extern ulong slave_exec_mode_options, slave_ddl_exec_mode_options;
130extern ulong slave_retried_transactions;
131extern ulong transactions_multi_engine;
132extern ulong rpl_transactions_multi_engine;
133extern ulong transactions_gtid_foreign_engine;
134extern ulong slave_run_triggers_for_rbr;
135extern ulonglong slave_type_conversions_options;
136extern my_bool read_only, opt_readonly;
137extern MYSQL_PLUGIN_IMPORT my_bool lower_case_file_system;
138extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
139extern my_bool opt_secure_auth;
140extern const char *current_dbug_option;
141extern char* opt_secure_file_priv;
142extern char* opt_secure_backup_file_priv;
143extern size_t opt_secure_backup_file_priv_len;
144extern my_bool sp_automatic_privileges, opt_noacl;
145extern ulong use_stat_tables;
146extern my_bool opt_old_style_user_limits, trust_function_creators;
147extern uint opt_crash_binlog_innodb;
148extern const char *shared_memory_base_name;
149extern char *mysqld_unix_port;
150extern my_bool opt_enable_shared_memory;
151extern ulong opt_replicate_events_marked_for_skip;
152extern char *default_tz_name;
153extern Time_zone *default_tz;
154extern char *my_bind_addr_str;
155extern char *default_storage_engine, *default_tmp_storage_engine;
156extern char *enforced_storage_engine;
157extern char *gtid_pos_auto_engines;
158extern plugin_ref *opt_gtid_pos_auto_plugins;
159extern bool opt_endinfo, using_udf_functions;
160extern my_bool locked_in_memory;
161extern bool opt_using_transactions;
162extern ulong max_long_data_size;
163extern ulong current_pid;
164extern ulong expire_logs_days;
165extern my_bool relay_log_recovery;
166extern uint sync_binlog_period, sync_relaylog_period,
167 sync_relayloginfo_period, sync_masterinfo_period;
168extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
169extern ulong tc_log_page_waits;
170extern my_bool relay_log_purge, opt_innodb_safe_binlog, opt_innodb;
171extern my_bool relay_log_recovery;
172extern uint test_flags,select_errors,ha_open_options;
173extern uint protocol_version, mysqld_port, dropping_tables;
174extern ulong delay_key_write_options;
175extern char *opt_logname, *opt_slow_logname, *opt_bin_logname,
176 *opt_relay_logname;
177extern char *opt_backup_history_logname, *opt_backup_progress_logname,
178 *opt_backup_settings_name;
179extern const char *log_output_str;
180extern const char *log_backup_output_str;
181
182/* System Versioning begin */
183enum vers_system_time_t
184{
185 SYSTEM_TIME_UNSPECIFIED = 0,
186 SYSTEM_TIME_AS_OF,
187 SYSTEM_TIME_FROM_TO,
188 SYSTEM_TIME_BETWEEN,
189 SYSTEM_TIME_BEFORE,
190 SYSTEM_TIME_ALL
191};
192
193struct vers_asof_timestamp_t
194{
195 ulong type;
196 MYSQL_TIME ltime;
197 vers_asof_timestamp_t() :
198 type(SYSTEM_TIME_UNSPECIFIED)
199 {}
200};
201
202enum vers_alter_history_enum
203{
204 VERS_ALTER_HISTORY_ERROR= 0,
205 VERS_ALTER_HISTORY_KEEP
206};
207/* System Versioning end */
208
209extern char *mysql_home_ptr, *pidfile_name_ptr;
210extern MYSQL_PLUGIN_IMPORT char glob_hostname[FN_REFLEN];
211extern char mysql_home[FN_REFLEN];
212extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
213extern char default_logfile_name[FN_REFLEN];
214extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
215extern const double log_10[309];
216extern ulonglong keybuff_size;
217extern ulonglong thd_startup_options;
218extern my_thread_id global_thread_id;
219extern ulong binlog_cache_use, binlog_cache_disk_use;
220extern ulong binlog_stmt_cache_use, binlog_stmt_cache_disk_use;
221extern ulong aborted_threads,aborted_connects;
222extern ulong delayed_insert_timeout;
223extern ulong delayed_insert_limit, delayed_queue_size;
224extern ulong delayed_insert_threads, delayed_insert_writes;
225extern ulong delayed_rows_in_use,delayed_insert_errors;
226extern int32 slave_open_temp_tables;
227extern ulonglong query_cache_size;
228extern ulong query_cache_limit;
229extern ulong query_cache_min_res_unit;
230extern ulong slow_launch_threads, slow_launch_time;
231extern MYSQL_PLUGIN_IMPORT ulong max_connections;
232extern uint max_digest_length;
233extern ulong max_connect_errors, connect_timeout;
234extern my_bool slave_allow_batching;
235extern my_bool allow_slave_start;
236extern LEX_CSTRING reason_slave_blocked;
237extern ulong slave_trans_retries;
238extern ulong slave_trans_retry_interval;
239extern uint slave_net_timeout;
240extern int max_user_connections;
241extern volatile ulong cached_thread_count;
242extern ulong what_to_log,flush_time;
243extern uint max_prepared_stmt_count, prepared_stmt_count;
244extern MYSQL_PLUGIN_IMPORT ulong open_files_limit;
245extern ulonglong binlog_cache_size, binlog_stmt_cache_size, binlog_file_cache_size;
246extern ulonglong max_binlog_cache_size, max_binlog_stmt_cache_size;
247extern ulong max_binlog_size;
248extern ulong slave_max_allowed_packet;
249extern ulong opt_binlog_rows_event_max_size;
250extern ulong rpl_recovery_rank, thread_cache_size;
251extern ulong stored_program_cache_size;
252extern ulong opt_slave_parallel_threads;
253extern ulong opt_slave_domain_parallel_threads;
254extern ulong opt_slave_parallel_max_queued;
255extern ulong opt_slave_parallel_mode;
256extern ulong opt_binlog_commit_wait_count;
257extern ulong opt_binlog_commit_wait_usec;
258extern my_bool opt_gtid_ignore_duplicates;
259extern ulong back_log;
260extern ulong executed_events;
261extern char language[FN_REFLEN];
262extern "C" MYSQL_PLUGIN_IMPORT ulong server_id;
263extern ulong concurrency;
264extern time_t server_start_time, flush_status_time;
265extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
266extern size_t mysql_unpacked_real_data_home_len;
267extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list;
268extern const char *first_keyword, *delayed_user;
269extern MYSQL_PLUGIN_IMPORT const char *my_localhost;
270extern MYSQL_PLUGIN_IMPORT const char **errmesg; /* Error messages */
271extern const char *myisam_recover_options_str;
272extern const LEX_CSTRING in_left_expr_name, in_additional_cond, in_having_cond;
273extern SHOW_VAR status_vars[];
274extern struct system_variables max_system_variables;
275extern struct system_status_var global_status_var;
276extern struct my_rnd_struct sql_rand;
277extern const char *opt_date_time_formats[];
278extern handlerton *partition_hton;
279extern handlerton *myisam_hton;
280extern handlerton *heap_hton;
281extern const char *load_default_groups[];
282extern struct my_option my_long_options[];
283int handle_early_options();
284extern int mysqld_server_started, mysqld_server_initialized;
285extern "C" MYSQL_PLUGIN_IMPORT int orig_argc;
286extern "C" MYSQL_PLUGIN_IMPORT char **orig_argv;
287extern pthread_attr_t connection_attrib;
288extern MYSQL_FILE *bootstrap_file;
289extern my_bool old_mode;
290extern LEX_STRING opt_init_connect, opt_init_slave;
291extern int bootstrap_error;
292extern I_List<THD> threads;
293extern char err_shared_dir[];
294extern ulong connection_errors_select;
295extern ulong connection_errors_accept;
296extern ulong connection_errors_tcpwrap;
297extern ulong connection_errors_internal;
298extern ulong connection_errors_max_connection;
299extern ulong connection_errors_peer_addr;
300extern ulong log_warnings;
301extern my_bool encrypt_binlog;
302extern my_bool encrypt_tmp_disk_tables, encrypt_tmp_files;
303extern ulong encryption_algorithm;
304extern const char *encryption_algorithm_names[];
305extern long opt_secure_timestamp;
306
307enum secure_timestamp { SECTIME_NO, SECTIME_SUPER, SECTIME_REPL, SECTIME_YES };
308
309#ifdef HAVE_PSI_INTERFACE
310#ifdef HAVE_MMAP
311extern PSI_mutex_key key_PAGE_lock, key_LOCK_sync, key_LOCK_active,
312 key_LOCK_pool, key_LOCK_pending_checkpoint;
313#endif /* HAVE_MMAP */
314
315#ifdef HAVE_OPENSSL
316extern PSI_mutex_key key_LOCK_des_key_file;
317#endif
318
319extern PSI_mutex_key key_BINLOG_LOCK_index, key_BINLOG_LOCK_xid_list,
320 key_BINLOG_LOCK_binlog_background_thread,
321 key_LOCK_binlog_end_pos,
322 key_delayed_insert_mutex, key_hash_filo_lock, key_LOCK_active_mi,
323 key_LOCK_connection_count, key_LOCK_crypt, key_LOCK_delayed_create,
324 key_LOCK_delayed_insert, key_LOCK_delayed_status, key_LOCK_error_log,
325 key_LOCK_gdl, key_LOCK_global_system_variables,
326 key_LOCK_logger, key_LOCK_manager,
327 key_LOCK_prepared_stmt_count,
328 key_LOCK_rpl_status, key_LOCK_server_started,
329 key_LOCK_status, key_LOCK_show_status,
330 key_LOCK_thd_data, key_LOCK_thd_kill,
331 key_LOCK_user_conn, key_LOG_LOCK_log,
332 key_master_info_data_lock, key_master_info_run_lock,
333 key_master_info_sleep_lock, key_master_info_start_stop_lock,
334 key_mutex_slave_reporting_capability_err_lock, key_relay_log_info_data_lock,
335 key_relay_log_info_log_space_lock, key_relay_log_info_run_lock,
336 key_rpl_group_info_sleep_lock,
337 key_structure_guard_mutex, key_TABLE_SHARE_LOCK_ha_data,
338 key_LOCK_start_thread,
339 key_LOCK_error_messages, key_LOCK_thread_count, key_PARTITION_LOCK_auto_inc;
340extern PSI_mutex_key key_RELAYLOG_LOCK_index;
341extern PSI_mutex_key key_LOCK_relaylog_end_pos;
342extern PSI_mutex_key key_LOCK_slave_state, key_LOCK_binlog_state,
343 key_LOCK_rpl_thread, key_LOCK_rpl_thread_pool, key_LOCK_parallel_entry;
344
345extern PSI_mutex_key key_TABLE_SHARE_LOCK_share, key_LOCK_stats,
346 key_LOCK_global_user_client_stats, key_LOCK_global_table_stats,
347 key_LOCK_global_index_stats, key_LOCK_wakeup_ready, key_LOCK_wait_commit,
348 key_TABLE_SHARE_LOCK_rotation;
349extern PSI_mutex_key key_LOCK_gtid_waiting;
350
351extern PSI_rwlock_key key_rwlock_LOCK_grant, key_rwlock_LOCK_logger,
352 key_rwlock_LOCK_sys_init_connect, key_rwlock_LOCK_sys_init_slave,
353 key_rwlock_LOCK_system_variables_hash, key_rwlock_query_cache_query_lock,
354 key_LOCK_SEQUENCE,
355 key_rwlock_LOCK_vers_stats, key_rwlock_LOCK_stat_serial;
356
357#ifdef HAVE_MMAP
358extern PSI_cond_key key_PAGE_cond, key_COND_active, key_COND_pool;
359#endif /* HAVE_MMAP */
360
361extern PSI_cond_key key_BINLOG_COND_xid_list, key_BINLOG_update_cond,
362 key_BINLOG_COND_binlog_background_thread,
363 key_BINLOG_COND_binlog_background_thread_end,
364 key_COND_cache_status_changed, key_COND_manager,
365 key_COND_rpl_status, key_COND_server_started,
366 key_delayed_insert_cond, key_delayed_insert_cond_client,
367 key_item_func_sleep_cond, key_master_info_data_cond,
368 key_master_info_start_cond, key_master_info_stop_cond,
369 key_master_info_sleep_cond,
370 key_relay_log_info_data_cond, key_relay_log_info_log_space_cond,
371 key_relay_log_info_start_cond, key_relay_log_info_stop_cond,
372 key_rpl_group_info_sleep_cond,
373 key_TABLE_SHARE_cond, key_user_level_lock_cond,
374 key_COND_start_thread,
375 key_COND_thread_count, key_COND_thread_cache, key_COND_flush_thread_cache;
376extern PSI_cond_key key_RELAYLOG_COND_relay_log_updated,
377 key_RELAYLOG_COND_bin_log_updated, key_COND_wakeup_ready,
378 key_COND_wait_commit;
379extern PSI_cond_key key_RELAYLOG_COND_queue_busy;
380extern PSI_cond_key key_TC_LOG_MMAP_COND_queue_busy;
381extern PSI_cond_key key_COND_rpl_thread, key_COND_rpl_thread_queue,
382 key_COND_rpl_thread_stop, key_COND_rpl_thread_pool,
383 key_COND_parallel_entry, key_COND_group_commit_orderer;
384extern PSI_cond_key key_COND_wait_gtid, key_COND_gtid_ignore_duplicates;
385extern PSI_cond_key key_TABLE_SHARE_COND_rotation;
386
387extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert,
388 key_thread_handle_manager, key_thread_kill_server, key_thread_main,
389 key_thread_one_connection, key_thread_signal_hand,
390 key_thread_slave_background, key_rpl_parallel_thread;
391
392extern PSI_file_key key_file_binlog, key_file_binlog_index, key_file_casetest,
393 key_file_dbopt, key_file_des_key_file, key_file_ERRMSG, key_select_to_file,
394 key_file_fileparser, key_file_frm, key_file_global_ddl_log, key_file_load,
395 key_file_loadfile, key_file_log_event_data, key_file_log_event_info,
396 key_file_master_info, key_file_misc, key_file_partition,
397 key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog,
398 key_file_trg, key_file_trn, key_file_init;
399extern PSI_file_key key_file_query_log, key_file_slow_log;
400extern PSI_file_key key_file_relaylog, key_file_relaylog_index;
401extern PSI_socket_key key_socket_tcpip, key_socket_unix,
402 key_socket_client_connection;
403extern PSI_file_key key_file_binlog_state;
404
405void init_server_psi_keys();
406#endif /* HAVE_PSI_INTERFACE */
407
408/*
409 MAINTAINER: Please keep this list in order, to limit merge collisions.
410 Hint: grep PSI_stage_info | sort -u
411*/
412extern PSI_stage_info stage_apply_event;
413extern PSI_stage_info stage_after_create;
414extern PSI_stage_info stage_after_opening_tables;
415extern PSI_stage_info stage_after_table_lock;
416extern PSI_stage_info stage_allocating_local_table;
417extern PSI_stage_info stage_alter_inplace_prepare;
418extern PSI_stage_info stage_alter_inplace;
419extern PSI_stage_info stage_alter_inplace_commit;
420extern PSI_stage_info stage_after_apply_event;
421extern PSI_stage_info stage_changing_master;
422extern PSI_stage_info stage_checking_master_version;
423extern PSI_stage_info stage_checking_permissions;
424extern PSI_stage_info stage_checking_privileges_on_cached_query;
425extern PSI_stage_info stage_checking_query_cache_for_query;
426extern PSI_stage_info stage_cleaning_up;
427extern PSI_stage_info stage_closing_tables;
428extern PSI_stage_info stage_connecting_to_master;
429extern PSI_stage_info stage_converting_heap_to_myisam;
430extern PSI_stage_info stage_copying_to_group_table;
431extern PSI_stage_info stage_copying_to_tmp_table;
432extern PSI_stage_info stage_copy_to_tmp_table;
433extern PSI_stage_info stage_creating_delayed_handler;
434extern PSI_stage_info stage_creating_sort_index;
435extern PSI_stage_info stage_creating_table;
436extern PSI_stage_info stage_creating_tmp_table;
437extern PSI_stage_info stage_deleting_from_main_table;
438extern PSI_stage_info stage_deleting_from_reference_tables;
439extern PSI_stage_info stage_discard_or_import_tablespace;
440extern PSI_stage_info stage_end;
441extern PSI_stage_info stage_enabling_keys;
442extern PSI_stage_info stage_executing;
443extern PSI_stage_info stage_execution_of_init_command;
444extern PSI_stage_info stage_explaining;
445extern PSI_stage_info stage_finding_key_cache;
446extern PSI_stage_info stage_finished_reading_one_binlog_switching_to_next_binlog;
447extern PSI_stage_info stage_flushing_relay_log_and_master_info_repository;
448extern PSI_stage_info stage_flushing_relay_log_info_file;
449extern PSI_stage_info stage_freeing_items;
450extern PSI_stage_info stage_fulltext_initialization;
451extern PSI_stage_info stage_got_handler_lock;
452extern PSI_stage_info stage_got_old_table;
453extern PSI_stage_info stage_init;
454extern PSI_stage_info stage_init_update;
455extern PSI_stage_info stage_insert;
456extern PSI_stage_info stage_invalidating_query_cache_entries_table;
457extern PSI_stage_info stage_invalidating_query_cache_entries_table_list;
458extern PSI_stage_info stage_killing_slave;
459extern PSI_stage_info stage_logging_slow_query;
460extern PSI_stage_info stage_making_temp_file_append_before_load_data;
461extern PSI_stage_info stage_making_temp_file_create_before_load_data;
462extern PSI_stage_info stage_manage_keys;
463extern PSI_stage_info stage_master_has_sent_all_binlog_to_slave;
464extern PSI_stage_info stage_opening_tables;
465extern PSI_stage_info stage_optimizing;
466extern PSI_stage_info stage_preparing;
467extern PSI_stage_info stage_purging_old_relay_logs;
468extern PSI_stage_info stage_query_end;
469extern PSI_stage_info stage_starting_cleanup;
470extern PSI_stage_info stage_rollback;
471extern PSI_stage_info stage_rollback_implicit;
472extern PSI_stage_info stage_commit;
473extern PSI_stage_info stage_commit_implicit;
474extern PSI_stage_info stage_queueing_master_event_to_the_relay_log;
475extern PSI_stage_info stage_reading_event_from_the_relay_log;
476extern PSI_stage_info stage_recreating_table;
477extern PSI_stage_info stage_registering_slave_on_master;
478extern PSI_stage_info stage_removing_duplicates;
479extern PSI_stage_info stage_removing_tmp_table;
480extern PSI_stage_info stage_rename;
481extern PSI_stage_info stage_rename_result_table;
482extern PSI_stage_info stage_requesting_binlog_dump;
483extern PSI_stage_info stage_reschedule;
484extern PSI_stage_info stage_searching_rows_for_update;
485extern PSI_stage_info stage_sending_binlog_event_to_slave;
486extern PSI_stage_info stage_sending_cached_result_to_client;
487extern PSI_stage_info stage_sending_data;
488extern PSI_stage_info stage_setup;
489extern PSI_stage_info stage_slave_has_read_all_relay_log;
490extern PSI_stage_info stage_show_explain;
491extern PSI_stage_info stage_sorting;
492extern PSI_stage_info stage_sorting_for_group;
493extern PSI_stage_info stage_sorting_for_order;
494extern PSI_stage_info stage_sorting_result;
495extern PSI_stage_info stage_sql_thd_waiting_until_delay;
496extern PSI_stage_info stage_statistics;
497extern PSI_stage_info stage_storing_result_in_query_cache;
498extern PSI_stage_info stage_storing_row_into_queue;
499extern PSI_stage_info stage_system_lock;
500extern PSI_stage_info stage_unlocking_tables;
501extern PSI_stage_info stage_table_lock;
502extern PSI_stage_info stage_filling_schema_table;
503extern PSI_stage_info stage_update;
504extern PSI_stage_info stage_updating;
505extern PSI_stage_info stage_updating_main_table;
506extern PSI_stage_info stage_updating_reference_tables;
507extern PSI_stage_info stage_upgrading_lock;
508extern PSI_stage_info stage_user_lock;
509extern PSI_stage_info stage_user_sleep;
510extern PSI_stage_info stage_verifying_table;
511extern PSI_stage_info stage_waiting_for_delay_list;
512extern PSI_stage_info stage_waiting_for_gtid_to_be_written_to_binary_log;
513extern PSI_stage_info stage_waiting_for_handler_insert;
514extern PSI_stage_info stage_waiting_for_handler_lock;
515extern PSI_stage_info stage_waiting_for_handler_open;
516extern PSI_stage_info stage_waiting_for_insert;
517extern PSI_stage_info stage_waiting_for_master_to_send_event;
518extern PSI_stage_info stage_waiting_for_master_update;
519extern PSI_stage_info stage_waiting_for_relay_log_space;
520extern PSI_stage_info stage_waiting_for_slave_mutex_on_exit;
521extern PSI_stage_info stage_waiting_for_slave_thread_to_start;
522extern PSI_stage_info stage_waiting_for_query_cache_lock;
523extern PSI_stage_info stage_waiting_for_table_flush;
524extern PSI_stage_info stage_waiting_for_the_next_event_in_relay_log;
525extern PSI_stage_info stage_waiting_for_the_slave_thread_to_advance_position;
526extern PSI_stage_info stage_waiting_to_finalize_termination;
527extern PSI_stage_info stage_waiting_to_get_readlock;
528extern PSI_stage_info stage_binlog_waiting_background_tasks;
529extern PSI_stage_info stage_binlog_write;
530extern PSI_stage_info stage_binlog_processing_checkpoint_notify;
531extern PSI_stage_info stage_binlog_stopping_background_thread;
532extern PSI_stage_info stage_waiting_for_work_from_sql_thread;
533extern PSI_stage_info stage_waiting_for_prior_transaction_to_commit;
534extern PSI_stage_info stage_waiting_for_prior_transaction_to_start_commit;
535extern PSI_stage_info stage_waiting_for_room_in_worker_thread;
536extern PSI_stage_info stage_waiting_for_workers_idle;
537extern PSI_stage_info stage_waiting_for_ftwrl;
538extern PSI_stage_info stage_waiting_for_ftwrl_threads_to_pause;
539extern PSI_stage_info stage_waiting_for_rpl_thread_pool;
540extern PSI_stage_info stage_master_gtid_wait_primary;
541extern PSI_stage_info stage_master_gtid_wait;
542extern PSI_stage_info stage_gtid_wait_other_connection;
543extern PSI_stage_info stage_slave_background_process_request;
544extern PSI_stage_info stage_slave_background_wait_request;
545extern PSI_stage_info stage_waiting_for_deadlock_kill;
546
547#ifdef HAVE_PSI_STATEMENT_INTERFACE
548/**
549 Statement instrumentation keys (sql).
550 The last entry, at [SQLCOM_END], is for parsing errors.
551*/
552extern PSI_statement_info sql_statement_info[(uint) SQLCOM_END + 1];
553
554/**
555 Statement instrumentation keys (com).
556 The last entry, at [COM_END], is for packet errors.
557*/
558extern PSI_statement_info com_statement_info[(uint) COM_END + 1];
559
560/**
561 Statement instrumentation key for replication.
562*/
563extern PSI_statement_info stmt_info_rpl;
564
565void init_sql_statement_info();
566void init_com_statement_info();
567#endif /* HAVE_PSI_STATEMENT_INTERFACE */
568
569#ifndef __WIN__
570extern pthread_t signal_thread;
571#endif
572
573#ifdef HAVE_OPENSSL
574extern struct st_VioSSLFd * ssl_acceptor_fd;
575#endif /* HAVE_OPENSSL */
576
577extern ulonglong my_pcre_frame_size;
578
579/*
580 The following variables were under INNODB_COMPABILITY_HOOKS
581 */
582extern my_bool opt_large_pages;
583extern uint opt_large_page_size;
584extern char lc_messages_dir[FN_REFLEN];
585extern char *lc_messages_dir_ptr, *log_error_file_ptr;
586extern MYSQL_PLUGIN_IMPORT char reg_ext[FN_EXTLEN];
587extern MYSQL_PLUGIN_IMPORT uint reg_ext_length;
588extern MYSQL_PLUGIN_IMPORT uint lower_case_table_names;
589extern MYSQL_PLUGIN_IMPORT bool mysqld_embedded;
590extern ulong specialflag;
591extern uint mysql_data_home_len;
592extern uint mysql_real_data_home_len;
593extern const char *mysql_real_data_home_ptr;
594extern ulong thread_handling;
595extern "C" MYSQL_PLUGIN_IMPORT char server_version[SERVER_VERSION_LENGTH];
596extern char *server_version_ptr;
597extern bool using_custom_server_version;
598extern MYSQL_PLUGIN_IMPORT char mysql_real_data_home[];
599extern char mysql_unpacked_real_data_home[];
600extern MYSQL_PLUGIN_IMPORT struct system_variables global_system_variables;
601extern char default_logfile_name[FN_REFLEN];
602extern char *my_proxy_protocol_networks;
603
604#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
605
606extern MYSQL_PLUGIN_IMPORT const key_map key_map_empty;
607extern MYSQL_PLUGIN_IMPORT key_map key_map_full; /* Should be threaded as const */
608
609/*
610 Server mutex locks and condition variables.
611 */
612extern mysql_mutex_t
613 LOCK_item_func_sleep, LOCK_status, LOCK_show_status,
614 LOCK_error_log, LOCK_delayed_insert, LOCK_short_uuid_generator,
615 LOCK_delayed_status, LOCK_delayed_create, LOCK_crypt, LOCK_timezone,
616 LOCK_slave_list, LOCK_active_mi, LOCK_manager,
617 LOCK_global_system_variables, LOCK_user_conn,
618 LOCK_prepared_stmt_count, LOCK_error_messages, LOCK_connection_count,
619 LOCK_slave_background;
620extern MYSQL_PLUGIN_IMPORT mysql_mutex_t LOCK_thread_count;
621extern mysql_mutex_t LOCK_start_thread;
622#ifdef HAVE_OPENSSL
623extern char* des_key_file;
624extern mysql_mutex_t LOCK_des_key_file;
625#endif
626extern mysql_mutex_t LOCK_server_started;
627extern mysql_cond_t COND_server_started;
628extern mysql_rwlock_t LOCK_grant, LOCK_sys_init_connect, LOCK_sys_init_slave;
629extern mysql_prlock_t LOCK_system_variables_hash;
630extern mysql_cond_t COND_thread_count, COND_start_thread;
631extern mysql_cond_t COND_manager;
632extern mysql_cond_t COND_slave_background;
633extern int32 thread_count, service_thread_count;
634
635extern char *opt_ssl_ca, *opt_ssl_capath, *opt_ssl_cert, *opt_ssl_cipher,
636 *opt_ssl_key, *opt_ssl_crl, *opt_ssl_crlpath;
637
638extern MYSQL_PLUGIN_IMPORT pthread_key(THD*, THR_THD);
639
640#ifdef MYSQL_SERVER
641
642/**
643 only options that need special treatment in get_one_option() deserve
644 to be listed below
645*/
646enum options_mysqld
647{
648 OPT_to_set_the_start_number=256,
649 OPT_BINLOG_DO_DB,
650 OPT_BINLOG_FORMAT,
651 OPT_BINLOG_IGNORE_DB,
652 OPT_BIN_LOG,
653 OPT_BOOTSTRAP,
654 OPT_CONSOLE,
655 OPT_DEBUG_SYNC_TIMEOUT,
656 OPT_DEPRECATED_OPTION,
657 OPT_IGNORE_DB_DIRECTORY,
658 OPT_ISAM_LOG,
659 OPT_KEY_BUFFER_SIZE,
660 OPT_KEY_CACHE_AGE_THRESHOLD,
661 OPT_KEY_CACHE_BLOCK_SIZE,
662 OPT_KEY_CACHE_DIVISION_LIMIT,
663 OPT_KEY_CACHE_PARTITIONS,
664 OPT_KEY_CACHE_CHANGED_BLOCKS_HASH_SIZE,
665 OPT_LOG_BASENAME,
666 OPT_LOG_ERROR,
667 OPT_LOWER_CASE_TABLE_NAMES,
668 OPT_MAX_LONG_DATA_SIZE,
669 OPT_PLUGIN_LOAD,
670 OPT_PLUGIN_LOAD_ADD,
671 OPT_PFS_INSTRUMENT,
672 OPT_REPLICATE_DO_DB,
673 OPT_REPLICATE_DO_TABLE,
674 OPT_REPLICATE_IGNORE_DB,
675 OPT_REPLICATE_IGNORE_TABLE,
676 OPT_REPLICATE_REWRITE_DB,
677 OPT_REPLICATE_WILD_DO_TABLE,
678 OPT_REPLICATE_WILD_IGNORE_TABLE,
679 OPT_SAFE,
680 OPT_SERVER_ID,
681 OPT_SILENT,
682 OPT_SKIP_HOST_CACHE,
683 OPT_SKIP_RESOLVE,
684 OPT_SLAVE_PARALLEL_MODE,
685 OPT_SSL_CA,
686 OPT_SSL_CAPATH,
687 OPT_SSL_CERT,
688 OPT_SSL_CIPHER,
689 OPT_SSL_CRL,
690 OPT_SSL_CRLPATH,
691 OPT_SSL_KEY,
692 OPT_THREAD_CONCURRENCY,
693 OPT_WANT_CORE,
694#ifdef WITH_WSREP
695 OPT_WSREP_CAUSAL_READS,
696 OPT_WSREP_SYNC_WAIT,
697#endif /* WITH_WSREP */
698 OPT_MYSQL_COMPATIBILITY,
699 OPT_MYSQL_TO_BE_IMPLEMENTED,
700 OPT_which_is_always_the_last
701};
702#endif
703
704/**
705 Query type constants (usable as bitmap flags).
706*/
707enum enum_query_type
708{
709 /// Nothing specific, ordinary SQL query.
710 QT_ORDINARY= 0,
711 /// In utf8.
712 QT_TO_SYSTEM_CHARSET= (1 << 0),
713 /// Without character set introducers.
714 QT_WITHOUT_INTRODUCERS= (1 << 1),
715 /// view internal representation (like QT_ORDINARY except ORDER BY clause)
716 QT_VIEW_INTERNAL= (1 << 2),
717 /// If identifiers should not include database names, where unambiguous
718 QT_ITEM_IDENT_SKIP_DB_NAMES= (1 << 3),
719 /// If identifiers should not include table names, where unambiguous
720 QT_ITEM_IDENT_SKIP_TABLE_NAMES= (1 << 4),
721 /// If Item_cache_wrapper should not print <expr_cache>
722 QT_ITEM_CACHE_WRAPPER_SKIP_DETAILS= (1 << 5),
723 /// If Item_subselect should print as just "(subquery#1)"
724 /// rather than display the subquery body
725 QT_ITEM_SUBSELECT_ID_ONLY= (1 << 6),
726 /// If NULLIF(a,b) should print itself as
727 /// CASE WHEN a_for_comparison=b THEN NULL ELSE a_for_return_value END
728 /// when "a" was replaced to two different items
729 /// (e.g. by equal fields propagation in optimize_cond())
730 /// or always as NULLIF(a, b).
731 /// The default behaviour is to use CASE syntax when
732 /// a_for_return_value is not the same as a_for_comparison.
733 /// SHOW CREATE {VIEW|PROCEDURE|FUNCTION} and other cases where the
734 /// original representation is required, should set this flag.
735 QT_ITEM_ORIGINAL_FUNC_NULLIF= (1 << 7),
736
737 /// This value means focus on readability, not on ability to parse back, etc.
738 QT_EXPLAIN= QT_TO_SYSTEM_CHARSET |
739 QT_ITEM_IDENT_SKIP_DB_NAMES |
740 QT_ITEM_CACHE_WRAPPER_SKIP_DETAILS |
741 QT_ITEM_SUBSELECT_ID_ONLY,
742
743 QT_SHOW_SELECT_NUMBER= (1<<10),
744 /// This is used for EXPLAIN EXTENDED extra warnings / Be more detailed
745 /// Be more detailed than QT_EXPLAIN.
746 /// Perhaps we should eventually include QT_ITEM_IDENT_SKIP_CURRENT_DATABASE
747 /// here, as it would give better readable results
748 QT_EXPLAIN_EXTENDED= QT_TO_SYSTEM_CHARSET|
749 QT_SHOW_SELECT_NUMBER,
750
751 // If an expression is constant, print the expression, not the value
752 // it evaluates to. Should be used for error messages, so that they
753 // don't reveal values.
754 QT_NO_DATA_EXPANSION= (1 << 9),
755};
756
757
758/* query_id */
759extern query_id_t global_query_id;
760
761ATTRIBUTE_NORETURN void unireg_end(void);
762
763/* increment query_id and return it. */
764inline __attribute__((warn_unused_result)) query_id_t next_query_id()
765{
766 return my_atomic_add64_explicit(&global_query_id, 1, MY_MEMORY_ORDER_RELAXED);
767}
768
769inline query_id_t get_query_id()
770{
771 return my_atomic_load64_explicit(&global_query_id, MY_MEMORY_ORDER_RELAXED);
772}
773
774/* increment global_thread_id and return it. */
775extern __attribute__((warn_unused_result)) my_thread_id next_thread_id(void);
776
777/*
778 TODO: Replace this with an inline function.
779 */
780#ifndef EMBEDDED_LIBRARY
781extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
782#else
783extern "C" void unireg_clear(int exit_code);
784#define unireg_abort(exit_code) do { unireg_clear(exit_code); DBUG_RETURN(exit_code); } while(0)
785#endif
786
787inline void table_case_convert(char * name, uint length)
788{
789 if (lower_case_table_names)
790 files_charset_info->cset->casedn(files_charset_info,
791 name, length, name, length);
792}
793
794inline void thread_safe_increment32(int32 *value)
795{
796 (void) my_atomic_add32_explicit(value, 1, MY_MEMORY_ORDER_RELAXED);
797}
798
799inline void thread_safe_decrement32(int32 *value)
800{
801 (void) my_atomic_add32_explicit(value, -1, MY_MEMORY_ORDER_RELAXED);
802}
803
804inline void thread_safe_increment64(int64 *value)
805{
806 (void) my_atomic_add64_explicit(value, 1, MY_MEMORY_ORDER_RELAXED);
807}
808
809inline void thread_safe_decrement64(int64 *value)
810{
811 (void) my_atomic_add64_explicit(value, -1, MY_MEMORY_ORDER_RELAXED);
812}
813
814extern void set_server_version(char *buf, size_t size);
815
816#define current_thd _current_thd()
817inline int set_current_thd(THD *thd)
818{
819 return my_pthread_setspecific_ptr(THR_THD, thd);
820}
821
822
823/*
824 @todo remove, make it static in ha_maria.cc
825 currently it's needed for sql_select.cc
826*/
827extern handlerton *maria_hton;
828
829extern uint extra_connection_count;
830extern uint64 global_gtid_counter;
831extern my_bool opt_gtid_strict_mode;
832extern my_bool opt_userstat_running, debug_assert_if_crashed_table;
833extern uint mysqld_extra_port;
834extern ulong opt_progress_report_time;
835extern ulong extra_max_connections;
836extern ulonglong denied_connections;
837extern ulong thread_created;
838extern scheduler_functions *thread_scheduler, *extra_thread_scheduler;
839extern char *opt_log_basename;
840extern my_bool opt_master_verify_checksum;
841extern my_bool opt_stack_trace, disable_log_notes;
842extern my_bool opt_expect_abort;
843extern my_bool opt_slave_sql_verify_checksum;
844extern my_bool opt_mysql56_temporal_format, strict_password_validation;
845extern my_bool opt_explicit_defaults_for_timestamp;
846extern ulong binlog_checksum_options;
847extern bool max_user_connections_checking;
848extern ulong opt_binlog_dbug_fsync_sleep;
849
850extern uint volatile global_disable_checkpoint;
851extern my_bool opt_help;
852
853#endif /* MYSQLD_INCLUDED */
854