Core Classes, Structures, Variables,
and APIs — Chapter 3

Navneet Ojha
3 min readJul 13, 2020

--

Highlights from the book

In continuation to below post

Chapter 2 — Nuts and Bolts of Working with the MySQL Source Code

It has all information about how to install MySQL, using the source code or by BitKeeper repository.

CHAPTER — 3

THD
The THD class defines a thread descriptor. It contains the information pertinent to the thread that is handling the given request. Each client connection is handled by a thread. Each thread has a descriptor object. Handling client requests is not the only time a thread is created. MySQL has a number of system threads, such as the replication of slave threads and delayed insert threads. Additionally, there exists a special case when a thread descriptor object is created without a thread — the server running in bootstrap mode to create the necessary system tables during installation

Note that in version 4.1, part of THD was moved into the newly created class Statement, and THD was made a subclass of Statement.

NET
The NET structure defines a network connection descriptor. MySQL uses a fairly complex protocol on top of the one already provided by the operating system for client/server communication. This structure lies at the core of the protocol’s implementation. The protocol defines its own packet format. A packet can send a command, a message, or a block of data. Packets can be compressed, or transmitted over the SSL layer.

All network communication functions use NET one way or the other, usually by accepting it as an argument. Becoming familiar with the members of NET is a major step toward understanding the client/server communication protocol.

TABLE
The TABLE structure defines a database table descriptor. A table can exist in an open or closed state. In order to be used in the server, it has to be opened. Whenever this happens, a table descriptor is created and placed in the table cache to be reused later when another request is made that references the same table. Instances of TABLE are frequently referenced in the parser, optimizer, access control, and query cache code. It glues things together in a number of ways. Studying its members is a good way to become acquainted with a degree with the low-level details of the server implementation.

Field
The Field class defines a field descriptor. It is actually a base abstract class for a number of subclasses defined for each specific field type, such as integer, string, or timestamp. This class naturally plays a critical role in the parser and optimizer, because most of the operations in processing a query involve table fields.

Utility API Calls
A number of core jobs, such as memory allocation, string operations, or file management, are performed by a group of internal API calls.

Preprocessor Macros
MySQL makes heavy use of the C preprocessor. A number of tasks are complex
enough to justify some form of an alias rather than being spelled out in the code but are still too simple to justify a function. Other tasks are performed differently — or in some cases, not at all — depending on the compilation options. Such tasks are performed with a preprocessor macro.

Global Variables
MySQL code uses a large number of global variables for various purposes: configuration settings, server status information, various data structures shared among threads, and other things. Studying the global variables provides numerous insights into the server architecture. Often the very existence of the variable concisely tells a story about how and why different components work together.

Reference

https://www.amazon.com/Understanding-MySQL-Internals-Discovering-Improving-ebook-dp-B0043EWUIO/dp/B0043EWUIO

--

--

Navneet Ojha
Navneet Ojha

Written by Navneet Ojha

I am Indian by birth, Punjabi by destiny. Humanity is my religion. Love to eat, travel, read books and my million dreams keep me alive.

No responses yet