移动云海山数据库(He3DB)-SQL语句执行流程(1)

1.总体描述与准备

通语过网络请求获取客户端的SQL 将SQL转换成LEX语法树 将语法树转换成具体执行 从存储空间加载到Page并找到记录
创建表格:
image.png
查询语句:select * from sbtest1 where id=1;

2. 连接认证

死循环,监听客户端请求并创建处理线程mysqld.cc
mysqld_main和network_int
image.png
Mysqld_socket_listener *mysqld_socket_listener 此类表示Mysqld_socket_listener,它准备侦听器套接字以接收来自客户端的连接事件。Mysqld_socket_listener可以由通过Mysqld命令行侦听默认Mysqld tcp端口或用户指定端口的tcp套接字和绑定到Mysqld实际路径名的unix套接字中的一个或两个组成。
image.png

Connection_acceptor<Mysqld_socket_listener> mysqld_socket_acceptor 此类提供了一个通用接口,用于初始化和运行不同类型侦听器的连接事件循环,以及一个回调函数,用于从侦听连接的侦听器调用连接事件。侦听器类型应该是一个提供方法setup_Listener、listen_for_connection_event和close_Listener的类。Connection事件回调函数对象将在接收到来自客户端的连接事件时处理连接。
image.png
处理连接事件的函数中,在线程初始化后会调用connection_event_loop( )。
image.png
connection_event_loop():connection_acceptor.h中 Connection acceptor loop to accept connections from clients.(死循环)
image.png
Template class Connection_acceptor: 此类提供了一个通用接口,用于初始化和运行不同类型侦听器的连接事件循环,以及一个回调函数,用于从侦听连接的侦听器调用连接事件。侦听器类型应该是一个提供方法setup_Listener、listen_for_connection_event和close_Listener的类。Connection事件回调函数对象将在接收到来自客户端的连接事件时处理连接。
Channel_info channel_info channel_info.h 文件中:这个抽象基类表示有关新连接的连接通道信息。它的子类封装了不同连接通道类型之间的差异。
image.png
Connection_handler_manager::process_new_connection(Channel_info
channel_info) 这是一个提供各种连接管理相关功能的单例类,最重要的是将新连接调度到当前激活的connection_handler
image.png
Connection handler:This abstract base class represents how connections are processed, most importantly how they map to OS threads.
image.png
bool Per_thread_connection_handler::add_connection(Channel_info
channel_info) 此类表示连接处理功能,即每个连接都是有一个独立线程处理的。
image.png
函数具体处理逻辑:线程缓存,有空闲就拿过来,没有就再创建一个加进去
image.png
handle_connection()函数:连接线程的管理
image.png
初始化thd时三种特殊情况的操作:thd=NULL、HAVE_PSI_THREAD_INTERFACE时,是否resued,要复用和不复用两种子情况
image.png
设置mysql_thread_set_psi的id和THD,通过socker设置线程所有者,将thd添加到thd_manger
image.png
关键函数:thd_prepare_connection(thd) sql_connect.cc中
image.png
关键函数:lex_start(thd) 在sql_lex中 The function creates a select_lex and a select_lex_unit object. These objects should rather be created by the parser bottom-up.
image.png
关键函数:login_connection(thd) 在sql_connect中 Autenticate user, with error reporting
image.png
关键函数:error= check_connection(thd):在sql_connect中 Perform handshake, authorize client and update thd ACL variables.
image.png
关键调用函数:acl_check_host() 在sql_authentication中 确认host和ip是否匹配 Return true if there is no users that can match the given host
image.png
关键调用函数:vio_keepalive() 设置keepalive
image.png
关键调用函数:acl_authenticate(thd, COM_CONNECT) 密码认证
image.png
Perform the handshake, authorize the client and update thd sctx variables
image.png
关键函数:do_auth_once() 第一步认证尝试、向server发送handshake包
image.png
thd->send_statement_status() 在sql_class中 Send the status of the current statement execution over network
image.png
关键函数:prepare_new_connection_state(THD* thd) 在sql_connect中 Initialize THD to handle queries
image.png
关键调用函数: thd_manager->add_thd(thd) 在connection_handler_per_thread.cc中
image.png
void Global_THD_manager::add_thd(THD *thd) 在mysql_thd_manager.cc中 将该线程加入list中
image.png
关键调用函数:do_command(thd) 和end_connection(thd) 死循环接受用户请求、关闭已有连接
image.png
do_command(THD *thd) 在sql_parse中 Read one command from connection and execute it (query or simple command)
image.png
最后释放资源、关闭连接
image.png

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值