MariaDB源码解读之引擎启动与查询流程

引擎启动流程

sql/mysqld.cc/int mysqld_main(int argc, char **argv)
	->sql/mysqld.cc/static int init_server_components()
		->sql/sql_plugin.cc/int plugin_init(int *argc, char **argv, int flags)
			->sql/sql_plugin.cc/ builtins= mysql_optional_plugins; -->extern struct st_maria_plugin *mysql_mandatory_plugins[]; -->sql/sql_builtin.cc/struct st_maria_plugin *mysql_optional_plugins[] -->storage/innobase/handler/ha_innodb.ccstatic/maria_declare_plugin(innobase)
				->storage/innobase/handler/ha_innodb.ccstatic/maria_declare_plugin(innobase)
					->storage/innobase/handler/ha_innodb.ccstatic/int innodb_init(void* p)
						-> storage/innobase/srv/srv0start.cc/dberr_t srv_start(bool create_new_db)
							->storage/innobase/srv/srv0srv.cc/void srv_boot(void)
								->storage/innobase/sync/sync0debug.cc/void sync_check_init();
								->storage/innobase/log/log0recv.cc/void recv_sys_var_init();
								->storage/innobase/trx/trx0trx.cc/void trx_pool_init();
								->storage/innobase/row/row0mysql.cc/void row_mysql_init();
								->storage/innobase/srv/srv0srv.cc/void srv_init();
			->sql/sql_plugin.cc/static bool register_builtin(struct st_maria_plugin *plugin, struct st_plugin_int *tmp, struct st_plugin_int **ptr)
			->sql/sql_plugin.cc/static int plugin_initialize(&tmp_root, plugin_ptr, argc, argv, (flags & PLUGIN_INIT_SKIP_INITIALIZATION)) in for(;;)
				->sql/sql_plugin.cc/plugin_type_initialize[plugin->plugin->type] -->{ha_initialize_handlerton} ⇋ int ha_initialize_handlerton(st_plugin_int *plugin)
		->sql/sql_plugin.cc/init_default_storage_engine(default_storage_engine, table_plugin) ⇋ static int init_default_storage_engine_impl(const char *opt_name, char *engine_name, plugin_ref *res)

查询语句执行流程

sql/mysqld.cc/mysqld_mian()
	-> sql/mysqld.cc/handle_connections_sockets()
		-> sql/mysqld.cc/handle_accepted_socket
			-> sql/mysqld.cc/create_new_thread
				-> sql/sql_connect.cc/do_handle_one_connection()
					-> sql/sql_parse.cc/do_command()
						-> sql/sql_parse.cc/dispatch_command() .. case COM_QUERY 
							-> sql/sql_parse.cc/mysql_parse()
								-> sql/sql_parse.cc/parse_sql()
									-> sql/sql_parse.cc/mysql_execute_command() .. case SQLCOM_SELECT
										-> sql/sql_parse.cc/check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables, bool any_combination_of_privileges_will_do, uint number, bool no_errors)
											-> sql/sql_parse.cc/static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
												-> sql/sql_base.h/inline bool open_and_lock_tables(THD *thd, TABLE_LIST *tables, bool derived, uint flags)
													-> sql/sql_base.cc/bool open_and_lock_tables(THD *thd, const DDL_options_st &options, TABLE_LIST *tables, bool derived, uint flags, Prelocking_strategy *prelocking_strategy)
														-> sql/sql_base.cc/bool open_tables(THD *thd, const DDL_options_st &options, TABLE_LIST **start, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy)
															-> sql/sql_base.cc/static bool open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy, bool has_prelocking_list, Open_table_context *ot_ctx)
																-> sql/sql_base.cc/bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
																	-> sql/table.cc/enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, const LEX_CSTRING *alias, uint db_stat, uint prgflag, uint ha_open_flags, TABLE *outparam, bool is_create_table, List<String> *partitions_to_open)
																		-> sql/handler.cc/int handler::ha_open(TABLE *table_arg, const char *name, int mode, uint test_if_locked, MEM_ROOT *mem_root, List<String> *partitions_to_open)
																			-> sql/handler.h/virtual int open(const char *name, int mode, uint test_if_locked)=0;
																				-> storage/innobase/handler/ha_innodb.h/int open(const char *name, int mode, uint test_if_locked);
																					-> sql/sql_select.cc/bool handle_select(THD *thd, LEX *lex, select_result *result, ulong setup_tables_done_option)
																						-> sql/sql_select.cc/bool mysql_select(THD *thd, TABLE_LIST *tables, uint wild_num, List<Item> &fields, COND *conds, uint og_num, ORDER *order, ORDER *group, Item *having, ORDER *proc_param, ulonglong select_options, select_result *result, SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex)
																							-> sql/sql_select.cc/int JOIN::prepare(TABLE_LIST *tables_init, uint wild_num, COND *conds_init, uint og_num, ORDER *order_init, bool skip_order_by, ORDER *group_init, Item *having_init, ORDER *proc_param_init, SELECT_LEX *select_lex_arg, SELECT_LEX_UNIT *unit_arg)
																								-> sql/sql_select.cc/int JOIN::optimize()
																									-> sql/sql_select.cc/int JOIN::optimize_inner()
																										-> sql/sql_select.cc/bool JOIN::build_explain()
																											-> sql/sql_select.cc/int JOIN::optimize_stage2()
																												-> sql/sql_select.cc/static bool make_join_readinfo(JOIN *join, ulonglong options, uint no_jbuf_after)
																													-> sql/sql_select.cc/void JOIN::exec()
																														-> sql/sql_select.cc/void JOIN::exec_inner()
																															-> sql/sql_select.cc/static int do_select(JOIN *join, Procedure *procedure)
																																-> sql/sql_select.cc/int join_init_read_record(JOIN_TAB *tab)
																																	-> sql/records.cc/bool init_read_record(READ_RECORD *info,THD *thd, TABLE *table, SQL_SELECT *select, SORT_INFO *filesort, int use_record_cache, bool print_error, bool disable_rr_cache)
																																		-> sql/handler.h/int ha_rnd_init(bool scan) __attribute__ ((warn_unused_result))
																																			-> storage/innobase/handler/ha_innodb.cc/int ha_innobase::rnd_init(
																																				-> sql/records.cc/int rr_sequential(READ_RECORD *info)
																																					-> sql/handler.cc/int handler::ha_rnd_next(uchar *buf)
																																						-> storage/innobase/handler/ha_innodb.cc/int ha_innobase::rnd_next(uchar* buf)

希望这篇博客能对有志研发数据库插件引擎的coder起到抛砖引玉之作用!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值