MySQL连接查询流程源码

发布时间:2020-08-10 23:27:13 作者:wangwenan6
来源:ITPUB博客 阅读:259
来源: 互联网
版本: 不详, 仅做参考用

初始化:

点击(此处)折叠或打开

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

插件启动:

点击(此处)折叠或打开

  1. main
  2.     |-mysqld_main
  3.         |-init_server_components
  4.             |-plugin_init
  5.                 |-plugin_initialize
  6.                     |-ha_initialize_handlerton
  7.                         |-innobase_init

登录过程:

点击(此处)折叠或打开

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

处理连接:


点击(此处)折叠或打开

  1. pfs_spawn_thread
  2.     |-handle_one_connection
  3.         |-do_handle_one_connection
  4.             |-MYSQL_CALLBACK_ELSE(thread_scheduler, init_new_connection_thread, (), 0)
  5.             | |-init_new_connection_handler_thread
  6.             |-thd_prepare_connection
  7.             | |-login_connection // 判断是否可以login,不可以则断开连接返回错误
  8.             | | |-check_connection
  9.             | | | |-acl_authenticate
  10.             | | | |-do_auth_once
  11.             | | | |-native_password_authenticate
  12.             | | | |-server_mpvio_write_packet
  13.             | | | | |-send_server_handshake_packet // 发送handshake包到客户端
  14.             | | | | |-my_net_write
  15.             | | | | | |-net_write_buff // 将数据写入到内存
  16.             | | | | |-net_flush // 将内存中数据发送到网络
  17.             | | | |-server_mpvio_read_packet // 从客户端接收Login Request信息
  18.             | | | |-my_net_read
  19.             | | |-Protocol::end_statement
  20.             | | |-Protocol::send_ok
  21.             | | |-net_send_ok // 发送response ok
  22.             | | |-my_net_write
  23.             | |-prepare_new_connection_state
  24.             |-do_command
  25.                 |-dispatch_command
  26.                     |-mysql_parse

select命令:


点击(此处)折叠或打开

  1. pfs_swpawn_thread
  2.     |-handle_one_connection
  3.         |-do_handle_one_connection
  4.             |-do_command
  5.                 |-dispatch_command
  6.                     |-mysql_parse
  7.                         |-parse_sql
  8.                         | |-MYSQLparse
  9.                         |-mysql_execute_command
  10.                             |-select_precheck
  11.                             | |-check_table_access
  12.                             |-execute_sqlcom_select
  13.                             | |-open_normal_and_derived_tables
  14.                             | |-open_tables
  15.                             | | |-open_and_process_table
  16.                             | | |-open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
  17.                             | | |-Table_cache::get_table
  18.                             | | |-get_table_share_with_discover
  19.                             | | | |-get_table_share
  20.                             | | | |-open_table_def
  21.                             | | |-my_malloc // 申请表数据结构
  22.                             | | |-open_table_from_share
  23.                             | | |-handler::ha_open
  24.                             | | |-ha_innobase::open
  25.                             | | |-dict_table_open_on_name
  26.                             | | |-dict_load_table
  27.                             | | |-btr_pcur_is_on_user_rec
  28.                             | | |-dict_load_table_low
  29.                             | | | |-dict_mem_table_create
  30.                             | | |-fil_space_for_table_exists_in_mem
  31.                             | | |-fil_open_single_table_tablespace // 打开表空间文件
  32.                             | |-mysql_handle_derived
  33.                             |-handle_select
  34.                                 |-mysql_select
  35.                                     |-mysql_prepare_select
  36.                                     | |-JOIN::prepare
  37.                                     |-mysql_execute_select
  38.                                         |-JOIN::exec
  39.                                             |-select_send::send_result_set_metadata
  40.                                             | |-Protocol::send_result_set_metadata
  41.                                             |-do_select
  42.                                                 |-sub_select
  43.                                                     |-evaluate_join_record
  44.                                                         |-end_send
  45.                                                             |-select_send::send_data
  46.                                                                 |-Protocol::write

推荐阅读:
  1. mysql如何实现多表连接查询
  2. mysql如何实现连接查询

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql 查询 流程

上一篇:Android多人视频聊天应用的开发(一)快速集成

下一篇:自定义控件

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》