Rate This Document
Findability
Accuracy
Completeness
Readability

MyCAT Working Principles

After intercepting a SQL statement from a user, MyCAT performs sharding, route, read/write splitting, and cache analyses on the SQL statement, sends it to the back-end database for proper processing, and then returns the result to the user.

Specifically, after receiving an SQL statement, MyCAT parses the SQL statement, searches for the involved table, and checks the definition of the table. If there is a sharding rule, MyCAT obtains the value of the sharding key in the SQL statement and matches the sharding function to obtain the shard list corresponding to the SQL statement. Then, the SQL statement is sent to these shards for execution. Finally, the result data returned by all shards is collected and processed, and then output to the client.

Take the select * from Orders where prov=? statement as an example. If prov=wuhan is found, dn1 is returned based on the sharding function. Therefore, the SQL statement is sent to MySQL, and the query result is obtained from DB1 and then returned to the user.