Mysql 体系结构系列之十

前言:参考Mysql体系结构系列之九:细看核心模块

http://blog.csdn.net/nature_ann/article/details/11067911

1. 细看核心模块 Detailed Look at the Core Modules

1.1 Optimizer 优化器

<<--- Optimizeranswer the querymost complex modulemysql_select()----->>

The Optimizer is responsible for creating the best strategy to answer the query, and

executing it to deliver the result to the client.

优化器负责创建回答查询的最佳策略,并执行该策略,向客户端提交结果。

 

It is perhaps the most complex module in the MySQL code. The entry point is mysql_select( ) in sql/sql_select.cc.

优化器是Mysql代码中最复杂的模块。该模块的入口点是sql/sql_select.cc中的mysql_select().

 

Some other functions and methods of interest,all insql/sql_select.cc, include:

>>JOIN::prepare( )

>>JOIN::optimize( )

>>JOIN::exec( )

>>make_join_statistics( )

>>find_best_combination( )

>>optimize_cond( )

其他有关的函数和方法都在sql/sql_select.cc中,包括:join::prepare(),join::optimize,join::exec(),make_join_statistics(),find_best_combination(),optimize_cond()

 

As you descend into the depths of the optimizer, there is acave worth visiting.

当读者深入优化器内部时,有一座深山值得研究。

 

It is the range optimizer, which was separate enough from the optimizer core andcomplex enoughto be isolated into a separate file,sql/opt_range.cc.

这就是范围优化器,它相对于优化器核心足够独立,足够复杂,以至于可以成为一个独立的文件:sql/opt_range.cc。

 

The range optimizer is responsible foroptimizing queries that use a key witha given value rangeor set of ranges.

范围优化器负责对使用带有给定范围的数值或范围数值集的键的查询进行优化。

 

The entry point for the range optimizer isSQL_SELECT::test_quick_select( ).

范围优化器的入口点是SQL_SELECT::test_quick_select()。

 

The optimizer has always been in a state of change. The addition ofsubqueries in 4.1

has added another layer of complexity.

优化器总是不断变化着。在4.1版本中添加的子查询功能,使得复杂程度更上一层楼。

 

Version 5.0 added a greedy search for the optimal table join order, and the ability to use severalkeys per table (index merge).

在5.0版本中,增加了强大的搜索功能针对最优表连接顺序,还有每一个表使用多个键(索引合并)的功能。

 

It is reasonable to expect that many more changes will be made in the future. One

long-awaited change is improvements in the optimization of sub-queries.

人们有理由相信,以后会发生更多的变化,更让大家有所期待的改变是子查询优化的改进。

1.2 Table Manager 表管理器

<<---Table manager—(creating,reading,modifying)—table cache—sql_base.cc,unireg.cc,lock.cc----->>

The Table Manager is responsible forcreating, reading, andmodifying the tabledefinition files (.frm extension),maintaining a cache of table descriptors called table

cache, and managing table-level locks.

表管理器负责创建、读取和修改表定义文件(.frm扩展名)、维护表描述符高速缓存即表高速缓存,以及管理表锁。

 

Most of the code is found in sql/sql_base.cc, sql/table.cc, sql/unireg.cc, and sql/lock.cc.

大部分代码位于sql/sql_base.cc、sql/table.cc、sql/unireg.cc、sql/lock.cc中。

 

Some functions of interest include:

>>openfrm( ) in sql/table.cc

>>mysql_create_frm( ) in sql/unireg.cc

>>open_table( ) in sql/sql_base.cc

>>open_tables( ) in sql/sql_base.cc

>>open_ltable( ) in sql/sql_base.cc

>>mysql_lock_table( ) in sql/lock.cc

部分有关函数如下:

位于sql/table.cc中的openfrm();

位于sql/unireg.cc中的mysql_create_frm( );

位于sql/sql_base.cc中的open_table( );

位于sql/sql_base.cc中的open_tables( );

位于sql/sql_base.cc中的open_ltable( );

位于sql/lock.cc中的mysql_lock_table( )。

 

The code has not changed much since version 3.22 except for the new tabledefinition file format in version 4.1.

从3.22版起,除了4.1版中新的表定义文件格式,这部分代码改动不多。

 

In the past, Monty has expressed some dissatisfaction with the inefficiencies in thetable cache code, and wanted to rewrite it.

过去,Monty曾经对表高速缓存代码的执行效率低下表示过不满,并打算重新编写它。

 

For a while, this was not a top priority. However, some progress has finally been made in version 5.1.

这在一段时间内并没有成为首要的工作,但最终在5.1版中做了一些改进。

1.3 Table Modification Modules 表修改模块

<<---Table Modification Modules:responsible of operations--sql/sql_update.cc| sql_insert.cc|sql/sql_table.cc|sql/sql_delete.cc ----->>

This collection of modules is responsible for operations such as creating, deleting,

renaming,dropping,updating, orinserting into a table. This is actually a very significant chunk of code.

这一模块集负责诸如表创建、删除、重命名、移除、更新或者插入之类的操作。实际上这是一段非常重要的代码。

 

Unfortunately, due to the space constraints, this book will not cover it in detail.

由于篇幅的限制,这里不会详细阐述。

 

However, once you become familiar with the rest of the code, you should be able to figure out the details by reading the source and using the debugger without too much trouble by starting from the followingentry points:

不过,只要你熟悉了代码的其余部分,通过阅读源代码和使用调试器,不用费什么力气就想详细了解。可以从下面的入口点开始:

• mysql_update( ) and mysql_multi_update( ) in sql/sql_update.cc

• mysql_insert( ) in sql/sql_insert.cc

• mysql_create_table( ) in sql/sql_table.cc

• mysql_alter_table( ) in sql/sql_table.cc

• mysql_rm_table( ) in sql/sql_table.cc

• mysql_delete( ) in sql/sql_delete.cc

 

The Update and Delete modules have been changed significantly in version 4.0 with

the addition of multi-table updates and deletes.

随着多表更新和删除的增加,在4.0版本中的更新和删除模块改动很大。

 

Some reorganization also happened in Update, Insert, and Delete modules to support prepared statements in version 4.1 and triggers in 5.1.

为了支持4.1版中的预处理语句和5.1版中的触发器,对更新、插入和删除进行了一些重新组织。

 

Otherwise, aside from fairly minor improvements from time to time, they have not changed much.

否则,除了偶尔进行的微小改进,其余没有什么大的变化。

 

It is reasonable to expect that for the large part the code will remain as it is in the future.

我们又理由相信,大部分代码以后将维持原状。

 

待续。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值