我是靠谱客的博主 贪玩小伙,这篇文章主要介绍MySQL连接查询流程源码分析,现在分享给大家,希望可以做个参考。

初始化

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
main |-mysqld |-my_init // 初始话线程变量,互斥量 |-load_defaults // 获取配置 |-init_common_variables // 初始化变量 |-init_server_components // 初始化插件 | |-plugin_init | | |-plugin_initialize | |-initialize_storage_engine |-network_init // 监听网络 |-grant_init |-servers_init |-udf_init

插件启动

复制代码
1
2
3
4
5
6
7
main |-mysqld_main |-init_server_components |-plugin_init |-plugin_initialize |-ha_initialize_handlerton |-innobase_init

登录过程

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
main |-mysqld_main |-network_init // 建立socket监听,一个针对网络,一个针对unix域 |-handle_connections_sockets |-poll |-mysql_socket_accept // 和客户端建立连接 |-create_new_thread // 针对每个socket连接建立一个新的线程 |-create_thread_to_handle_connection |-waiting_thd_list->push_back(thd);mysql_cond_signal(&COND_thread_cache); // 已有连接处理线程时,通过信号唤醒,处理线程函数为pfs_spawn_thread |-mysql_thread_create(启动的线程执行函数,inline_mysql_thread_create) |-spawn_thread_v1 |-pthread_create(pfs_spawn_thread)

处理连接

复制代码
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
pfs_spawn_thread |-handle_one_connection |-do_handle_one_connection |-MYSQL_CALLBACK_ELSE(thread_scheduler, init_new_connection_thread, (), 0) | |-init_new_connection_handler_thread |-thd_prepare_connection | |-login_connection // 判断是否可以login,不可以则断开连接返回错误 | | |-check_connection | | | |-acl_authenticate | | | |-do_auth_once | | | |-native_password_authenticate | | | |-server_mpvio_write_packet | | | | |-send_server_handshake_packet // 发送handshake包到客户端 | | | | |-my_net_write | | | | | |-net_write_buff // 将数据写入到内存 | | | | |-net_flush // 将内存中数据发送到网络 | | | |-server_mpvio_read_packet // 从客户端接收Login Request信息 | | | |-my_net_read | | |-Protocol::end_statement | | |-Protocol::send_ok | | |-net_send_ok // 发送response ok | | |-my_net_write | |-prepare_new_connection_state |-do_command |-dispatch_command |-mysql_parse

处理命令select

复制代码
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
pfs_swpawn_thread |-handle_one_connection |-do_handle_one_connection |-do_command |-dispatch_command |-mysql_parse |-parse_sql | |-MYSQLparse |-mysql_execute_command |-select_precheck | |-check_table_access |-execute_sqlcom_select | |-open_normal_and_derived_tables | |-open_tables | | |-open_and_process_table | | |-open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) | | |-Table_cache::get_table | | |-get_table_share_with_discover | | | |-get_table_share | | | |-open_table_def | | |-my_malloc // 申请表数据结构 | | |-open_table_from_share | | |-handler::ha_open | | |-ha_innobase::open | | |-dict_table_open_on_name | | |-dict_load_table | | |-btr_pcur_is_on_user_rec | | |-dict_load_table_low | | | |-dict_mem_table_create | | |-fil_space_for_table_exists_in_mem | | |-fil_open_single_table_tablespace // 打开表空间文件 | |-mysql_handle_derived |-handle_select |-mysql_select |-mysql_prepare_select | |-JOIN::prepare |-mysql_execute_select |-JOIN::exec |-select_send::send_result_set_metadata | |-Protocol::send_result_set_metadata |-do_select |-sub_select |-evaluate_join_record |-end_send |-select_send::send_data |-Protocol::write

最后

以上就是贪玩小伙最近收集整理的关于MySQL连接查询流程源码分析的全部内容,更多相关MySQL连接查询流程源码分析内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部