MySQL連接查詢流程源碼分析
來源:程序員人生 發布時間:2015-05-27 07:38:36 閱讀次數:3058次
初始化
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
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈