-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathmysqld.cc
14730 lines (13166 loc) · 564 KB
/
mysqld.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/**
@file sql/mysqld.cc
MySQL server daemon.
*/
/* clang-format off */
/**
@mainpage Welcome
Welcome to the MySQL source code documentation.
This documentation covers primarily the MySQL server,
for the @c mysqld process.
Other programs, like the MySQL Router, are also documented,
see the @ref PAGE_SERVER_TOOLS section.
The order chosen to present the content is to start with low level components,
and build upon previous sections, so that code is presented in a logical order.
For some sections, a full article (Doxygen 'page') presents the component in detail.
For other sections, only links are provided, as a starting point into the component.
For the user manual, see http://dev.mysql.com/doc/refman/8.0/en/
This documentation is published for each release, starting with MySQL 8.0.
The present document corresponds to:
Document generated on: ${DOXYGEN_GENERATION_DATE},
branch: ${DOXYGEN_GENERATION_BRANCH},
revision: ${DOXYGEN_GENERATION_REVISION}
For the latest available version, see https://dev.mysql.com/doc/dev/mysql-server/latest/
For other versions, see https://dev.mysql.com/doc/index-archive.html
*/
/**
@page PAGE_GET_STARTED Getting Started
- @ref start_source
- @subpage PAGE_CODING_GUIDELINES
- @ref start_debug
@section start_source Build from source
See https://dev.mysql.com/doc/refman/8.0/en/source-installation.html
@section start_debug Debugging
The easiest way to install a server, and attach a debugger to it,
is to start the mysql-test-run (MTR) tool with debugging options
@verbatim
cd mysql-test
./mtr --ddd main.parser
@endverbatim
The following functions are good candidates for breakpoints:
- #my_message_sql
- #dispatch_command
Replace 'main.parser' with another test script, or write your own, to debug a specific area.
*/
/**
@page PAGE_CODING_GUIDELINES Coding Guidelines
This section shows the guidelines that MySQL developers
follow when writing new code.
New MySQL code uses the Google C++ coding style
(https://google.github.io/styleguide/cppguide.html), with two
exceptions:
- Member variable names: Do not use foo_. Instead, use
m_foo (non-static) or s_foo (static).
Old projects and modifications to old code use an older MySQL-specific
style for the time being. Since 8.0, MySQL style uses the same formatting
rules as Google coding style (e.g., brace placement, indentation, line
lengths, etc.), but differs in a few important aspects:
- Class names: Do not use MyClass. Instead, use My_class.
- Function names: Use snake_case().
- Comment Style: Use either the // or <em>/</em>* *<em>/</em> syntax. // is
much more common but both syntaxes are permitted for the time being.
- Doxygen comments: Use <em>/</em>** ... *<em>/</em> syntax and not ///.
- Doxygen commands: Use '@' and not '\' for doxygen commands.
- You may see structs starting with st_ and being typedef-ed to some
UPPERCASE (e.g. typedef struct st_foo { ... } FOO). However,
this is legacy from when the codebase contained C. Do not make such new
typedefs nor structs with st_ prefixes, and feel free to remove those that
already exist, except in public header files that are part of libmysql
(which need to be parseable as C99).
Code formatting is enforced by use of clang-format throughout the code
base. However, note that formatting is only one part of coding style;
you are required to take care of non-formatting issues yourself, such as
following naming conventions, having clear ownership of code or minimizing
the use of macros. See the Google coding style guide for the entire list.
Consistent style is important for us, because everyone must know what to
expect. Knowing our rules, you'll find it easier to read our code, and when
you decide to contribute (which we hope you'll consider!) we'll find it
easier to read and review your code.
- @subpage GENERAL_DEVELOPMENT_GUIDELINES
- @subpage DBUG_TAGS
*/
/**
@page PAGE_INFRASTRUCTURE Infrastructure
@section infra_basic Basic classes and templates
@subsection infra_basic_container Container
See #DYNAMIC_ARRAY, #List, #I_P_List, #LF_HASH.
@subsection infra_basic_syncho Synchronization
See #native_mutex_t, #native_rw_lock_t, #native_cond_t.
@subsection infra_basic_fileio File IO
See #my_open, #my_dir.
@section infra_server_blocks Server building blocks
@subsection infra_server_blocks_vio Virtual Input Output
See #Vio, #vio_init.
@section deployment Deployment
@subsection deploy_install Installation
See #opt_initialize, #bootstrap::run_bootstrap_thread.
@subsection deploy_startup Startup
See #mysqld_main.
@subsection deploy_shutdown Shutdown
See #handle_fatal_signal, #signal_hand.
@subsection deploy_upgrade Upgrade
See #Mysql::Tools::Upgrade::Program.
*/
/**
@page PAGE_PROTOCOL Client/Server Protocol
@section protocol_overview Overview
The MySQL protocol is used between MySQL Clients and a MySQL Server.
It is implemented by:
- Connectors (Connector/C, Connector/J, and so forth)
- MySQL Proxy
- Communication between master and slave replication servers
The protocol supports these features:
- Transparent encryption using SSL
- Transparent compression
- A @ref page_protocol_connection_phase where capabilities and
authentication data are exchanged
- A @ref page_protocol_command_phase which accepts commands
from the client and executes them
Further reading:
- @subpage page_protocol_basics
- @subpage page_protocol_connection_lifecycle
*/
/** @page page_mysqlx_protocol X %Protocol
@par Topics in this section:
- @subpage mysqlx_protocol_lifecycle
- @subpage mysqlx_protocol_authentication
- @subpage mysqlx_protocol_messages
- @subpage mysqlx_protocol_expectations
- @subpage mysqlx_protocol_notices
- @subpage mysqlx_protocol_xplugin
- @subpage mysqlx_protocol_use_cases
- @subpage mysqlx_protocol_implementation
- @subpage mysqlx_protocol_comparison
- @subpage mysqlx_community_connector
The X %Protocol is implemented by the X Plugin and the following
MySQL clients support the protocol:
- MYSQLXSHELL
- MySQL for Visual Studio 2.0.2 or higher
- MySQL Connector/J 6.0.2 or higher
- MySQL Connector/Net 7.0.2 or higher
- MySQL Connector/Node.js
*/
/**
@page PAGE_SQL_EXECUTION SQL Query Execution
@section sql_query_exec_parsing SQL Parsing
The parser processes SQL strings and builds a tree representation of them.
See @ref GROUP_PARSER.
@subpage PAGE_SQL_Optimizer
@subpage stored_programs
@section sql_query_exec_prepared Prepared statements
See #mysql_stmt_prepare
@section func_stored_proc Stored procedures
See #sp_head, #sp_instr.
@section sql_query_exec_sql_functions SQL Functions
See #Item_func
@section sql_query_exec_error_handling Error handling
See #my_message, #my_error
@subpage PAGE_TXN
*/
/**
@page PAGE_STORAGE Data Storage
@section storage_innodb Innodb
See #ha_innobase or read details about InnoDB internals:
- @subpage PAGE_INNODB_PFS
- @subpage PAGE_INNODB_REDO_LOG
- @subpage PAGE_INNODB_LOCK_SYS
- @subpage PAGE_INNODB_UTILS
@section storage_temptable Temp table
Before 8.0, temporary tables were handled by heap engine.
The heap engine had no feature to store bigger tables on disk.
Since 8.0, there is a brand new temptable engine, which
is written from scratch using c++11. It has following advantages:
- it is able to store bigger tables on disk (in temporary files),
- it uses row format with variable size (can save memory for varchars),
- it is better designed (easier to maintain).
@subpage PAGE_TEMPTABLE
*/
/**
@page PAGE_REPLICATION Replication
@subpage PAGE_RPL_FIELD_METADATA
*/
/**
@page PAGE_TXN Transactions
See #trans_begin, #trans_commit, #trans_rollback.
*/
/**
@page PAGE_SECURITY Security
@subpage AUTHORIZATION_PAGE
@subpage PAGE_KEYRING_COMPONENT
*/
/**
@page PAGE_MONITORING Monitoring
@subpage PAGE_PFS
*/
/**
@page PAGE_EXTENDING Extending MySQL
Components
----------
MySQL 8.0 introduces support for extending the server through components.
Components can communicate with other components through service APIs.
And can provide implementations of service APIs for other components to use.
All components are equal and can communicate with all other components.
Service implementations can be found by name via a registry service handle
which is passed to the component initialization function.
There can be multiple service API implementations for a single service API.
One of them is the default implementation.
Service API are stateless by definition. If they need to handle state or
object instances they need to do so by using factory methods and instance
handles.
To ease up transition to the component model the current server
functionality (server proper and plugins) is contained within
a dedicated built in server component. The server component currently
contains all of the functionality provided by the server and
classical server plugins.
More components can be installed via the "INSTALL COMPONENT" SQL command.
The component infrastructure is designed as a replacement for the classical
MySQL plugin system as it does not suffer from some of the limitations of it
and provides better isolation for the component code.
See @subpage PAGE_COMPONENTS.
Plugins and Services
--------------------
As of MySQL 5.1 the server functionality can be extended through
installing (dynamically or statically linked) extra code modules
called plugins.
The server defines a set of well known plugin APIs that the modules
can implement.
To allow plugins to reuse server code the server exposes a pre-defined
set of functions to plugins called plugin services.
See the following for more details:
- @subpage page_ext_plugins
- @subpage page_ext_plugin_services
User Defined Functions
----------------------
Native code user defined functions can be added to MySQL server using
the CREATE FUNCTION ... SONAME syntax.
These can co-exit with @ref page_ext_plugins or reside in their own
separate binaries.
To learn how to create these user defined functions see @subpage page_ext_udf
*/
/**
@page PAGE_SERVICES Available services
@subpage PAGE_TABLE_ACCESS_SERVICE
@subpage PAGE_MYSQL_SERVER_TELEMETRY_TRACES_SERVICE
@subpage page_event_tracking_services
@subpage PAGE_MYSQL_SERVER_METRICS_INSTRUMENT_SERVICE
@subpage PAGE_MYSQL_SERVER_TELEMETRY_METRICS_SERVICE
@subpage PAGE_MYSQL_GLOBAL_VARIABLE_ATTRIBUTES_SERVICE
@subpage PAGE_MYSQL_SERVER_TELEMETRY_LOGS_SERVICE
@subpage PAGE_MYSQL_SERVER_TELEMETRY_LOGS_CLIENT_SERVICE
*/
/**
@page PAGE_SERVER_TOOLS Server tools
- @subpage PAGE_MYSQL_ROUTER
*/
/**
@page PAGE_CLIENT_TOOLS Client tools
See mysqldump.cc mysql.cc
*/
/**
@page PAGE_TESTING_TOOLS Testing Tools
- @subpage PAGE_MYSQL_TEST_RUN
- @subpage PAGE_COMPONENT_MOCK_UNIT_TEST_TOOLS
*/
/**
@page PAGE_DEV_TOOLS Development Tools
- @subpage PAGE_LOCK_ORDER
*/
/**
@page PAGE_CODE_PATHS Code paths
This section details how the server executes some statements,
to illustrate how different parts work together.
Note that this overall view might take some shortcuts,
hiding some details or taking liberties with the notations,
to present the whole code structure in a comprehensible way.
- @subpage CODE_PATH_CREATE_TABLE
*/
/**
@page CODE_PATH_CREATE_TABLE CREATE TABLE
@section CREATE_TABLE_PARSER Parser
@startuml
actor ddl as "CREATE TABLE Query"
participant server as "MySQL Server"
participant parser as "SQL Parser"
participant bison as "Bison Parser"
participant lexer as "Lexical Scanner"
participant pt as "Parse Tree Nodes"
ddl -> server : DDL QUERY TEXT
server -> parser : THD::sql_parser()
== Bison parser ==
parser -> bison : MYSQLparse()
bison -> lexer : MYSQLlex()
bison <-- lexer : yylval, yylloc
bison -> pt : new
activate pt
parser <-- pt : Abstract Syntax Tree
@enduml
When a query is sent to the server,
the first step is to invoke the bison parser
to build an Abstract Syntax Tree to represent the query text.
Assume the following statement:
@verbatim
CREATE TABLE test.t1 (a int) ENGINE = "INNODB";
@endverbatim
In the bison grammar file, the rule implementing the CREATE TABLE
statement is @c create_table_stmt.
The tree created is an object of class @ref PT_create_table_stmt.
This parse tree node has several related nodes, such as:
- @ref PT_create_table_option and sub classes, for table options.
- @ref PT_table_element and sub classes, for the columns, indexes, etc.
The collection of nodes returned after the bison parsing is known
as the "Abstract Syntax Tree" that represents a SQL query.
@section CREATE_TABLE_CMD Sql command
@startuml
actor ddl as "CREATE TABLE Query"
participant server as "MySQL Server"
participant parser as "SQL Parser"
participant ast as "Abstract Syntax Tree"
participant cmd as "SQL Command"
participant ci as "HA_CREATE_INFO"
participant plugin as "MySQL plugin"
ddl -> server : DDL QUERY TEXT
server -> parser : THD::sql_parser()
== Bison parser ==
== Build SQL command ==
parser -> ast : make_cmd()
ast -> ast : contextualize()
ast -> ci : build()
activate ci
ci -> plugin : ha_resolve_engine()
ci <-- plugin : storage engine handlerton
ast <-- ci : Parse Tree (contextualized)
ast -> cmd : build()
activate cmd
server <-- cmd : SQL Command
@enduml
Once the bison parser has finished parsing a query text,
the next step is to build a SQL command from the Abstract Syntax Tree.
In the Abstract Syntax Tree, attributes like a storage engine name
("INNODB") are represented as strings, taken from the query text.
These attributes need to be converted to objects in the SQL context,
such as an @ref innodb_hton pointer to represent the INNODB storage engine.
The process that performs these transformations is contextualize().
The @ref Parse_tree_root class is an abstract factory, building @ref Sql_cmd
objects.
For a CREATE TABLE statement, class @ref PT_create_table_stmt builds a
concrete @ref Sql_cmd_create_table object.
@ref PT_create_table_stmt::make_cmd() in particular performs the following
actions:
- contextualize the parse tree for the CREATE TABLE statement.
- build a @ref HA_CREATE_INFO structure to represent the table DDL.
- resolve the storage engine name to an actual @ref handlerton pointer,
in @ref PT_create_table_engine_option::do_contextualize()
@section CREATE_TABLE_RUNTIME Runtime execution
@startuml
actor ddl as "CREATE TABLE Query"
participant server as "MySQL Server"
participant cmd as "SQL Command"
participant rt as "Runtime"
ddl -> server : DDL QUERY TEXT
== Bison parser ==
== Build SQL command ==
== Execute SQL command ==
server -> cmd : execute()
cmd -> rt : mysql_create_table()
@enduml
Execution of a CREATE TABLE statement invokes
@ref Sql_cmd_create_table::execute(),
which in turns calls:
- @ref mysql_create_table(),
- @ref mysql_create_table_no_lock(),
- @ref create_table_impl(),
- @ref rea_create_base_table().
Execution of this code is the runtime implementation of the CREATE TABLE
statement, and eventually leads to:
- @ref dd::create_table(), to create the table in the Data Dictionary,
- @ref ha_create_table(), to create the table in the handlerton.
Details about the dictionary and the storage engine are expanded
in the following two sections.
@section CREATE_TABLE_DD Data Dictionary
@startuml
actor ddl as "CREATE TABLE Query"
participant server as "MySQL Server"
participant rt as "Runtime"
participant dd as "Data Dictionary"
participant ddt as "Data Dictionary Table"
participant sdi as "Serialized Dictionary Information"
participant hton as "Handlerton"
participant se as "Storage Engine"
participant ts as "Tablespace"
ddl -> server : DDL QUERY TEXT
== ... ==
server -> rt : ( execution code path )
== Data Dictionary ==
rt -> dd : dd::create_table()
dd -> ddt : build dd::Table()
activate ddt
rt <-- ddt : dd:Table instance
== Serialized Dictionary Information ==
rt -> dd : store()
dd -> sdi : dd::sdi::store()
sdi -> sdi : sdi_tablespace::store_tbl_sdi()
== Storage Engine (Tablespace) ==
sdi -> hton : handlerton::sdi()
hton -> se : ::sdi() implementation.
se -> ts : write metadata in tablespace
@enduml
In the data dictionary, creation of a new table calls:
- @ref dd::create_dd_user_table()
- @ref fill_dd_table_from_create_info()
The data dictionary code parses the content of the HA_CREATE_INFO
input, and builds a @ref dd::Table object, to represent the table metadata.
Part of this metadata includes the storage engine name.
The runtime code then calls @c store() to save this new metadata.
To store a table metadata, the data dictionary code first serialize it
into an sdi format.
The serialized object is then stored in persistence,
either in a tablespace or in a file:
- @ref sdi_tablespace::store_tbl_sdi()
- @ref sfi_file::store_tbl_sdi()
When storing data into a tablespace, the storage engine handlerton is
invoked, so that the storage engine can ultimately store
the table metadata in the tablespace maintained by the storage engine.
@section CREATE_TABLE_SE Storage Engine
@startuml
actor ddl as "CREATE TABLE Query"
participant server as "MySQL Server"
participant rt as "Runtime"
participant sei as "Storage Engine Interface"
participant hton as "Storage Engine Handlerton"
participant handler as "Storage Engine Handler"
ddl -> server : DDL QUERY TEXT
== ... ==
server -> rt : ( execution code path )
== Storage Engine (table) ==
rt -> sei : ha_create_table()
sei -> hton : handlerton::create()
hton -> handler : (build a new table handler)
activate handler
sei <-- handler : storage engine table handler
sei -> handler : handler::create()
@enduml
When execution of the CREATE TABLE statement
reaches the storage engine interface,
the SQL layer function @ref ha_create_table()
invokes the storage engine @ref handlerton::create()
method to instantiate a new storage engine table,
represented by @ref handler.
The SQL layer then calls @ref handler::create() to create
the table inside the storage engine.
*/
/**
@page PAGE_SQL_Optimizer SQL Optimizer
The task of query optimizer is to determine the most efficient means for
executing queries. The query optimizer consists of the following
sub-modules:
- @ref Query_Resolver
- @ref Query_Optimizer
- @ref Query_Planner
- @ref Query_Executor
@subpage PAGE_OPT_TRACE
Additional articles about the query optimizer:
- @ref PAGE_OPT_TRACE
- @ref AGGREGATE_CHECKS
*/
/* clang-format on */
#define LOG_SUBSYSTEM_TAG "Server"
#include "sql/mysqld.h"
#include "my_config.h"
#include "errmsg.h" // init_client_errs
#include "ft_global.h"
#ifdef _WIN32
#include "jemalloc_win.h"
#endif
#include "keycache.h" // KEY_CACHE
#include "m_string.h"
#include "migrate_keyring.h" // Migrate_keyring
#include "my_alloc.h"
#include "my_base.h"
#include "my_bitmap.h" // MY_BITMAP
#include "my_command.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_default.h" // print_defaults
#include "my_dir.h"
#include "my_getpwnam.h"
#include "my_macros.h"
#include "my_rnd.h"
#include "my_shm_defaults.h" // IWYU pragma: keep
#include "my_ssl_algo_cache.h"
#include "my_stacktrace.h" // my_set_exception_pointers
#include "my_thread_local.h"
#include "my_time.h"
#include "my_timer.h" // my_timer_initialize
#include "myisam.h"
#include "mysql/binlog/event/binlog_event.h"
#include "mysql/binlog/event/control_events.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/components/services/mysql_option_tracker.h"
#include "mysql/components/services/mysql_runtime_error_service.h"
#include "mysql/components/util/weak_service_reference.h"
#include "mysql/my_loglevel.h"
#include "mysql/plugin.h"
#include "mysql/plugin_audit.h"
#include "mysql/psi/mysql_cond.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/psi/mysql_memory.h" // mysql_memory_init
#include "mysql/psi/mysql_metric.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_rwlock.h"
#include "mysql/psi/mysql_socket.h"
#include "mysql/psi/mysql_stage.h"
#include "mysql/psi/mysql_statement.h"
#include "mysql/psi/mysql_thread.h"
#include "mysql/psi/psi_cond.h"
#include "mysql/psi/psi_data_lock.h"
#include "mysql/psi/psi_error.h"
#include "mysql/psi/psi_file.h"
#include "mysql/psi/psi_idle.h"
#include "mysql/psi/psi_mdl.h"
#include "mysql/psi/psi_memory.h"
#include "mysql/psi/psi_mutex.h"
#include "mysql/psi/psi_rwlock.h"
#include "mysql/psi/psi_socket.h"
#include "mysql/psi/psi_stage.h"
#include "mysql/psi/psi_statement.h"
#include "mysql/psi/psi_system.h"
#include "mysql/psi/psi_table.h"
#include "mysql/psi/psi_thread.h"
#include "mysql/psi/psi_tls_channel.h"
#include "mysql/psi/psi_transaction.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/thread_type.h"
#include "mysql_time.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include "mysys/build_id.h"
#include "mysys_err.h" // EXIT_OUT_OF_MEMORY
#include "nulls.h"
#include "pfs_thread_provider.h"
#include "print_version.h"
#include "scope_guard.h" // create_scope_guard()
#include "server_component/log_sink_buffer.h" // log_error_stage_set()
#include "server_component/log_sink_perfschema.h" // log_error_read_log()
#include "server_component/log_sink_trad.h" // log_sink_trad()
#include "server_component/log_source_backtrace.h" // log_error_read_backtrace()
#include "server_component/mysql_server_event_tracking_bridge_imp.h" // init_srv_event_tracking_handles()
#include "sql/mysqld_cs.h"
#ifdef _WIN32
#include <shellapi.h>
#endif
#include "sql-common/my_decimal.h"
#include "sql/auth/auth_common.h" // grant_init
#include "sql/auth/authentication_policy.h"
#include "sql/auth/sql_authentication.h" // init_rsa_keys
#include "sql/auth/sql_security_ctx.h"
#include "sql/auto_thd.h" // Auto_THD
#include "sql/binlog.h" // mysql_bin_log
#include "sql/bootstrap.h" // bootstrap
#include "sql/check_stack.h"
#include "sql/conn_handler/connection_acceptor.h" // Connection_acceptor
#include "sql/conn_handler/connection_handler_impl.h" // Per_thread_connection_handler
#include "sql/conn_handler/connection_handler_manager.h" // Connection_handler_manager
#include "sql/conn_handler/socket_connection.h" // stmt_info_new_packet
#include "sql/current_thd.h" // current_thd
#include "sql/dd/cache/dictionary_client.h"
#include "sql/debug_sync.h" // debug_sync_end
#include "sql/derror.h"
#include "sql/event_data_objects.h" // init_scheduler_psi_keys
#include "sql/events.h" // Events
#include "sql/handler.h"
#include "sql/hostname_cache.h" // hostname_cache_init
#include "sql/init.h" // unireg_init
#include "sql/item.h"
#include "sql/item_cmpfunc.h" // Arg_comparator
#include "sql/item_create.h"
#include "sql/item_func.h"
#include "sql/item_strfunc.h" // Item_func_uuid
#include "sql/keycaches.h" // get_or_create_key_cache
#include "sql/log.h"
#include "sql/log_event.h" // Rows_log_event
#include "sql/log_resource.h"
#include "sql/mdl.h"
#include "sql/mdl_context_backup.h" // mdl_context_backup_manager
#include "sql/mysqld_daemon.h"
#include "sql/mysqld_thd_manager.h" // Global_THD_manager
#include "sql/opt_costconstantcache.h" // delete_optimizer_cost_module
#include "sql/options_mysqld.h" // OPT_THREAD_CACHE_SIZE
#include "sql/partitioning/partition_handler.h" // partitioning_init
#include "sql/persisted_variable.h" // Persisted_variables_cache
#include "sql/plugin_table.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h" // key_memory_MYSQL_RELAY_LOG_index
#include "sql/query_options.h"
#include "sql/range_optimizer/range_optimizer.h" // range_optimizer_init
#include "sql/reference_caching_setup.h" // Event_reference_caching_channels
#include "sql/regexp/regexp_facade.h" // regexp::regexp_lib_charset
#include "sql/replication.h" // thd_enter_cond
#include "sql/resourcegroups/resource_group_mgr.h" // init, post_init
#include "sql/statement/statement.h"
#ifdef _WIN32
#include "sql/restart_monitor_win.h"
#endif
#include <mysql/psi/mysql_telemetry_logs_client.h> // mysql_log_client_register
#include "my_openssl_fips.h" // OPENSSL_ERROR_LENGTH, set_fips_mode
#include "pfs_metric_provider.h"
#include "pfs_telemetry_logs_client_provider.h"
#include "sql/binlog/services/iterator/file_storage.h"
#include "sql/rpl_async_conn_failover_configuration_propagation.h"
#include "sql/rpl_filter.h"
#include "sql/rpl_gtid.h"
#include "sql/rpl_gtid_persist.h" // Gtid_table_persistor
#include "sql/rpl_handler.h" // RUN_HOOK
#include "sql/rpl_info_factory.h"
#include "sql/rpl_info_handler.h"
#include "sql/rpl_injector.h" // injector
#include "sql/rpl_io_monitor.h"
#include "sql/rpl_log_encryption.h"
#include "sql/rpl_mi.h"
#include "sql/rpl_msr.h" // Multisource_info
#include "sql/rpl_opt_tracker.h"
#include "sql/rpl_replica.h" // replica_load_tmpdir
#include "sql/rpl_rli.h" // Relay_log_info
#include "sql/rpl_source.h" // max_binlog_dump_events
#include "sql/rpl_trx_tracking.h"
#include "sql/sd_notify.h" // sd_notify_connect
#include "sql/session_tracker.h"
#include "sql/set_var.h"
#include "sql/signal_handler.h"
#include "sql/sp_head.h" // init_sp_psi_keys
#include "sql/sql_audit.h" // mysql_audit_general
#include "sql/sql_base.h"
#include "sql/sql_callback.h" // MUSQL_CALLBACK
#include "sql/sql_class.h" // THD
#include "sql/sql_component.h"
#include "sql/sql_connect.h"
#include "sql/sql_error.h"
#include "sql/sql_event_tracking_to_audit_event_mapping.h"
#include "sql/sql_initialize.h" // opt_initialize_insecure
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_locale.h" // MY_LOCALE
#include "sql/sql_manager.h" // start_handle_manager
#include "sql/sql_parse.h" // check_stack_overrun
#include "sql/sql_plugin.h" // opt_plugin_dir
#include "sql/sql_plugin_ref.h"
#include "sql/sql_reload.h" // handle_reload_request
#include "sql/sql_restart_server.h" // is_mysqld_managed
#include "sql/sql_servers.h"
#include "sql/sql_show.h"
#include "sql/sql_table.h" // build_table_filename
#include "sql/sql_udf.h"
#include "sql/srv_event_plugin_handles.h"
#include "sql/ssl_acceptor_context_iterator.h"
#include "sql/ssl_acceptor_context_operator.h"
#include "sql/ssl_acceptor_context_status.h"
#include "sql/ssl_init_callback.h"
#include "sql/sys_vars.h" // fixup_enforce_gtid_consistency_...
#include "sql/sys_vars_shared.h" // intern_find_sys_var
#include "sql/table_cache.h" // table_cache_manager
#include "sql/tc_log.h" // tc_log
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql/transaction.h"
#include "sql/tztime.h" // Time_zone
#include "sql/udf_service_impl.h"
#include "sql/xa.h"
#include "sql/xa/transaction_cache.h" // xa::Transaction_cache
#include "sql_common.h" // mysql_client_plugin_init
#include "sql_string.h"
#include "storage/myisam/ha_myisam.h" // HA_RECOVER_OFF
#include "storage/perfschema/pfs_buffer_container.h" // PFS metric counters
#include "storage/perfschema/pfs_instr_class.h" // PFS metric counters
#include "storage/perfschema/pfs_services.h"
#include "storage/perfschema/telemetry_pfs_metrics.h" // register_pfs_metric_sources
#include "string_with_len.h"
#include "strings/str_alloc.h"
#include "strmake.h"
#include "strxmov.h"
#include "strxnmov.h"
#include "thr_lock.h"
#include "thr_mutex.h"
#include "typelib.h"
#include "violite.h"
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
#include "storage/perfschema/pfs_server.h"
#endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */
#ifdef _WIN32
#include "sql/conn_handler/named_pipe_connection.h"
#include "sql/conn_handler/shared_memory_connection.h"
#include "sql/named_pipe.h"
#endif
#ifdef MY_MSCRT_DEBUG
#include <crtdbg.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <fenv.h>
#include <limits.h>
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
#ifndef _WIN32
#include <netdb.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#include <signal.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_SYS_MMAN_H
#include <sys/mman.h>
#endif
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef _WIN32
#include <crtdbg.h>
#include <process.h>
#endif
#include "unicode/putil.h" // u_setDataDirectory()
#include "unicode/uclean.h" // u_cleanup()
#include <algorithm>
#include <atomic>
#include <functional>
#include <new>
#ifndef EMBEDDED_LIBRARY
#ifdef WITH_LOCK_ORDER
#include "sql/debug_lock_order.h"
#endif /* WITH_LOCK_ORDER */
#endif /* EMBEDDED_LIBRARY */
#ifndef EMBEDDED_LIBRARY
#include "srv_session.h"
#endif
#include <mysql/components/minimal_chassis.h>
#include <mysql/components/services/dynamic_loader_scheme_file.h>
#include <mysql/components/services/mysql_psi_system_service.h>
#include <mysql/components/services/mysql_rwlock_service.h>
#include <mysql/components/services/ongoing_transaction_query_service.h>
#include "sql/auth/dynamic_privileges_impl.h"
#include "sql/command_mapping.h"
#include "sql/dd/dd.h" // dd::shutdown
#include "sql/dd/dd_kill_immunizer.h" // dd::DD_kill_immunizer
#include "sql/dd/dictionary.h" // dd::get_dictionary
#include "sql/dd/ndbinfo_schema/init.h" // dd::ndbinfo::init_schema_and_tables()
#include "sql/dd/performance_schema/init.h" // performance_schema::init
#include "sql/dd/upgrade/server.h" // dd::upgrade::upgrade_system_schemas
#include "sql/server_component/component_sys_var_service_imp.h"
#include "sql/server_component/log_builtins_filter_imp.h"
#include "sql/server_component/log_builtins_imp.h"
#include "sql/server_component/mysql_server_keyring_lockable_imp.h"