程序员人生 网站导航

MySQL连接查询流程源码分析

栏目:数据库应用时间:2015-05-27 07:38:36

初始化

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

插件启动

main |-mysqld_main |-init_server_components |-plugin_init |-plugin_initialize |-ha_initialize_handlerton |-innobase_init

登录进程

main |-mysqld_main |-network_init // 建立socket监听,1个针对网络,1个针对unix域 |-handle_connections_sockets |-poll |-mysql_socket_accept // 和客户端建立连接 |-create_new_thread // 针对每一个socket连接建立1个新的线程 |-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)

处理连接

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

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
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐