MySQL 9.1.0
Source Code Documentation
|
When a query is sent to the server, the first step is to invoke the bison parser to build an Abstract Syntax Tree to represent the query text.
Assume the following statement:
CREATE TABLE test.t1 (a int) ENGINE = "INNODB";
In the bison grammar file, the rule implementing the CREATE TABLE statement is create_table_stmt
.
The tree created is an object of class PT_create_table_stmt.
This parse tree node has several related nodes, such as:
The collection of nodes returned after the bison parsing is known as the "Abstract Syntax Tree" that represents a SQL query.
Once the bison parser has finished parsing a query text, the next step is to build a SQL command from the Abstract Syntax Tree.
In the Abstract Syntax Tree, attributes like a storage engine name ("INNODB") are represented as strings, taken from the query text.
These attributes need to be converted to objects in the SQL context, such as an innodb_hton pointer to represent the INNODB storage engine.
The process that performs these transformations is contextualize().
The Parse_tree_root class is an abstract factory, building Sql_cmd objects.
For a CREATE TABLE statement, class PT_create_table_stmt builds a concrete Sql_cmd_create_table object.
PT_create_table_stmt::make_cmd() in particular performs the following actions:
Execution of a CREATE TABLE statement invokes Sql_cmd_create_table::execute(), which in turns calls:
Execution of this code is the runtime implementation of the CREATE TABLE statement, and eventually leads to:
Details about the dictionary and the storage engine are expanded in the following two sections.
In the data dictionary, creation of a new table calls:
The data dictionary code parses the content of the HA_CREATE_INFO input, and builds a dd::Table object, to represent the table metadata. Part of this metadata includes the storage engine name.
The runtime code then calls store()
to save this new metadata.
To store a table metadata, the data dictionary code first serialize it into an sdi format.
The serialized object is then stored in persistence, either in a tablespace or in a file:
When storing data into a tablespace, the storage engine handlerton is invoked, so that the storage engine can ultimately store the table metadata in the tablespace maintained by the storage engine.
When execution of the CREATE TABLE statement reaches the storage engine interface, the SQL layer function ha_create_table() invokes the storage engine handlerton::create() method to instantiate a new storage engine table, represented by handler. The SQL layer then calls handler::create() to create the table inside the storage engine.