MyCAT Architecture
MyCAT logically consists of the following modules:
- MySQL protocol communication layer
Applications connect to MyCAT through the MySQL protocol. MyCAT serves as the front-end server by leveraging the non-blocking I/O (NIO) and asynchronous I/O (AIO) frameworks. NIO is more recommended because Linux does not support AIO.
- Application connection pool
The pool manages the connections between applications and MyCAT. MyCAT uses the connection pool mode based on MySQL instances. Each database can use idle connections among the existing 1000 connections.
- SQL parsing/optimization/routing components
The three components parse, optimize, and route the SQL statements of applications in sequence, determine the back-end database to which the SQL statements should be routed for execution, and then submit the SQL statements to the SQL execution component.
- SQL executor
SQL executor sends SQL statements to all targets based on the routing result. In this process, connections must be obtained from the back-end database connection pool and a specific driver is used to communicate with the back-end database.
- Database connection pool
The pool creates, manages, and maintains back-end connection pools. The connection pool mechanism is adopted for connection lifecycle management to reduce the cost of each database connection.
- Back-end MySQL protocol communication layer + Back-end JDBC driver
These modules implement the communication protocol of a specific database. For MySQL, NIO and AIO are provided. NIO is recommended because Linux does not support AIO.
- ORDER BY + GROUP BY + UNION (ALL)
These modules aggregate, sort, and truncate cross-shard query results.