tencent cloud

Hint Syntax Usage
Last updated: 2025-07-31 17:02:19
Hint Syntax Usage
Last updated: 2025-07-31 17:02:19
This document describes how to use the hint syntax on the database proxy.
The hint syntax can be used to forcibly execute SQL requests on the specified instance. A hint has the highest routing priority, and it is not subject to consistency and transaction constraints. You need to evaluate whether it is required in your business scenario before using it.
Note:
When you use the TDSQL-C for MySQL command line for connection with the hint syntax, you need to add the -c option to the command. Otherwise, the hints will be filtered out by the command line tool.
For example, the command should be mysql -h hostname -u username -p -c for connection through the private network.
When you use the hint syntax on the database proxy, the prepare statement is supported for database proxy 1.3.3 and later versions.
Currently, four types of hints are supported.
Specify the read-write instance for execution:
-- Hint syntax
/* to master */
Or
/*FORCE_MASTER*/
-- Example
-- Specify the read-write instance to perform the query operation
SELECT /* to master */ * FROM users WHERE user_id = 1;

-- Specify the read-write instance to perform the update operation
UPDATE /* FORCE_MASTER */ orders SET status = 'shipped' WHERE order_id = 1001;
Specify a read-only instance for execution:
-- Hint syntax
/* to slave */
Or
/*FORCE_SLAVE*/
-- Example
-- Specify a read-only instance to perform the query operation
SELECT /* to slave */ * FROM products WHERE category = 'electronics';

-- Specify a read-only instance to perform the count operation
SELECT /* FORCE_SLAVE */ COUNT(*) FROM transactions WHERE status = 'completed';
Specify a read-only analysis engine for execution:
Note:
This execution method is only supported when the database proxy version is 1.4.4 or later. If multiple read-only analysis engines exist, load balancing will be performed based on weight rules.
-- Specify the read-only analysis engine to perform the query operation
SELECT /* to ap */ * FROM products WHERE category = 'electronics';
Specify a certain instance for execution:
-- Hint syntax
/* to server server_name */
-- Example
-- Specify the instance test_ro_1 to perform the query operation
SELECT /* to server test_ro_1 */ * FROM inventory WHERE product_id = 2002;
Note:
server_name in the above statement indicates the instance ID. You can obtain the ID of the target instance in the instance information area on the right side of the cluster details page (in tab view), as shown below.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback