SQL Routing
Under normal circumstances, the read/write separation feature provided by a database proxy effectively utilizes replica databases, thereby improving the throughput of the entire database system. However, in certain situations, we may also want to route SQL queries to specific databases to meet our business requirements. Here are some scenarios where SQL routing can be useful:
- Query statements need to avoid master-replica replication delay, so they are routed to the master database to ensure data real-time consistency.
- Data statistics and complex computation queries are routed to replica databases with lower load weights to separate them from real-time business databases.
Access SQL Routing
Click on 'Details' for the proxy to enter the details page. On the far right of the Database Proxy details page, you will find the SQL Routing feature. Click on the 'Edit' button to access the SQL Routing configuration page. On the SQL Routing page, at the top left corner, there is a 'Create Route' button. Clicking on it will open a dialog to create an SQL route.
Create SQL Routing Rule
On the SQL Routing settings page, you can set rate limiting for SQL statements of the SELECT type.
We can input the corresponding SQL statements based on the actual business scenario. The system will automatically replace variables ('hello world') with placeholders to accommodate incoming parameters.
Based on the actual business requirements, we can choose to route this SQL statement to the master database, replica database, or custom databases. In the 'Custom' option, you can select multiple databases.
Click 'Confirm,' and you will see that the rule has been added to the list.
Modify Routing Type
After creating the SQL routing rule, you can modify the routing type by clicking on the 'Modify Routing Type' button on the right.
Clicking on it will open a pop-up box where you can modify the routing type.
Delete Routing Rule
You can delete SQL routing rules. Click the 'Delete' button on the right, and then confirm to delete the rule.