MySQL connection query process source code Analysis

Source: Internet
Author: User

Initialization
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
Plug-in Startup
main    |-mysqld_main        |-init_server_components            |-plugin_init                |-plugin_initialize                    |-ha_initialize_handlerton                        |-innobase_init
Logon process
Main|-mysqld_main        |-network_init//Establish socket listener, one for network, one for UNIX domain        |-handle_connections_sockets            |-poll            |-mysql_socket_accept//And Client connection established            |-create_new_thread//Create a new thread for each socket connection                |-create_thread_to_handle_connection                    |-waiting_thd_list->push_back (THD); mysql_cond_signal (&cond_thread_cache); The processing thread function is pfs_spawn_thread when there is a connection processing thread that wakes through the signal                    |-mysql_thread_create (startup thread execution function, inline_mysql_thread_create)                        |-SPAWN_THREAD_V1                            |-pthread_create (Pfs_spawn_thread)
Processing connections
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//To determine if login is possible, no disconnect return error            |   | |-check_connection            |   |   | |-acl_authenticate            |   |       | |-do_auth_once            |   |           | |-native_password_authenticate            |   |               | |-server_mpvio_write_packet            |   |               |   | |-send_server_handshake_packet//Send handshake package to client            |   |               |       | |-my_net_write            |   |               |       |   | |-net_write_buff//Writes data to memory            |   |               |       | |-net_flush//sending in-memory data to the network            |   |               | |-server_mpvio_read_packet//Receive login request information from client            |   |                   | |-my_net_read            |   | |-protocol::end_statement            |       | |-PROTOCOL::SEND_OK            |           | |-NET_SEND_OK//Send response OK            |               | |-my_net_write            | |-prepare_new_connection_state            |-do_command                |-dispatch_command                    |-mysql_parse
Processing Command 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//Application form data structure                            |           | |-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//opening tablespace files                            | |-mysql_handle_derived                            |-handle_select                                |-mysql_select                                    |-mysql_prepare_select                                    | |-join::p repare                                    |-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 connection query process source code Analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.