Using Hints for Read/Write Splitting
In addition to the weight assignment rules of read/write splitting, hints serve as a complementary SQL syntax to specify whether a SQL statement is executed on a primary node or read replica.
This section describes how to use hints to route read and write requests to a primary node or read replica.
Precautions
Hints are only used as routing suggestions. In non-read-only SQL and non-transaction scenarios, SQL statements cannot be routed to read replicas.
Usage
You can add the following hints at the beginning of a SQL statement as needed.
/*FORCE_MASTER*/: The SQL statement is executed on the primary node.
/*FORCE_SLAVE*/: The SQL statement is executed on read replicas.
For example, if you run select * from table1, the SQL statement will be executed on a read replica by default. If you change it to /*FORCE_MASTER*/ select * from table1, the SQL statement will be executed on the primary node.
/*FORCE_MASTER*/ only works for read/write addresses. If your primary node is read-only, adding /*FORCE_MASTER*/ will not help route the SQL statement to the primary node.
Hints are case insensitive. For example, /*FORCE_MASTER*/ and /*force_master*/ work the same.
Hints cannot contain spaces. Incorrect example: /* FORCE_MASTER */; correct example: /*FORCE_MASTER*/
Hints must be placed at the beginning of a SQL statement.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot