溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

MySQL連接查詢(xún)流程源碼

發(fā)布時(shí)間:2020-08-10 23:27:13 來(lái)源:ITPUB博客 閱讀:265 作者:wangwenan6 欄目:MySQL數(shù)據(jù)庫(kù)
來(lái)源: 互聯(lián)網(wǎng)
版本: 不詳, 僅做參考用

初始化:

點(diǎn)擊(此處)折疊或打開(kāi)

  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 // 監(jiān)聽(tīng)網(wǎng)絡(luò)
  11.         |-grant_init
  12.         |-servers_init
  13.         |-udf_init

插件啟動(dòng):

點(diǎn)擊(此處)折疊或打開(kāi)

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

登錄過(guò)程:

點(diǎn)擊(此處)折疊或打開(kāi)

  1. main
  2.     |-mysqld_main
  3.         |-network_init // 建立socket監(jiān)聽(tīng),一個(gè)針對(duì)網(wǎng)絡(luò),一個(gè)針對(duì)unix域
  4.         |-handle_connections_sockets
  5.             |-poll
  6.             |-mysql_socket_accept // 和客戶(hù)端建立連接
  7.             |-create_new_thread // 針對(duì)每個(gè)socket連接建立一個(gè)新的線程
  8.                 |-create_thread_to_handle_connection
  9.                     |-waiting_thd_list->push_back(thd);mysql_cond_signal(&COND_thread_cache); // 已有連接處理線程時(shí),通過(guò)信號(hào)喚醒,處理線程函數(shù)為pfs_spawn_thread
  10.                     |-mysql_thread_create(啟動(dòng)的線程執(zhí)行函數(shù),inline_mysql_thread_create)
  11.                         |-spawn_thread_v1
  12.                             |-pthread_create(pfs_spawn_thread)

處理連接:


點(diǎn)擊(此處)折疊或打開(kāi)

  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,不可以則斷開(kāi)連接返回錯(cuò)誤
  8.             | | |-check_connection
  9.             | | | |-acl_authenticate
  10.             | | | |-do_auth_once
  11.             | | | |-native_password_authenticate
  12.             | | | |-server_mpvio_write_packet
  13.             | | | | |-send_server_handshake_packet // 發(fā)送handshake包到客戶(hù)端
  14.             | | | | |-my_net_write
  15.             | | | | | |-net_write_buff // 將數(shù)據(jù)寫(xiě)入到內(nèi)存
  16.             | | | | |-net_flush // 將內(nèi)存中數(shù)據(jù)發(fā)送到網(wǎng)絡(luò)
  17.             | | | |-server_mpvio_read_packet // 從客戶(hù)端接收Login Request信息
  18.             | | | |-my_net_read
  19.             | | |-Protocol::end_statement
  20.             | | |-Protocol::send_ok
  21.             | | |-net_send_ok // 發(fā)送response ok
  22.             | | |-my_net_write
  23.             | |-prepare_new_connection_state
  24.             |-do_command
  25.                 |-dispatch_command
  26.                     |-mysql_parse

select命令:


點(diǎn)擊(此處)折疊或打開(kāi)

  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 // 申請(qǐng)表數(shù)據(jù)結(jié)構(gòu)
  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 // 打開(kāi)表空間文件
  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

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI