Help Center/ Distributed Database Middleware/ User Guide/ SQL Syntax/ Supported SQL Statements/ Specifying a Shard Using a Hint When You Execute a SQL Statement
Updated on 2024-07-30 GMT+08:00

Specifying a Shard Using a Hint When You Execute a SQL Statement

DDM allows you to customize a hint to specify whether SQL statements are executed on one shard or multiple shards.

The following hint formats are supported:

  • SQL statement executed on one shard: /*+db=<physical_db_name>*/ <your query>;
  • SQL statement executed on multiple shards: /*+db={<physical_db_name1>, <physical_db_name2>,<physical_db_name3>......}*/ <your query>;

Example:

  • SQL statement executed on one shard: /*+db=test_0000*/ select * from t1;
  • SQL statement executed on multiple shards: /*+db={test_0001, test_0002, test_0003}*/ select * from t2;

Constraints:

  • If the SQL statement is executed on multiple shards, the value of physical_db_name must be unique.
  • The hint is valid only for SELECT, DML, and TRUNCATE statements.
  • The hint works only under the text protocol, rather than the Prepare protocol.