search
HomeDatabaseMysql TutorialMysql源码学习――八度空间_MySQL

bitsCN.com

 

学习完词法分析和语法分析后,开始进入Mysql源码的正式学习之旅了。这么多模块,肿么入手呢?!还好从网上搜到了一个模块划分,以后就尽可能根据这个模块划分一步一步的跟踪源码,揭开Mysql的面纱。

Mysql源码学习――八度空间_MySQL <script></script>

 

 

      我们从上至下来看各个模块的划分,首先客户端发送请求与服务器连接,通过connection manager模块,连接管理模块会调用Thread Manager模块,即线程管理模块,这里会为一个连接创建一个新的线程,专门为这个连接服务,这就保证了每个连接都有一个独立的线程为之工作,当然连接数一般也会有个限制,不然无限制的创建新的线程,操作系统也顶不住啊。接着进入了User Module,用户模块,这个模块应该是身份识别认证阶段,说白了就是检查用户名密码,当然应该还包括权限检查(只有自主访问控制,Mysql不像Oracle,不支持role,更不用说label了。这就是简约而不简单吧,^_^)。

 

      上面的三个模块就是登录过程中必须经历的阶段。connection manager为客户端和服务器创建连接,thread manager为新建的连接分配一个独立的线程,user Module进行身份认证。oh yeah~~

 

      接着进入Commander Dispatcher模块,命令分发模块,大概就是一个switch case的过程,根据不同的命令,进行不同的操作。这个模块又会间接关联到Query Cache模块和Logging Module,即查询缓存模块和日志模块。Query Cache模块个人感觉至少包含结果集缓存模块,至于有木有执行计划缓存,这个就不清楚了,还需要进入源码慢慢看来。Logging Module就是传说中的日志了,日志包括redo和undo两方面吧,日志系统是一个database必备的,是实现事务特性的重要手段,而事务便是database和file system的根本区别,不要小瞧了Logging Module啊!!

 

      命令分发模块,根据命令的性质,将命令分给不同的子模块。SELECT分配给Optimizer即优化模块,一条select语句最重要的就是执行计划了,一个好的执行计划比一个坏的执行计划不知道要快多少倍,这就是为什么我们要建立索引,其实在经常查询的列上建立二级索引,就是为了改变执行计划,让执行计划可以选择二级索引,而抛弃聚簇索引(当然不是完全抛弃,聚簇索引是根本)。UPDATE、INSERT、DELETE交给Table Modification Module,不看也知道,这个模块主要是处理数据更新了(这里所说的更新是指数据的改变,即UID)。Repairs分配给了Table Maintenance Module,字面意义是说表维护模块,我OUT了,默认表坏了,支持修复?是何种坏了?不太了解啊…。Replication分配给了Replication Module,就是复制模块。最后一个是Status分配给了Status Reporting Module,这个我貌似接触过,是不是所谓的那些动态试图?比如查看系统当前状态下的锁资源的占用情况等,这个模块应该是性能分析者居家旅行必备的模块吧,通过这个模块可能很快找到系统性能的瓶颈。

 

      上面的模块又统一走到Access Control Module,访问控制模块啊,原来上面所说的User Module不包含访问控制…,这个访问控制就是简单的DAC,即检查用户是否对要访问的对象具有增、删、改、查的权限。接着进入Table Manager模块,因为Mysql支持不同的存储引擎,而这个模块是个统一的模块,个人感觉这个应该是表的字典对象管理模块,即表的一些元数据,比如这个表包含哪些列啊,各个列的类型,表的创建者,创建日期,表的存储引擎之类的信息。最下面是Abstract Storage Engine Module,即抽象存储引擎模块,Mysql的保持这么多存储引擎同时在服务器中,是通过一个handler抽象类实现的(不知道有木有抽象类的概念,小弟C++、JAVA丢了很久了…),每个存储引擎按照规定的接口,实现一个具体的handler类,然后再调用的时候,根据上面的Table Manager模块中的存储引擎的信息,选择对应的handler类进行相应表的物理操作。

 

      看了这个模块图,感觉思路清晰了很多。下面就一步一步的学习每个模块,当然这些模块之间也是一个执行流程顺序执行的过程。今天就写到这了,下次开始学习第一个模块:Connection Manager

 

      PS. 貌似最近没这么忙了,加班加了好几个月终于算是稍微轻松了一点。以后把更多的业余时间放在读书学习上。

 

      PS again. 每天下班脑子都一锅粥了,回来写点博客权当放松啦,标题的八度空间是JAY的专辑名啦,借此来比喻Mysql的各个模块^_^

 


摘自 心中无码 bitsCN.com
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Apr 15, 2025 am 12:11 AM

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL vs. Other Databases: Comparing the OptionsMySQL vs. Other Databases: Comparing the OptionsApr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment