This is a creation in Article, where the information may have evolved or changed.
This article from the analysis of MySQL x the protocol layer of this plugin includes two aspects: the specific definition of the PROTOBUF message, and the mapping of these messages to the SQL statement.
About MySQL X
MySQL x is a plugin that comes with MySQL 5.7 when it is released, and is enabled to provide a very mongodb-like service via the X-Protocol protocol. In the Unix/linux environment, the command to load this plugin is:
INSTALL PLUGIN mysqlx SONAME 'mysqlx.so';
Follow the configuration, you can refer here.
Correspondingly, the client program is called the MySQL Shell , which can be downloaded here.
After the request is received by the server, the plugin translates it into the corresponding SQL statement, which is then forwarded to the MySQL master service execution and returns the result set to the client.
Message Protocol
The message protocol is defined in the MySQL 5.7 source tree rapid/plugin/x/protocol directory, including connection management, session management, CRUD and many other types. It is important to note that these files are defined in several different names of packages, so in Golang, it is not available, but also need to do some of the sub-directories, change the package name and other minor processing. The documentation for the message itself is here.
However, the documentation does not cover all the details, so we write a tool to grab the packet and print the message content to help us debug the protocol. The project is here.
message map to SQL
administrator Commands , in rapid/plugin/x/src/{admin_cmd_handler.h,admin_cmd_handler.cc} .
- Ping, return the OK message directly;
- List_clients, return 4 column metadata, respectively client_id, user, host, sql_session;
- Kill_client
- Create_collection
- Drop_collection
- Ensure_collection
- Create_collection_index
- Drop_collection_index
- List_objects
- Enable_notices
- Disable_notices
- List_notices
verify the relevant commands , both in the same directory auth_mysql41.h and in the auth_mysql41.cc file. Consists of three functions that correspond to start,continue and done three stages respectively.
CRUD class Operations , through the crud_cmd_handler.h definition of the Crud_command_handler Class 7 interface implementation, the 7 interfaces are responsible for adding and deleting records, and create, modify, destroy the view.
Insert_statement_builderclass to overwrite a document's insert operation with an INSERT statement for SQL;
Update_statement_builderclass to overwrite the update operation of the document with the updated statement;
- Corresponding, there are
Delete_statement_builder and find_statement_builder classes.
There are some notice related content, tentatively.