All Products
Search
Document Center

PolarDB:How to use HINTs

Last Updated:Aug 20, 2026

This topic describes the syntax of HINTs and provides usage examples.

HINTs are a supplementary SQL syntax that plays an important role in relational databases. They allow you to influence how SQL statements are executed for specific optimizations. PolarDB-X also provides a special HINT syntax.

Syntax

/*+TDDL: hint_command [hint_command ...]*/
    
/!+TDDL: hint_command [hint_command ...]*/
Note When you execute SQL statements that contain PolarDB-X custom HINTs in the /*+TDDL:hint_command*/ format using the official MySQL command-line client, you must add the -c parameter to the logon command. Otherwise, because PolarDB-X custom HINTs are formatted as MySQL comments, the client will delete the comments before sending the statements to the server for execution, rendering the PolarDB-X custom HINTs ineffective. For more information, see the MySQL official client command options.

Examples

# Query the physical table names in each database shard.
/*+TDDL:scan()*/SHOW TABLES;
   
# Send the query to the 0000 database shard of the RDS read-only instance.
/*+TDDL:node(0) slave()*/SELECT * FROM t1;

# Force the workload type to AP.
/*+TDDL:WORKLOAD=AP*/SELECT * FROM t1;

PolarDB-X supports the use of multiple HINT commands in a single HINT statement:

SELECT /*+TDDL:node(0) slave()*/ ...;

PolarDB-X does not support the use of multiple HINT commands in the following ways:

# Multiple HINT statements are not supported in a single SQL statement.
SELECT /*+TDDL:node(0)*/ /*+TDDL:slave()*/ ...;
    
# Duplicate HINT commands are not supported in a HINT statement.
SELECT /*+TDDL:node(0) node(1)*/ ...;